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

Method parse_position

python/ccxt/hyperliquid.py:3463–3537  ·  view source on GitHub ↗
(self, position: dict, market: Market = None)

Source from the content-addressed store, hash-verified

3461 return self.filter_by_array_positions(result, 'symbol', symbols, False)
3462
3463 def parse_position(self, position: dict, market: Market = None):
3464 #
3465 # {
3466 # "position": {
3467 # "coin": "ETH",
3468 # "cumFunding": {
3469 # "allTime": "0.0",
3470 # "sinceChange": "0.0",
3471 # "sinceOpen": "0.0"
3472 # },
3473 # "entryPx": "2213.9",
3474 # "leverage": {
3475 # "rawUsd": "-475.23904",
3476 # "type": "isolated",
3477 # "value": "20"
3478 # },
3479 # "liquidationPx": "2125.00856238",
3480 # "marginUsed": "24.88097",
3481 # "maxLeverage": "50",
3482 # "positionValue": "500.12001",
3483 # "returnOnEquity": "0.0",
3484 # "szi": "0.2259",
3485 # "unrealizedPnl": "0.0"
3486 # },
3487 # "type": "oneWay"
3488 # }
3489 #
3490 entry = self.safe_dict(position, 'position', {})
3491 coin = self.safe_string(entry, 'coin')
3492 marketId = self.coin_to_market_id(coin)
3493 market = self.safe_market(marketId, None)
3494 symbol = market['symbol']
3495 leverage = self.safe_dict(entry, 'leverage', {})
3496 marginMode = self.safe_string(leverage, 'type')
3497 isIsolated = (marginMode == 'isolated')
3498 rawSize = self.safe_string(entry, 'szi')
3499 size = rawSize
3500 side = None
3501 if size is not None:
3502 side = 'long' if Precise.string_gt(rawSize, '0') else 'short'
3503 size = Precise.string_abs(size)
3504 rawUnrealizedPnl = self.safe_string(entry, 'unrealizedPnl')
3505 absRawUnrealizedPnl = Precise.string_abs(rawUnrealizedPnl)
3506 marginUsed = self.safe_string(entry, 'marginUsed')
3507 initialMargin = None
3508 if isIsolated:
3509 initialMargin = Precise.string_sub(marginUsed, rawUnrealizedPnl)
3510 else:
3511 initialMargin = marginUsed
3512 percentage = Precise.string_mul(Precise.string_div(absRawUnrealizedPnl, marginUsed), '100')
3513 return self.safe_position({
3514 'info': position,
3515 'id': None,
3516 'symbol': symbol,
3517 'timestamp': None,
3518 'datetime': None,
3519 'isolated': isIsolated,
3520 'hedged': None,

Callers 1

fetch_positionsMethod · 0.95

Calls 12

coin_to_market_idMethod · 0.95
safe_dictMethod · 0.80
safe_stringMethod · 0.80
string_gtMethod · 0.80
string_absMethod · 0.80
string_subMethod · 0.80
string_mulMethod · 0.80
string_divMethod · 0.80
safe_positionMethod · 0.80
parse_numberMethod · 0.80
safe_numberMethod · 0.80
safe_marketMethod · 0.45

Tested by

no test coverage detected