Type/to search
Built-in Functions
Global
Version
Sleep
IsVirtual
Mail
Mail_Go
SetErrorFilter
GetPid
GetLastError
GetCommand
GetMeta
Dial
HttpQuery
HttpQuery_Go
Encode
UnixNano
Unix
GetOS
MD5
DBExec
UUID
EventLoop
__Serve
_G
_D
_N
_C
_Cross
JSON.parse
JSON.stringify
SetChannelData
GetChannelData
Log
Market
Trade
Account
Futures
NetSettings
Threads
threading
Thread
getThread
mainThread
currentThread
Lock
Condition
Event
Dict
pending
Thread
ThreadLock
ThreadEvent
ThreadCondition
ThreadDict
Web3
TA
Talib
talib.CDL2CROWS
talib.CDL3BLACKCROWS
talib.CDL3INSIDE
talib.CDL3LINESTRIKE
talib.CDL3OUTSIDE
talib.CDL3STARSINSOUTH
talib.CDL3WHITESOLDIERS
talib.CDLABANDONEDBABY
talib.CDLADVANCEBLOCK
talib.CDLBELTHOLD
talib.CDLBREAKAWAY
talib.CDLCLOSINGMARUBOZU
talib.CDLCONCEALBABYSWALL
talib.CDLCOUNTERATTACK
talib.CDLDARKCLOUDCOVER
talib.CDLDOJI
talib.CDLDOJISTAR
talib.CDLDRAGONFLYDOJI
talib.CDLENGULFING
talib.CDLEVENINGDOJISTAR
talib.CDLEVENINGSTAR
talib.CDLGAPSIDESIDEWHITE
talib.CDLGRAVESTONEDOJI
talib.CDLHAMMER
talib.CDLHANGINGMAN
talib.CDLHARAMI
talib.CDLHARAMICROSS
talib.CDLHIGHWAVE
talib.CDLHIKKAKE
talib.CDLHIKKAKEMOD
talib.CDLHOMINGPIGEON
talib.CDLIDENTICAL3CROWS
talib.CDLINNECK
talib.CDLINVERTEDHAMMER
talib.CDLKICKING
talib.CDLKICKINGBYLENGTH
talib.CDLLADDERBOTTOM
talib.CDLLONGLEGGEDDOJI
talib.CDLLONGLINE
talib.CDLMARUBOZU
talib.CDLMATCHINGLOW
talib.CDLMATHOLD
talib.CDLMORNINGDOJISTAR
talib.CDLMORNINGSTAR
talib.CDLONNECK
talib.CDLPIERCING
talib.CDLRICKSHAWMAN
talib.CDLRISEFALL3METHODS
talib.CDLSEPARATINGLINES
talib.CDLSHOOTINGSTAR
talib.CDLSHORTLINE
talib.CDLSPINNINGTOP
talib.CDLSTALLEDPATTERN
talib.CDLSTICKSANDWICH
talib.CDLTAKURI
talib.CDLTASUKIGAP
talib.CDLTHRUSTING
talib.CDLTRISTAR
talib.CDLUNIQUE3RIVER
talib.CDLUPSIDEGAP2CROWS
talib.CDLXSIDEGAP3METHODS
talib.AD
talib.ADOSC
talib.OBV
talib.ACOS
talib.ASIN
talib.ATAN
talib.CEIL
talib.COS
talib.COSH
talib.EXP
talib.FLOOR
talib.LN
talib.LOG10
talib.SIN
talib.SINH
talib.SQRT
talib.TAN
talib.TANH
talib.MAX
talib.MAXINDEX
talib.MIN
talib.MININDEX
talib.MINMAX
talib.MINMAXINDEX
talib.SUM
talib.HT_DCPERIOD
talib.HT_DCPHASE
talib.HT_PHASOR
talib.HT_SINE
talib.HT_TRENDMODE
talib.ATR
talib.NATR
talib.TRANGE
talib.BBANDS
talib.DEMA
talib.EMA
talib.HT_TRENDLINE
talib.KAMA
talib.MA
talib.MAMA
talib.MIDPOINT
talib.MIDPRICE
talib.SAR
talib.SAREXT
talib.SMA
talib.T3
talib.TEMA
talib.TRIMA
talib.WMA
talib.LINEARREG
talib.LINEARREG_ANGLE
talib.LINEARREG_INTERCEPT
talib.LINEARREG_SLOPE
talib.STDDEV
talib.TSF
talib.VAR
talib.ADX
talib.ADXR
talib.APO
talib.AROON
talib.AROONOSC
talib.BOP
talib.CCI
talib.CMO
talib.DX
talib.MACD
talib.MACDEXT
talib.MACDFIX
talib.MFI
talib.MINUS_DI
talib.MINUS_DM
talib.MOM
talib.PLUS_DI
talib.PLUS_DM
talib.PPO
talib.ROC
talib.ROCP
talib.ROCR
talib.ROCR100
talib.RSI
talib.STOCH
talib.STOCHF
talib.STOCHRSI
talib.TRIX
talib.ULTOSC
talib.WILLR
talib.AVGPRICE
talib.MEDPRICE
talib.TYPPRICE
talib.WCLPRICE
OS
Structures
Built-in Variables

