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

Method fetch_position

python/ccxt/xt.py:4446–4501  ·  view source on GitHub ↗

fetch data on a single open contract trade position https://doc.xt.com/#futures_usergetPosition :param str symbol: unified market symbol of the market the position is held in :param dict params: extra parameters specific to the xt api endpoint :returns dict

(self, symbol: str, params={})

Source from the content-addressed store, hash-verified

4444 }
4445
4446 def fetch_position(self, symbol: str, params={}):
4447 """
4448 fetch data on a single open contract trade position
4449
4450 https://doc.xt.com/#futures_usergetPosition
4451
4452 :param str symbol: unified market symbol of the market the position is held in
4453 :param dict params: extra parameters specific to the xt api endpoint
4454 :returns dict: a `position structure <https://docs.ccxt.com/?id=position-structure>`
4455 """
4456 self.load_markets()
4457 market = self.market(symbol)
4458 request = {
4459 'symbol': market['id'],
4460 }
4461 subType = None
4462 subType, params = self.handle_sub_type_and_params('fetchPosition', market, params)
4463 response = None
4464 if subType == 'inverse':
4465 response = self.privateInverseGetFutureUserV1PositionList(self.extend(request, params))
4466 else:
4467 response = self.privateLinearGetFutureUserV1PositionList(self.extend(request, params))
4468 #
4469 # {
4470 # "returnCode": 0,
4471 # "msgInfo": "success",
4472 # "error": null,
4473 # "result": [
4474 # {
4475 # "symbol": "btc_usdt",
4476 # "positionType": "ISOLATED",
4477 # "positionSide": "SHORT",
4478 # "contractType": "PERPETUAL",
4479 # "positionSize": "10",
4480 # "closeOrderSize": "0",
4481 # "availableCloseSize": "10",
4482 # "entryPrice": "27060",
4483 # "openOrderSize": "0",
4484 # "isolatedMargin": "1.0824",
4485 # "openOrderMarginFrozen": "0",
4486 # "realizedProfit": "-0.00130138",
4487 # "autoMargin": False,
4488 # "leverage": 25
4489 # },
4490 # ]
4491 # }
4492 #
4493 positions = self.safe_value(response, 'result', [])
4494 for i in range(0, len(positions)):
4495 entry = positions[i]
4496 marketId = self.safe_string(entry, 'symbol')
4497 marketInner = self.safe_market(marketId, None, None, 'contract')
4498 positionSize = self.safe_string(entry, 'positionSize')
4499 if positionSize != '0':
4500 return self.parse_position(entry, marketInner)
4501 return None
4502
4503 def fetch_positions(self, symbols: Strings = None, params={}) -> List[Position]:

Callers 3

example_2Function · 0.45
mainFunction · 0.45

Calls 11

parse_positionMethod · 0.95
safe_valueMethod · 0.80
safe_stringMethod · 0.80
rangeFunction · 0.50
load_marketsMethod · 0.45
marketMethod · 0.45
extendMethod · 0.45
safe_marketMethod · 0.45

Tested by

no test coverage detected