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

Method parse_position

python/ccxt/apex.py:1814–1864  ·  view source on GitHub ↗
(self, position: dict, market: Market = None)

Source from the content-addressed store, hash-verified

1812 return self.parse_positions(positions, symbols)
1813
1814 def parse_position(self, position: dict, market: Market = None):
1815 #
1816 # {
1817 # "symbol": "BTC-USDT",
1818 # "status": "",
1819 # "side": "LONG",
1820 # "size": "0.000",
1821 # "entryPrice": "0.00",
1822 # "exitPrice": "",
1823 # "createdAt": 1690366452416,
1824 # "updatedTime": 1690366452416,
1825 # "fee": "0.000000",
1826 # "fundingFee": "0.000000",
1827 # "lightNumbers": "",
1828 # "customInitialMarginRate": "0"
1829 # }
1830 marketId = self.safe_string(position, 'symbol')
1831 market = self.safe_market(marketId, market)
1832 symbol = market['symbol']
1833 side = self.safe_string_lower(position, 'side')
1834 quantity = self.safe_string(position, 'size')
1835 timestamp = self.safe_integer(position, 'updatedTime')
1836 leverage = 20
1837 customInitialMarginRate = self.safe_string_n(position, ['customInitialMarginRate', 'customImr'], '0')
1838 if self.precision_from_string(customInitialMarginRate) != 0:
1839 leverage = self.parse_to_int(Precise.string_div('1', customInitialMarginRate, 4))
1840 return self.safe_position({
1841 'info': position,
1842 'id': self.safe_string(position, 'id'),
1843 'symbol': symbol,
1844 'entryPrice': self.safe_string(position, 'entryPrice'),
1845 'markPrice': None,
1846 'notional': None,
1847 'collateral': None,
1848 'unrealizedPnl': None,
1849 'side': side,
1850 'contracts': self.parse_number(quantity),
1851 'contractSize': None,
1852 'timestamp': timestamp,
1853 'datetime': self.iso8601(timestamp),
1854 'hedged': None,
1855 'maintenanceMargin': None,
1856 'maintenanceMarginPercentage': None,
1857 'initialMargin': None,
1858 'initialMarginPercentage': None,
1859 'leverage': leverage,
1860 'liquidationPrice': None,
1861 'marginRatio': None,
1862 'marginMode': None,
1863 'percentage': None,
1864 })
1865
1866 def sign(self, path, api: Any = 'public', method='GET', params={}, headers: dict = None, body: Str = None):
1867 url = self.implode_hostname(self.urls['api'][api]) + '/' + path

Callers

nothing calls this directly

Calls 11

safe_marketMethod · 0.95
safe_stringMethod · 0.80
safe_string_lowerMethod · 0.80
safe_integerMethod · 0.80
safe_string_nMethod · 0.80
precision_from_stringMethod · 0.80
parse_to_intMethod · 0.80
string_divMethod · 0.80
safe_positionMethod · 0.80
parse_numberMethod · 0.80
iso8601Method · 0.45

Tested by

no test coverage detected