MCPcopy Create free account
hub / github.com/ccxt/ccxt / parse_account_positions

Method parse_account_positions

python/ccxt/async_support/aster.py:3460–3491  ·  view source on GitHub ↗
(self, account, filterClosed=False)

Source from the content-addressed store, hash-verified

3458 raise NotSupported(self.id + '.options["fetchPositions"]["method"] or params["method"] = "' + defaultMethod + '" is invalid, please choose between "account" and "positionRisk"')
3459
3460 def parse_account_positions(self, account, filterClosed=False):
3461 positions = self.safe_list(account, 'positions', [])
3462 assets = self.safe_list(account, 'assets', [])
3463 balances = {}
3464 for i in range(0, len(assets)):
3465 entry = assets[i]
3466 currencyId = self.safe_string(entry, 'asset')
3467 code = self.safe_currency_code(currencyId)
3468 crossWalletBalance = self.safe_string(entry, 'crossWalletBalance')
3469 crossUnPnl = self.safe_string(entry, 'crossUnPnl')
3470 balances[code] = {
3471 'crossMargin': Precise.string_add(crossWalletBalance, crossUnPnl),
3472 'crossWalletBalance': crossWalletBalance,
3473 }
3474 result = []
3475 for i in range(0, len(positions)):
3476 position = positions[i]
3477 marketId = self.safe_string(position, 'symbol')
3478 market = self.safe_market(marketId, None, None, 'contract')
3479 code = market['quote'] if market['linear'] else market['base']
3480 maintenanceMargin = self.safe_string(position, 'maintMargin')
3481 # check for maintenance margin so empty positions are not returned
3482 isPositionOpen = (maintenanceMargin != '0') and (maintenanceMargin != '0.00000000')
3483 if not filterClosed or isPositionOpen:
3484 # sometimes not all the codes are correctly returned...
3485 if code in balances:
3486 parsed = self.parse_account_position(self.extend(position, {
3487 'crossMargin': balances[code]['crossMargin'],
3488 'crossWalletBalance': balances[code]['crossWalletBalance'],
3489 }), market)
3490 result.append(parsed)
3491 return result
3492
3493 def parse_account_position(self, position, market: Market = None):
3494 marketId = self.safe_string(position, 'symbol')

Callers 1

Calls 9

safe_listMethod · 0.80
safe_stringMethod · 0.80
string_addMethod · 0.80
rangeFunction · 0.50
safe_currency_codeMethod · 0.45
safe_marketMethod · 0.45
extendMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected