* @method * @name bitget#fetchPositions * @description fetch all open positions * @see https://www.bitget.com/api-doc/contract/position/get-all-position * @see https://www.bitget.com/api-doc/contract/position/Get-History-Position * @see https://www.bitget.com/api-doc/uta/tra
(symbols = undefined, params = {})
| 8075 | * @returns {object[]} a list of [position structure]{@link https://docs.ccxt.com/?id=position-structure} |
| 8076 | */ |
| 8077 | async fetchPositions(symbols = undefined, params = {}) { |
| 8078 | await this.loadMarkets(); |
| 8079 | let paginate = false; |
| 8080 | [paginate, params] = this.handleOptionAndParams(params, 'fetchPositions', 'paginate'); |
| 8081 | if (paginate) { |
| 8082 | return await this.fetchPaginatedCallCursor('fetchPositions', undefined, undefined, undefined, params, 'endId', 'idLessThan'); |
| 8083 | } |
| 8084 | let method = undefined; |
| 8085 | const useHistoryEndpoint = this.safeBool(params, 'useHistoryEndpoint', false); |
| 8086 | if (useHistoryEndpoint) { |
| 8087 | method = 'privateMixGetV2MixPositionHistoryPosition'; |
| 8088 | } |
| 8089 | else { |
| 8090 | [method, params] = this.handleOptionAndParams(params, 'fetchPositions', 'method', 'privateMixGetV2MixPositionAllPosition'); |
| 8091 | } |
| 8092 | let market = undefined; |
| 8093 | if (symbols !== undefined) { |
| 8094 | const first = this.safeString(symbols, 0); |
| 8095 | // symbols can be undefined or [] |
| 8096 | if (first !== undefined) { |
| 8097 | market = this.market(first); |
| 8098 | } |
| 8099 | } |
| 8100 | let productType = undefined; |
| 8101 | [productType, params] = this.handleProductTypeAndParams(market, params); |
| 8102 | const request = {}; |
| 8103 | let response = undefined; |
| 8104 | let isHistory = false; |
| 8105 | let uta = undefined; |
| 8106 | [uta, params] = this.handleOptionAndParams(params, 'fetchPositions', 'uta', false); |
| 8107 | if (uta) { |
| 8108 | request['category'] = productType; |
| 8109 | response = await this.privateUtaGetV3PositionCurrentPosition(this.extend(request, params)); |
| 8110 | } |
| 8111 | else if (method === 'privateMixGetV2MixPositionAllPosition') { |
| 8112 | let marginCoin = this.safeString(params, 'marginCoin', 'USDT'); |
| 8113 | if (market !== undefined) { |
| 8114 | marginCoin = market['settleId']; |
| 8115 | } |
| 8116 | else if (productType === 'USDT-FUTURES') { |
| 8117 | marginCoin = 'USDT'; |
| 8118 | } |
| 8119 | else if (productType === 'USDC-FUTURES') { |
| 8120 | marginCoin = 'USDC'; |
| 8121 | } |
| 8122 | else if (productType === 'SUSDT-FUTURES') { |
| 8123 | marginCoin = 'SUSDT'; |
| 8124 | } |
| 8125 | else if (productType === 'SUSDC-FUTURES') { |
| 8126 | marginCoin = 'SUSDC'; |
| 8127 | } |
| 8128 | else if ((productType === 'SCOIN-FUTURES') || (productType === 'COIN-FUTURES')) { |
| 8129 | if (marginCoin === undefined) { |
| 8130 | throw new ArgumentsRequired(this.id + ' fetchPositions() requires a marginCoin parameter that matches the productType'); |
| 8131 | } |
| 8132 | } |
| 8133 | request['marginCoin'] = marginCoin; |
| 8134 | request['productType'] = productType; |
nothing calls this directly
no test coverage detected