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

Method fetchPositions

ts/src/cryptocom.ts:3223–3275  ·  view source on GitHub ↗

* @method * @name cryptocom#fetchPositions * @description fetch all open positions * @see https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#private-get-positions * @param {string[]|undefined} symbols list of unified market symbols * @param {object} [params] ext

(symbols: Strings = undefined, params = {})

Source from the content-addressed store, hash-verified

3221 * @returns {object[]} a list of [position structure]{@link https://docs.ccxt.com/?id=position-structure}
3222 */
3223 async fetchPositions (symbols: Strings = undefined, params = {}): Promise<Position[]> {
3224 await this.loadMarkets ();
3225 symbols = this.marketSymbols (symbols);
3226 const request: Dict = {};
3227 let market: Market = undefined;
3228 if (symbols !== undefined) {
3229 let symbol: Str = undefined;
3230 if (Array.isArray (symbols)) {
3231 const symbolsLength = symbols.length;
3232 if (symbolsLength > 1) {
3233 throw new BadRequest (this.id + ' fetchPositions() symbols argument cannot contain more than 1 symbol');
3234 }
3235 symbol = symbols[0];
3236 } else {
3237 symbol = symbols;
3238 }
3239 market = this.market (symbol);
3240 request['instrument_name'] = market['id'];
3241 }
3242 const response = await this.v1PrivatePostPrivateGetPositions (this.extend (request, params));
3243 //
3244 // {
3245 // "id": 1688015952050,
3246 // "method": "private/get-positions",
3247 // "code": 0,
3248 // "result": {
3249 // "data": [
3250 // {
3251 // "account_id": "ce075bef-b600-4277-bd6e-ff9007251e63",
3252 // "quantity": "0.0001",
3253 // "cost": "3.02392",
3254 // "open_pos_cost": "3.02392",
3255 // "open_position_pnl": "-0.0010281328",
3256 // "session_pnl": "-0.0010281328",
3257 // "update_timestamp_ms": 1688015919091,
3258 // "instrument_name": "BTCUSD-PERP",
3259 // "type": "PERPETUAL_SWAP"
3260 // }
3261 // ]
3262 // }
3263 // }
3264 //
3265 const responseResult = this.safeDict (response, 'result', {});
3266 const positions = this.safeList (responseResult, 'data', []);
3267 const result: any[] = [];
3268 for (let i = 0; i < positions.length; i++) {
3269 const entry = positions[i];
3270 const marketId = this.safeString (entry, 'instrument_name');
3271 const marketInner = this.safeMarket (marketId, undefined, undefined, 'contract');
3272 result.push (this.parsePosition (entry, marketInner));
3273 }
3274 return this.filterByArrayPositions (result, 'symbol', undefined, false);
3275 }
3276
3277 parsePosition (position: Dict, market: Market = undefined) {
3278 //

Callers 1

loadPositionsSnapshotMethod · 0.95

Calls 13

parsePositionMethod · 0.95
pushMethod · 0.80
loadMarketsMethod · 0.45
marketSymbolsMethod · 0.45
isArrayMethod · 0.45
marketMethod · 0.45
extendMethod · 0.45
safeDictMethod · 0.45
safeListMethod · 0.45
safeStringMethod · 0.45
safeMarketMethod · 0.45

Tested by

no test coverage detected