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

Method parse_position

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

Source from the content-addressed store, hash-verified

1747 return self.parse_positions(result, symbols)
1748
1749 def parse_position(self, position: dict, market: Market = None):
1750 #
1751 # fetchPosition
1752 #
1753 # {
1754 # "entry_price":null,
1755 # "size":0,
1756 # "timestamp":1605454074268079
1757 # }
1758 #
1759 #
1760 # fetchPositions
1761 #
1762 # {
1763 # "user_id": 0,
1764 # "size": 0,
1765 # "entry_price": "string",
1766 # "margin": "string",
1767 # "liquidation_price": "string",
1768 # "bankruptcy_price": "string",
1769 # "adl_level": 0,
1770 # "product_id": 0,
1771 # "product_symbol": "string",
1772 # "commission": "string",
1773 # "realized_pnl": "string",
1774 # "realized_funding": "string"
1775 # }
1776 #
1777 marketId = self.safe_string(position, 'product_symbol')
1778 market = self.safe_market(marketId, market)
1779 symbol = market['symbol']
1780 timestamp = self.safe_integer_product(position, 'timestamp', 0.001)
1781 sizeString = self.safe_string(position, 'size')
1782 side = None
1783 if sizeString is not None:
1784 if Precise.string_gt(sizeString, '0'):
1785 side = 'buy'
1786 elif Precise.string_lt(sizeString, '0'):
1787 side = 'sell'
1788 return self.safe_position({
1789 'info': position,
1790 'id': None,
1791 'symbol': symbol,
1792 'notional': None,
1793 'marginMode': None,
1794 'liquidationPrice': self.safe_number(position, 'liquidation_price'),
1795 'entryPrice': self.safe_number(position, 'entry_price'),
1796 'unrealizedPnl': None, # todo - realized_pnl ?
1797 'percentage': None,
1798 'contracts': self.parse_number(sizeString),
1799 'contractSize': self.safe_number(market, 'contractSize'),
1800 'markPrice': None,
1801 'side': side,
1802 'hedged': None,
1803 'timestamp': timestamp,
1804 'datetime': self.iso8601(timestamp),
1805 'maintenanceMargin': None,
1806 'maintenanceMarginPercentage': None,

Callers 2

fetch_positionMethod · 0.95
close_all_positionsMethod · 0.95

Calls 9

safe_marketMethod · 0.95
safe_stringMethod · 0.80
safe_integer_productMethod · 0.80
string_gtMethod · 0.80
string_ltMethod · 0.80
safe_positionMethod · 0.80
safe_numberMethod · 0.80
parse_numberMethod · 0.80
iso8601Method · 0.45

Tested by

no test coverage detected