exchange.GetPositions() function is used to get position information; the GetPositions() function is a member function of the exchange object exchange.

GetPositions() function is used to get the position information of the exchange account bound to the exchange object exchange. The purpose of the member functions (methods) of the exchange object is only related to exchange, which will not be repeated in the rest of this document.

exchange.GetPositions()
exchange.GetPositions(symbol)

Examples

Using the futures exchange object, place market orders on multiple symbols with different trading pairs and contract codes, and query position information through various methods.

javascript
/*backtest start: 2024-05-21 00:00:00 end: 2024-09-05 00:00:00 period: 5m basePeriod: 1m exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}] */ function main() { var arrSymbol = ["BTC_USDT.swap", "BTC_USDT.quarter", "ETH_USDT.swap", "ETH_USDT.quarter"] for (var symbol of arrSymbol) { exchange.CreateOrder(symbol, "buy", -1, 1) exchange.CreateOrder(symbol, "sell", -1, 1) } var defaultPositions = exchange.GetPositions() var swapPositions = exchange.GetPositions("USDT.swap") var futuresPositions = exchange.GetPositions("USDT.futures") var btcUsdtSwapPositions = exchange.GetPositions("BTC_USDT.swap") var tbls = [] var arr = [defaultPositions, swapPositions, futuresPositions, btcUsdtSwapPositions] var tblDesc = ["defaultPositions", "swapPositions", "futuresPositions", "btcUsdtSwapPositions"] for (var index in arr) { var positions = arr[index] var tbl = {type: "table", title: tblDesc[index], cols: ["Symbol", "MarginLevel", "Amount", "FrozenAmount", "Price", "Profit", "Type", "ContractType", "Margin"], rows: [] } for (var pos of positions) { tbl.rows.push([pos.Symbol, pos.MarginLevel, pos.Amount, pos.FrozenAmount, pos.Price, pos.Profit, pos.Type, pos.ContractType, pos.Margin]) } tbls.push(tbl) } LogStatus("`" + JSON.stringify(tbls) + "`") // After printing the information once, return to prevent subsequent order fills during backtesting from affecting data observation return }
python
'''backtest start: 2024-05-21 00:00:00 end: 2024-09-05 00:00:00 period: 5m basePeriod: 1m exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}] ''' import json def main(): arrSymbol = ["BTC_USDT.swap", "BTC_USDT.quarter", "ETH_USDT.swap", "ETH_USDT.quarter"] for symbol in arrSymbol: exchange.CreateOrder(symbol, "buy", -1, 1) exchange.CreateOrder(symbol, "sell", -1, 1) defaultPositions = exchange.GetPositions() swapPositions = exchange.GetPositions("USDT.swap") futuresPositions = exchange.GetPositions("USDT.futures") btcUsdtSwapPositions = exchange.GetPositions("BTC_USDT.swap") tbls = [] arr = [defaultPositions, swapPositions, futuresPositions, btcUsdtSwapPositions] tblDesc = ["defaultPositions", "swapPositions", "futuresPositions", "btcUsdtSwapPositions"] for index in range(len(arr)): positions = arr[index] tbl = {"type": "table", "title": tblDesc[index], "cols": ["Symbol", "MarginLevel", "Amount", "FrozenAmount", "Price", "Profit", "Type", "ContractType", "Margin"], "rows": []} for pos in positions: tbl["rows"].append([pos["Symbol"], pos["MarginLevel"], pos["Amount"], pos["FrozenAmount"], pos["Price"], pos["Profit"], pos["Type"], pos["ContractType"], pos["Margin"]]) tbls.append(tbl) LogStatus("`" + json.dumps(tbls) + "`") return
rust
/*backtest start: 2024-05-21 00:00:00 end: 2024-09-05 00:00:00 period: 5m basePeriod: 1m exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}] */ fn main() { let arrSymbol = ["BTC_USDT.swap", "BTC_USDT.quarter", "ETH_USDT.swap", "ETH_USDT.quarter"]; for symbol in arrSymbol { exchange.CreateOrder(symbol, "buy", -1, 1); exchange.CreateOrder(symbol, "sell", -1, 1); } let defaultPositions = exchange.GetPositions(None).unwrap(); let swapPositions = exchange.GetPositions("USDT.swap").unwrap(); let futuresPositions = exchange.GetPositions("USDT.futures").unwrap(); let btcUsdtSwapPositions = exchange.GetPositions("BTC_USDT.swap").unwrap(); // The Rust SDK has no JSON serialization; use format! to concatenate the table's JSON text let mut tbls: Vec<String> = Vec::new(); let arr = [defaultPositions, swapPositions, futuresPositions, btcUsdtSwapPositions]; let tblDesc = ["defaultPositions", "swapPositions", "futuresPositions", "btcUsdtSwapPositions"]; for (index, positions) in arr.iter().enumerate() { let mut rows: Vec<String> = Vec::new(); for pos in positions { rows.push(format!(r#"["{}", {}, {}, {}, {}, {}, {}, "{}", {}]"#, pos.Symbol, pos.MarginLevel, pos.Amount, pos.FrozenAmount, pos.Price, pos.Profit, pos.Type, pos.ContractType, pos.Margin)); } let tbl = format!(r#"{{"type": "table", "title": "{}", "cols": ["Symbol", "MarginLevel", "Amount", "FrozenAmount", "Price", "Profit", "Type", "ContractType", "Margin"], "rows": [{}]}}"#, tblDesc[index], rows.join(",")); tbls.push(tbl); } LogStatus!(format!("`[{}]`", tbls.join(","))); // After printing the information once, return to prevent subsequent order fills during backtesting from affecting data observation return; }
c++
/*backtest start: 2024-05-21 00:00:00 end: 2024-09-05 00:00:00 period: 5m basePeriod: 1m exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}] */ void main() { auto arrSymbol = {"BTC_USDT.swap", "BTC_USDT.quarter", "ETH_USDT.swap", "ETH_USDT.quarter"}; for (const auto& symbol : arrSymbol) { exchange.CreateOrder(symbol, "buy", -1, 1); exchange.CreateOrder(symbol, "sell", -1, 1); } auto defaultPositions = exchange.GetPositions(); auto swapPositions = exchange.GetPositions("USDT.swap"); auto futuresPositions = exchange.GetPositions("USDT.futures"); auto btcUsdtSwapPositions = exchange.GetPositions("BTC_USDT.swap"); json tbls = R"([])"_json; std::vector<std::vector<Position>> arr = {defaultPositions, swapPositions, futuresPositions, btcUsdtSwapPositions}; std::string tblDesc[] = {"defaultPositions", "swapPositions", "futuresPositions", "btcUsdtSwapPositions"}; for (int index = 0; index < arr.size(); index++) { auto positions = arr[index]; json tbl = R"({ "type": "table", "cols": ["Symbol", "MarginLevel", "Amount", "FrozenAmount", "Price", "Profit", "Type", "ContractType", "Margin"], "rows": [] })"_json; tbl["title"] = tblDesc[index]; for (const auto& pos : positions) { json arrJson = R"([])"_json; arrJson.push_back(pos.Symbol); arrJson.push_back(pos.MarginLevel); arrJson.push_back(pos.Amount); arrJson.push_back(pos.FrozenAmount); arrJson.push_back(pos.Price); arrJson.push_back(pos.Profit); arrJson.push_back(pos.Type); arrJson.push_back(pos.ContractType); arrJson.push_back(pos.Margin); tbl["rows"].push_back(arrJson); } tbls.push_back(tbl); } LogStatus(_D(), "\n", "`" + tbls.dump() + "`"); return; }

Returns

TypeDescription

Position array / null value

The exchange.GetPositions() function returns a Position structure array when the data request succeeds, and returns a null value when the data request fails.

Arguments

NameTypeRequiredDescription

symbol

string

No

The symbol parameter is used to specify the trading instrument or range of trading instruments to be queried.

When the symbol parameter is not passed in, by default it requests the position data of all instruments within the dimension range of the current trading pair and contract code.

See Also

Remarks

Cryptocurrency futures contracts are different from cryptocurrency spot; spot only has a logical concept of position. In the FMZ Quant Trading Platform system, the specific instrument of a cryptocurrency futures contract is jointly identified by the **trading pair** and the **contract code**. Refer to the exchange.SetCurrency and exchange.SetContractType functions.

In the GetPositions function, the usage scenarios of the symbol parameter are summarized as follows:

Exchange Object Categorysymbol ParameterQuery ScopeRemarks
Futuressymbol parameter not passedQuery all trading instruments within the dimension range of the current trading pair and contract codeIf the current trading pair is BTC_USDT and the contract code is swap, it queries all USDT-margined perpetual contracts. Equivalent to calling GetPositions("USDT.swap")
FuturesSpecify a trading instrument, symbol parameter is: "BTC_USDT.swap"Query the specified BTC USDT-margined perpetual contractFor a futures exchange object, the format of the symbol parameter is: the combination of the trading pair and contract code defined by the FMZ platform, separated by the character ".".
FuturesSpecify a range of trading instruments, symbol parameter is: "USDT.swap"Query all USDT-margined perpetual contracts-
Futures exchange supporting optionssymbol parameter not passedQuery all option contracts within the dimension range of the current trading pairIf the current trading pair is BTC_USDT and the contract is set to an option contract, for example, a Binance option contract: BTC-240108-40000-C
Futures exchange supporting optionsSpecify a specific trading instrumentQuery the specified option contractFor example, for the Binance futures exchange, the symbol parameter is: BTC_USDT.BTC-240108-40000-C
Futures exchange supporting optionsSpecify a range of trading instruments, symbol parameter is: "USDT.option"Query all USDT-margined option contracts-

In the GetPositions function, the query dimension ranges of the futures exchange object are summarized as follows:

symbol ParameterRequest Scope DefinitionRemarks
USDT.swapScope of USDT-margined perpetual contracts.For dimensions not supported by the exchange API interface, calling it will report an error and return a null value.
USDT.futuresScope of USDT-margined delivery contracts.-
USD.swapScope of coin-margined perpetual contracts.-
USD.futuresScope of coin-margined delivery contracts.-
USDT.optionScope of USDT-margined option contracts.-
USD.optionScope of coin-margined option contracts.-
USDT.futures_comboScope of spread combo contracts.Futures_Deribit exchange
USD.futures_ffScope of mixed-margin delivery contracts.Futures_Kraken exchange
USD.swap_pfScope of mixed-margin perpetual contracts.Futures_Kraken exchange

Compatible with the exchange.GetPosition() call; GetPosition and GetPositions are used in exactly the same way.

When the account represented by the exchange object exchange has no positions within the query scope or on the specified trading instrument, the exchange.GetPositions() function returns an empty array, for example: [].