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

Method parsePosition

ts/src/cryptocom.ts:3277–3323  ·  view source on GitHub ↗
(position: Dict, market: Market = undefined)

Source from the content-addressed store, hash-verified

3275 }
3276
3277 parsePosition (position: Dict, market: Market = undefined) {
3278 //
3279 // {
3280 // "account_id": "ce075bef-b600-4277-bd6e-ff9007251e63",
3281 // "quantity": "0.0001",
3282 // "cost": "3.02392",
3283 // "open_pos_cost": "3.02392",
3284 // "open_position_pnl": "-0.0010281328",
3285 // "session_pnl": "-0.0010281328",
3286 // "update_timestamp_ms": 1688015919091,
3287 // "instrument_name": "BTCUSD-PERP",
3288 // "type": "PERPETUAL_SWAP"
3289 // }
3290 //
3291 const marketId = this.safeString (position, 'instrument_name');
3292 market = this.safeMarket (marketId, market, undefined, 'contract');
3293 const symbol = this.safeSymbol (marketId, market, undefined, 'contract');
3294 const timestamp = this.safeInteger (position, 'update_timestamp_ms');
3295 const amount = this.safeString (position, 'quantity');
3296 return this.safePosition ({
3297 'info': position,
3298 'id': undefined,
3299 'symbol': symbol,
3300 'timestamp': timestamp,
3301 'datetime': this.iso8601 (timestamp),
3302 'hedged': undefined,
3303 'side': Precise.stringGt (amount, '0') ? 'buy' : 'sell',
3304 'contracts': Precise.stringAbs (amount),
3305 'contractSize': market['contractSize'],
3306 'entryPrice': undefined,
3307 'markPrice': undefined,
3308 'notional': undefined,
3309 'leverage': undefined,
3310 'collateral': this.safeNumber (position, 'open_pos_cost'),
3311 'initialMargin': this.safeNumber (position, 'cost'),
3312 'maintenanceMargin': undefined,
3313 'initialMarginPercentage': undefined,
3314 'maintenanceMarginPercentage': undefined,
3315 'unrealizedPnl': this.safeNumber (position, 'open_position_pnl'),
3316 'liquidationPrice': undefined,
3317 'marginMode': undefined,
3318 'percentage': undefined,
3319 'marginRatio': undefined,
3320 'stopLossPrice': undefined,
3321 'takeProfitPrice': undefined,
3322 });
3323 }
3324
3325 nonce () {
3326 return this.milliseconds ();

Callers 3

fetchPositionMethod · 0.95
fetchPositionsMethod · 0.95
handlePositionsMethod · 0.95

Calls 9

safeStringMethod · 0.45
safeMarketMethod · 0.45
safeSymbolMethod · 0.45
safeIntegerMethod · 0.45
safePositionMethod · 0.45
iso8601Method · 0.45
stringGtMethod · 0.45
stringAbsMethod · 0.45
safeNumberMethod · 0.45

Tested by

no test coverage detected