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

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

The GetPositions() function gets the position information of the exchange account bound to the exchange object exchange. The purpose of member functions (methods) of the exchange object is only related to exchange, which will not be repeated in subsequent documentation.

exchange.GetPositions()
exchange.GetPositions(symbol)

Examples

Use futures exchange object to place market orders for multiple different trading pairs and contract codes. Query positions in various ways.

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) + "`") // Print output information once and return to prevent subsequent order execution during backtesting, which would affect 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
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

The exchange.GetPositions() function returns a Position structure array when data request is successful, and returns null when data request fails.

Arguments

NameTypeRequiredDescription

symbol

string

No

The symbol parameter is used to set the trading symbol or range of trading symbols to be queried.

When the symbol parameter is not passed, it defaults to requesting position data for all symbols within the dimension range of the current trading pair and contract code.

See Also

Remarks

Cryptocurrency futures contracts differ from cryptocurrency spot trading, where spot only has a logical position concept. In the FMZ quantitative trading platform system, specific cryptocurrency futures contract varieties are identified by both **trading pair** and **contract code**. Please refer to exchange.SetCurrency and exchange.SetContractType functions.

Summary of symbol parameter usage scenarios in the GetPositions function:

Exchange Object Categorysymbol ParameterQuery ScopeNotes
FuturesNo symbol parameterQuery all trading varieties within current trading pair and contract code dimensionIf current trading pair is BTC_USDT and contract code is swap, it queries all USDT-margined perpetual contracts. Equivalent to calling GetPositions("USDT.swap")
FuturesSpecify trading variety, symbol parameter: "BTC_USDT.swap"Query specified BTC USDT-margined perpetual contractFor futures exchange objects, the symbol parameter format is: FMZ platform-defined trading pair and contract code combination, separated by . character.
FuturesSpecify trading variety range, symbol parameter: "USDT.swap"Query all USDT-margined perpetual contracts-
Futures exchanges supporting optionsNo symbol parameterQuery all option contracts within current trading pair dimensionIf current trading pair is BTC_USDT and contract is set to option contract, e.g., Binance option contract: BTC-240108-40000-C
Futures exchanges supporting optionsSpecify specific trading varietyQuery specified option contractFor example, for Binance futures exchange, symbol parameter: BTC_USDT.BTC-240108-40000-C
Futures exchanges supporting optionsSpecify trading variety range, symbol parameter: "USDT.option"Query all USDT-margined option contracts-

Summary of futures exchange object query dimension ranges in the GetPositions function:

symbol ParameterRequest Scope DefinitionNotes
USDT.swapUSDT-margined perpetual contract range.For dimensions not supported by exchange API interfaces, calls will return an error with null value.
USDT.futuresUSDT-margined delivery contract range.-
USD.swapCoin-margined perpetual contract range.-
USD.futuresCoin-margined delivery contract range.-
USDT.optionUSDT-margined option contract range.-
USD.optionCoin-margined option contract range.-
USDT.futures_comboSpread combination contract range.Futures_Deribit exchange
USD.futures_ffMulti-collateral delivery contract range.Futures_Kraken exchange
USD.swap_pfMulti-collateral perpetual contract range.Futures_Kraken exchange

Compatible with exchange.GetPosition() call, GetPosition and GetPositions usage is completely identical.

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