ccxt 4.4.73 → 4.4.75
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -4
- package/dist/ccxt.browser.min.js +2 -2
- package/dist/cjs/ccxt.js +1 -11
- package/dist/cjs/src/ace.js +9 -6
- package/dist/cjs/src/alpaca.js +3 -0
- package/dist/cjs/src/ascendex.js +6 -0
- package/dist/cjs/src/base/Exchange.js +36 -14
- package/dist/cjs/src/bequant.js +1 -0
- package/dist/cjs/src/binanceusdm.js +1 -1
- package/dist/cjs/src/bit2c.js +30 -4
- package/dist/cjs/src/bitbank.js +32 -0
- package/dist/cjs/src/bitbns.js +1 -1
- package/dist/cjs/src/bitflyer.js +1 -0
- package/dist/cjs/src/bithumb.js +34 -0
- package/dist/cjs/src/bitmart.js +74 -7
- package/dist/cjs/src/bitopro.js +37 -0
- package/dist/cjs/src/blofin.js +1 -1
- package/dist/cjs/src/bybit.js +14 -1
- package/dist/cjs/src/coinlist.js +87 -11
- package/dist/cjs/src/deribit.js +29 -1
- package/dist/cjs/src/gate.js +12 -7
- package/dist/cjs/src/hitbtc.js +7 -1
- package/dist/cjs/src/okx.js +29 -25
- package/dist/cjs/src/pro/ascendex.js +1 -1
- package/dist/cjs/src/pro/bingx.js +10 -1
- package/dist/cjs/src/pro/bitget.js +10 -1
- package/dist/cjs/src/pro/bitmart.js +10 -1
- package/dist/cjs/src/pro/bitopro.js +5 -4
- package/dist/cjs/src/pro/onetrading.js +7 -7
- package/js/ccxt.d.ts +2 -14
- package/js/ccxt.js +2 -10
- package/js/src/abstract/bitmart.d.ts +2 -0
- package/js/src/abstract/coinlist.d.ts +3 -0
- package/js/src/ace.js +9 -6
- package/js/src/alpaca.js +3 -0
- package/js/src/ascendex.js +6 -0
- package/js/src/base/Exchange.d.ts +1 -0
- package/js/src/base/Exchange.js +36 -14
- package/js/src/bequant.js +1 -0
- package/js/src/binanceusdm.js +1 -1
- package/js/src/bit2c.js +30 -4
- package/js/src/bitbank.js +32 -0
- package/js/src/bitbns.js +1 -1
- package/js/src/bitflyer.js +1 -0
- package/js/src/bithumb.js +34 -0
- package/js/src/bitmart.d.ts +24 -0
- package/js/src/bitmart.js +74 -7
- package/js/src/bitopro.js +37 -0
- package/js/src/blofin.js +1 -1
- package/js/src/bybit.js +14 -1
- package/js/src/coinlist.js +87 -11
- package/js/src/deribit.js +29 -1
- package/js/src/gate.js +12 -7
- package/js/src/hitbtc.js +7 -1
- package/js/src/okx.js +29 -25
- package/js/src/pro/ascendex.js +1 -1
- package/js/src/pro/bingx.js +10 -1
- package/js/src/pro/bitget.js +10 -1
- package/js/src/pro/bitmart.js +10 -1
- package/js/src/pro/bitopro.js +5 -4
- package/js/src/pro/onetrading.d.ts +7 -7
- package/js/src/pro/onetrading.js +7 -7
- package/package.json +1 -1
- package/js/src/abstract/bitcoincom.d.ts +0 -118
- package/js/src/abstract/bitcoincom.js +0 -11
- package/js/src/abstract/bitfinex1.d.ts +0 -72
- package/js/src/abstract/bitfinex1.js +0 -11
- package/js/src/abstract/bitpanda.d.ts +0 -26
- package/js/src/abstract/bitpanda.js +0 -11
- package/js/src/abstract/poloniexfutures.d.ts +0 -51
- package/js/src/abstract/poloniexfutures.js +0 -11
- package/js/src/abstract/wazirx.d.ts +0 -33
- package/js/src/abstract/wazirx.js +0 -11
- package/js/src/bitcoincom.d.ts +0 -4
- package/js/src/bitcoincom.js +0 -18
- package/js/src/bitpanda.d.ts +0 -4
- package/js/src/bitpanda.js +0 -17
- package/js/src/poloniexfutures.d.ts +0 -321
- package/js/src/poloniexfutures.js +0 -1941
- package/js/src/pro/bitcoincom.d.ts +0 -4
- package/js/src/pro/bitcoincom.js +0 -34
- package/js/src/pro/bitpanda.d.ts +0 -4
- package/js/src/pro/bitpanda.js +0 -17
- package/js/src/pro/poloniexfutures.d.ts +0 -108
- package/js/src/pro/poloniexfutures.js +0 -1042
- package/js/src/pro/wazirx.d.ts +0 -102
- package/js/src/pro/wazirx.js +0 -784
- package/js/src/static_dependencies/starknet/utils/json.d.ts +0 -24
- package/js/src/static_dependencies/starknet/utils/json.js +0 -43
|
@@ -1,1941 +0,0 @@
|
|
|
1
|
-
// ----------------------------------------------------------------------------
|
|
2
|
-
|
|
3
|
-
// PLEASE DO NOT EDIT THIS FILE, IT IS GENERATED AND WILL BE OVERWRITTEN:
|
|
4
|
-
// https://github.com/ccxt/ccxt/blob/master/CONTRIBUTING.md#how-to-contribute-code
|
|
5
|
-
// EDIT THE CORRESPONDENT .ts FILE INSTEAD
|
|
6
|
-
|
|
7
|
-
// ---------------------------------------------------------------------------
|
|
8
|
-
import { Precise } from './base/Precise.js';
|
|
9
|
-
import Exchange from './abstract/poloniexfutures.js';
|
|
10
|
-
import { TICK_SIZE } from './base/functions/number.js';
|
|
11
|
-
import { BadRequest, ArgumentsRequired, InvalidOrder, AuthenticationError, NotSupported, RateLimitExceeded, ExchangeNotAvailable, InvalidNonce, AccountSuspended, OrderNotFound } from './base/errors.js';
|
|
12
|
-
import { sha256 } from './static_dependencies/noble-hashes/sha256.js';
|
|
13
|
-
// ---------------------------------------------------------------------------
|
|
14
|
-
/**
|
|
15
|
-
* @class poloniexfutures
|
|
16
|
-
* @augments Exchange
|
|
17
|
-
*/
|
|
18
|
-
export default class poloniexfutures extends Exchange {
|
|
19
|
-
describe() {
|
|
20
|
-
return this.deepExtend(super.describe(), {
|
|
21
|
-
'id': 'poloniexfutures',
|
|
22
|
-
'name': 'Poloniex Futures',
|
|
23
|
-
'countries': ['US'],
|
|
24
|
-
// 30 requests per second
|
|
25
|
-
'rateLimit': 33.3,
|
|
26
|
-
'certified': false,
|
|
27
|
-
'pro': true,
|
|
28
|
-
'version': 'v1',
|
|
29
|
-
'has': {
|
|
30
|
-
'CORS': undefined,
|
|
31
|
-
'spot': false,
|
|
32
|
-
'margin': true,
|
|
33
|
-
'swap': true,
|
|
34
|
-
'future': false,
|
|
35
|
-
'option': undefined,
|
|
36
|
-
'createOrder': true,
|
|
37
|
-
'createStopOrder': true,
|
|
38
|
-
'createTriggerOrder': true,
|
|
39
|
-
'fetchBalance': true,
|
|
40
|
-
'fetchClosedOrders': true,
|
|
41
|
-
'fetchCurrencies': false,
|
|
42
|
-
'fetchDepositAddress': false,
|
|
43
|
-
'fetchDepositAddresses': false,
|
|
44
|
-
'fetchDepositAddressesByNetwork': false,
|
|
45
|
-
'fetchFundingInterval': true,
|
|
46
|
-
'fetchFundingIntervals': false,
|
|
47
|
-
'fetchFundingRate': true,
|
|
48
|
-
'fetchFundingRateHistory': false,
|
|
49
|
-
'fetchL3OrderBook': true,
|
|
50
|
-
'fetchMarkets': true,
|
|
51
|
-
'fetchMyTrades': true,
|
|
52
|
-
'fetchOHLCV': true,
|
|
53
|
-
'fetchOpenOrders': true,
|
|
54
|
-
'fetchOrder': true,
|
|
55
|
-
'fetchOrderBook': true,
|
|
56
|
-
'fetchOrdersByStatus': true,
|
|
57
|
-
'fetchPositions': true,
|
|
58
|
-
'fetchTicker': true,
|
|
59
|
-
'fetchTickers': true,
|
|
60
|
-
'fetchTime': true,
|
|
61
|
-
'fetchTrades': true,
|
|
62
|
-
'setMarginMode': true,
|
|
63
|
-
},
|
|
64
|
-
'timeframes': {
|
|
65
|
-
'1m': 1,
|
|
66
|
-
'5m': 5,
|
|
67
|
-
'15m': 15,
|
|
68
|
-
'30m': 30,
|
|
69
|
-
'1h': 60,
|
|
70
|
-
'2h': 120,
|
|
71
|
-
'4h': 480,
|
|
72
|
-
'12h': 720,
|
|
73
|
-
'1d': 1440,
|
|
74
|
-
'1w': 10080,
|
|
75
|
-
},
|
|
76
|
-
'urls': {
|
|
77
|
-
'logo': 'https://user-images.githubusercontent.com/1294454/27766817-e9456312-5ee6-11e7-9b3c-b628ca5626a5.jpg',
|
|
78
|
-
'api': {
|
|
79
|
-
'public': 'https://futures-api.poloniex.com',
|
|
80
|
-
'private': 'https://futures-api.poloniex.com',
|
|
81
|
-
},
|
|
82
|
-
'www': 'https://www.poloniex.com',
|
|
83
|
-
'doc': 'https://api-docs.poloniex.com/futures/',
|
|
84
|
-
'fees': 'https://poloniex.com/fee-schedule',
|
|
85
|
-
'referral': 'https://poloniex.com/signup?c=UBFZJRPJ',
|
|
86
|
-
},
|
|
87
|
-
'api': {
|
|
88
|
-
'public': {
|
|
89
|
-
'get': {
|
|
90
|
-
'contracts/active': 10,
|
|
91
|
-
'contracts/{symbol}': 10,
|
|
92
|
-
'ticker': 10,
|
|
93
|
-
'tickers': 10,
|
|
94
|
-
'level2/snapshot': 180.002,
|
|
95
|
-
'level2/depth': 180.002,
|
|
96
|
-
'level2/message/query': 180.002,
|
|
97
|
-
'level3/snapshot': 180.002,
|
|
98
|
-
'trade/history': 10,
|
|
99
|
-
'interest/query': 10,
|
|
100
|
-
'index/query': 10,
|
|
101
|
-
'mark-price/{symbol}/current': 10,
|
|
102
|
-
'premium/query': 10,
|
|
103
|
-
'funding-rate/{symbol}/current': 10,
|
|
104
|
-
'timestamp': 10,
|
|
105
|
-
'status': 10,
|
|
106
|
-
'kline/query': 10,
|
|
107
|
-
},
|
|
108
|
-
'post': {
|
|
109
|
-
'bullet-public': 10,
|
|
110
|
-
},
|
|
111
|
-
},
|
|
112
|
-
'private': {
|
|
113
|
-
'get': {
|
|
114
|
-
'account-overview': 1,
|
|
115
|
-
'transaction-history': 1,
|
|
116
|
-
'maxActiveOrders': 1,
|
|
117
|
-
'maxRiskLimit': 1,
|
|
118
|
-
'userFeeRate': 1,
|
|
119
|
-
'marginType/query': 1,
|
|
120
|
-
'orders': 1,
|
|
121
|
-
'stopOrders': 1,
|
|
122
|
-
'recentDoneOrders': 1,
|
|
123
|
-
'orders/{order-id}': 1,
|
|
124
|
-
'clientOrderId/{clientOid}': 1,
|
|
125
|
-
'fills': 1,
|
|
126
|
-
'openOrderStatistics': 1,
|
|
127
|
-
'position': 1.5,
|
|
128
|
-
'positions': 1.5,
|
|
129
|
-
'funding-history': 1,
|
|
130
|
-
},
|
|
131
|
-
'post': {
|
|
132
|
-
'orders': 1.5,
|
|
133
|
-
'batchOrders': 1.5,
|
|
134
|
-
'position/margin/auto-deposit-status': 1.5,
|
|
135
|
-
'position/margin/deposit-margin': 1.5,
|
|
136
|
-
'position/margin/withdraw-margin': 1.5,
|
|
137
|
-
'bullet-private': 1,
|
|
138
|
-
'marginType/change': 1,
|
|
139
|
-
},
|
|
140
|
-
'delete': {
|
|
141
|
-
'orders/{order-id}': 1.5,
|
|
142
|
-
'orders': 150.016,
|
|
143
|
-
'stopOrders': 150.016,
|
|
144
|
-
},
|
|
145
|
-
},
|
|
146
|
-
},
|
|
147
|
-
'precisionMode': TICK_SIZE,
|
|
148
|
-
'fees': {
|
|
149
|
-
'trading': {
|
|
150
|
-
'tierBased': false,
|
|
151
|
-
'percentage': true,
|
|
152
|
-
'taker': this.parseNumber('0.00075'),
|
|
153
|
-
'maker': this.parseNumber('0.0001'),
|
|
154
|
-
},
|
|
155
|
-
'funding': {
|
|
156
|
-
'tierBased': false,
|
|
157
|
-
'percentage': false,
|
|
158
|
-
'withdraw': {},
|
|
159
|
-
'deposit': {},
|
|
160
|
-
},
|
|
161
|
-
},
|
|
162
|
-
'commonCurrencies': {},
|
|
163
|
-
'requiredCredentials': {
|
|
164
|
-
'apiKey': true,
|
|
165
|
-
'secret': true,
|
|
166
|
-
'password': true,
|
|
167
|
-
},
|
|
168
|
-
'options': {
|
|
169
|
-
'networks': {
|
|
170
|
-
'OMNI': 'omni',
|
|
171
|
-
'ERC20': 'eth',
|
|
172
|
-
'TRC20': 'trx',
|
|
173
|
-
},
|
|
174
|
-
'versions': {
|
|
175
|
-
'public': {
|
|
176
|
-
'GET': {
|
|
177
|
-
'ticker': 'v2',
|
|
178
|
-
'tickers': 'v2',
|
|
179
|
-
'level3/snapshot': 'v2',
|
|
180
|
-
},
|
|
181
|
-
},
|
|
182
|
-
},
|
|
183
|
-
},
|
|
184
|
-
'features': {
|
|
185
|
-
'default': {
|
|
186
|
-
'sandbox': false,
|
|
187
|
-
'createOrder': {
|
|
188
|
-
'marginMode': false,
|
|
189
|
-
'triggerPrice': true,
|
|
190
|
-
// todo implementation
|
|
191
|
-
'triggerPriceType': {
|
|
192
|
-
'last': true,
|
|
193
|
-
'mark': true,
|
|
194
|
-
'index': true,
|
|
195
|
-
},
|
|
196
|
-
'triggerDirection': true,
|
|
197
|
-
'stopLossPrice': false,
|
|
198
|
-
'takeProfitPrice': false,
|
|
199
|
-
'attachedStopLossTakeProfit': undefined,
|
|
200
|
-
'timeInForce': {
|
|
201
|
-
'IOC': true,
|
|
202
|
-
'FOK': false,
|
|
203
|
-
'PO': true,
|
|
204
|
-
'GTD': false,
|
|
205
|
-
},
|
|
206
|
-
'hedged': false,
|
|
207
|
-
'leverage': true,
|
|
208
|
-
'marketBuyByCost': true,
|
|
209
|
-
'marketBuyRequiresPrice': false,
|
|
210
|
-
'selfTradePrevention': false,
|
|
211
|
-
'trailing': false,
|
|
212
|
-
'iceberg': true, // deprecated?
|
|
213
|
-
},
|
|
214
|
-
'createOrders': undefined,
|
|
215
|
-
'fetchMyTrades': {
|
|
216
|
-
'marginMode': false,
|
|
217
|
-
'limit': undefined,
|
|
218
|
-
'daysBack': 100000,
|
|
219
|
-
'untilDays': 7,
|
|
220
|
-
'symbolRequired': false,
|
|
221
|
-
},
|
|
222
|
-
'fetchOrder': {
|
|
223
|
-
'marginMode': false,
|
|
224
|
-
'trigger': false,
|
|
225
|
-
'trailing': false,
|
|
226
|
-
'symbolRequired': false,
|
|
227
|
-
},
|
|
228
|
-
'fetchOpenOrders': {
|
|
229
|
-
'marginMode': true,
|
|
230
|
-
'limit': undefined,
|
|
231
|
-
'trigger': false,
|
|
232
|
-
'trailing': false,
|
|
233
|
-
'symbolRequired': false,
|
|
234
|
-
},
|
|
235
|
-
'fetchOrders': undefined,
|
|
236
|
-
'fetchClosedOrders': {
|
|
237
|
-
'marginMode': false,
|
|
238
|
-
'limit': 100,
|
|
239
|
-
'daysBack': 100000,
|
|
240
|
-
'daysBackCanceled': 1,
|
|
241
|
-
'untilDays': 100000,
|
|
242
|
-
'trigger': false,
|
|
243
|
-
'trailing': false,
|
|
244
|
-
'symbolRequired': false,
|
|
245
|
-
},
|
|
246
|
-
'fetchOHLCV': {
|
|
247
|
-
'limit': 200, // todo implement
|
|
248
|
-
},
|
|
249
|
-
},
|
|
250
|
-
'spot': undefined,
|
|
251
|
-
'swap': {
|
|
252
|
-
'linear': {
|
|
253
|
-
'extends': 'default',
|
|
254
|
-
},
|
|
255
|
-
'inverse': undefined,
|
|
256
|
-
},
|
|
257
|
-
'future': {
|
|
258
|
-
'linear': undefined,
|
|
259
|
-
'inverse': undefined,
|
|
260
|
-
},
|
|
261
|
-
},
|
|
262
|
-
'exceptions': {
|
|
263
|
-
'exact': {
|
|
264
|
-
'400': BadRequest,
|
|
265
|
-
'401': AuthenticationError,
|
|
266
|
-
'403': NotSupported,
|
|
267
|
-
'404': NotSupported,
|
|
268
|
-
'405': NotSupported,
|
|
269
|
-
'415': BadRequest,
|
|
270
|
-
'429': RateLimitExceeded,
|
|
271
|
-
'500': ExchangeNotAvailable,
|
|
272
|
-
'503': ExchangeNotAvailable,
|
|
273
|
-
'400001': AuthenticationError,
|
|
274
|
-
'400002': InvalidNonce,
|
|
275
|
-
'400003': AuthenticationError,
|
|
276
|
-
'400004': AuthenticationError,
|
|
277
|
-
'400005': AuthenticationError,
|
|
278
|
-
'400006': AuthenticationError,
|
|
279
|
-
'400007': AuthenticationError,
|
|
280
|
-
'404000': NotSupported,
|
|
281
|
-
'400100': BadRequest,
|
|
282
|
-
'411100': AccountSuspended,
|
|
283
|
-
'500000': ExchangeNotAvailable, // Internal Server Error -- We had a problem with our server. Try again later.
|
|
284
|
-
},
|
|
285
|
-
'broad': {
|
|
286
|
-
'Position does not exist': OrderNotFound, // { "code":"200000", "msg":"Position does not exist" }
|
|
287
|
-
},
|
|
288
|
-
},
|
|
289
|
-
});
|
|
290
|
-
}
|
|
291
|
-
/**
|
|
292
|
-
* @method
|
|
293
|
-
* @name poloniexfutures#fetchMarkets
|
|
294
|
-
* @description retrieves data on all markets for poloniexfutures
|
|
295
|
-
* @see https://api-docs.poloniex.com/futures/api/symbol
|
|
296
|
-
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
297
|
-
* @returns {object[]} an array of objects representing market data
|
|
298
|
-
*/
|
|
299
|
-
async fetchMarkets(params = {}) {
|
|
300
|
-
const response = await this.publicGetContractsActive(params);
|
|
301
|
-
//
|
|
302
|
-
// {
|
|
303
|
-
// "code": "200000",
|
|
304
|
-
// "data": [
|
|
305
|
-
// {
|
|
306
|
-
// "symbol": "APTUSDTPERP",
|
|
307
|
-
// "takerFixFee": "0E-10",
|
|
308
|
-
// "nextFundingRateTime": "20145603",
|
|
309
|
-
// "makerFixFee": "0E-10",
|
|
310
|
-
// "type": "FFWCSX",
|
|
311
|
-
// "predictedFundingFeeRate": "0.000000",
|
|
312
|
-
// "turnoverOf24h": "386037.46704292",
|
|
313
|
-
// "initialMargin": "0.05",
|
|
314
|
-
// "isDeleverage": true,
|
|
315
|
-
// "createdAt": "1666681959000",
|
|
316
|
-
// "fundingBaseSymbol": ".APTINT8H",
|
|
317
|
-
// "lowPriceOf24h": "4.34499979019165",
|
|
318
|
-
// "lastTradePrice": "4.4090000000",
|
|
319
|
-
// "indexPriceTickSize": "0.001",
|
|
320
|
-
// "fairMethod": "FundingRate",
|
|
321
|
-
// "takerFeeRate": "0.00040",
|
|
322
|
-
// "order": "102",
|
|
323
|
-
// "updatedAt": "1671076377000",
|
|
324
|
-
// "displaySettleCurrency": "USDT",
|
|
325
|
-
// "indexPrice": "4.418",
|
|
326
|
-
// "multiplier": "1.0",
|
|
327
|
-
// "maxLeverage": "20",
|
|
328
|
-
// "fundingQuoteSymbol": ".USDTINT8H",
|
|
329
|
-
// "quoteCurrency": "USDT",
|
|
330
|
-
// "maxOrderQty": "1000000",
|
|
331
|
-
// "maxPrice": "1000000.0000000000",
|
|
332
|
-
// "maintainMargin": "0.025",
|
|
333
|
-
// "status": "Open",
|
|
334
|
-
// "displayNameMap": [Object],
|
|
335
|
-
// "openInterest": "2367",
|
|
336
|
-
// "highPriceOf24h": "4.763999938964844",
|
|
337
|
-
// "fundingFeeRate": "0.000000",
|
|
338
|
-
// "volumeOf24h": "83540.00000000",
|
|
339
|
-
// "riskStep": "500000",
|
|
340
|
-
// "isQuanto": true,
|
|
341
|
-
// "maxRiskLimit": "20000",
|
|
342
|
-
// "rootSymbol": "USDT",
|
|
343
|
-
// "baseCurrency": "APT",
|
|
344
|
-
// "firstOpenDate": "1666701000000",
|
|
345
|
-
// "tickSize": "0.001",
|
|
346
|
-
// "markMethod": "FairPrice",
|
|
347
|
-
// "indexSymbol": ".PAPTUSDT",
|
|
348
|
-
// "markPrice": "4.418",
|
|
349
|
-
// "minRiskLimit": "1000000",
|
|
350
|
-
// "settlementFixFee": "0E-10",
|
|
351
|
-
// "settlementSymbol": '',
|
|
352
|
-
// "priceChgPctOf24h": "-0.0704",
|
|
353
|
-
// "fundingRateSymbol": ".APTUSDTPERPFPI8H",
|
|
354
|
-
// "makerFeeRate": "0.00010",
|
|
355
|
-
// "isInverse": false,
|
|
356
|
-
// "lotSize": "1",
|
|
357
|
-
// "settleCurrency": "USDT",
|
|
358
|
-
// "settlementFeeRate": "0.0"
|
|
359
|
-
// },
|
|
360
|
-
// ]
|
|
361
|
-
// }
|
|
362
|
-
//
|
|
363
|
-
const data = this.safeValue(response, 'data', []);
|
|
364
|
-
return this.parseMarkets(data);
|
|
365
|
-
}
|
|
366
|
-
parseMarket(market) {
|
|
367
|
-
const id = this.safeString(market, 'symbol');
|
|
368
|
-
const baseId = this.safeString(market, 'baseCurrency');
|
|
369
|
-
const quoteId = this.safeString(market, 'quoteCurrency');
|
|
370
|
-
const settleId = this.safeString(market, 'rootSymbol');
|
|
371
|
-
const base = this.safeCurrencyCode(baseId);
|
|
372
|
-
const quote = this.safeCurrencyCode(quoteId);
|
|
373
|
-
const settle = this.safeCurrencyCode(settleId);
|
|
374
|
-
const symbol = base + '/' + quote + ':' + settle;
|
|
375
|
-
const inverse = this.safeValue(market, 'isInverse');
|
|
376
|
-
const status = this.safeString(market, 'status');
|
|
377
|
-
const multiplier = this.safeString(market, 'multiplier');
|
|
378
|
-
const tickSize = this.safeNumber(market, 'indexPriceTickSize');
|
|
379
|
-
const lotSize = this.safeNumber(market, 'lotSize');
|
|
380
|
-
const limitAmountMax = this.safeNumber(market, 'maxOrderQty');
|
|
381
|
-
const limitPriceMax = this.safeNumber(market, 'maxPrice');
|
|
382
|
-
return {
|
|
383
|
-
'id': id,
|
|
384
|
-
'symbol': symbol,
|
|
385
|
-
'base': base,
|
|
386
|
-
'quote': quote,
|
|
387
|
-
'settle': settle,
|
|
388
|
-
'baseId': baseId,
|
|
389
|
-
'quoteId': quoteId,
|
|
390
|
-
'settleId': settleId,
|
|
391
|
-
'type': 'swap',
|
|
392
|
-
'spot': false,
|
|
393
|
-
'margin': false,
|
|
394
|
-
'swap': true,
|
|
395
|
-
'future': false,
|
|
396
|
-
'option': false,
|
|
397
|
-
'active': (status === 'Open'),
|
|
398
|
-
'contract': true,
|
|
399
|
-
'linear': !inverse,
|
|
400
|
-
'inverse': inverse,
|
|
401
|
-
'taker': this.safeNumber(market, 'takerFeeRate'),
|
|
402
|
-
'maker': this.safeNumber(market, 'makerFeeRate'),
|
|
403
|
-
'contractSize': this.parseNumber(Precise.stringAbs(multiplier)),
|
|
404
|
-
'expiry': undefined,
|
|
405
|
-
'expiryDatetime': undefined,
|
|
406
|
-
'strike': undefined,
|
|
407
|
-
'optionType': undefined,
|
|
408
|
-
'precision': {
|
|
409
|
-
'amount': lotSize,
|
|
410
|
-
'price': tickSize,
|
|
411
|
-
},
|
|
412
|
-
'limits': {
|
|
413
|
-
'leverage': {
|
|
414
|
-
'min': this.parseNumber('1'),
|
|
415
|
-
'max': this.safeNumber(market, 'maxLeverage'),
|
|
416
|
-
},
|
|
417
|
-
'amount': {
|
|
418
|
-
'min': lotSize,
|
|
419
|
-
'max': limitAmountMax,
|
|
420
|
-
},
|
|
421
|
-
'price': {
|
|
422
|
-
'min': tickSize,
|
|
423
|
-
'max': limitPriceMax,
|
|
424
|
-
},
|
|
425
|
-
'cost': {
|
|
426
|
-
'min': undefined,
|
|
427
|
-
'max': undefined,
|
|
428
|
-
},
|
|
429
|
-
},
|
|
430
|
-
'created': this.safeInteger(market, 'firstOpenDate'),
|
|
431
|
-
'info': market,
|
|
432
|
-
};
|
|
433
|
-
}
|
|
434
|
-
parseTicker(ticker, market = undefined) {
|
|
435
|
-
//
|
|
436
|
-
// {
|
|
437
|
-
// "symbol": "BTCUSDTPERP", // Market of the symbol
|
|
438
|
-
// "sequence": 45, // Sequence number which is used to judge the continuity of the pushed messages
|
|
439
|
-
// "side": "sell", // Transaction side of the last traded taker order
|
|
440
|
-
// "price": 3600.00, // Filled price
|
|
441
|
-
// "size": 16, // Filled quantity
|
|
442
|
-
// "tradeId": "5c9dcf4170744d6f5a3d32fb", // Order ID
|
|
443
|
-
// "bestBidSize": 795, // Best bid size
|
|
444
|
-
// "bestBidPrice": 3200.00, // Best bid
|
|
445
|
-
// "bestAskPrice": 3600.00, // Best ask size
|
|
446
|
-
// "bestAskSize": 284, // Best ask
|
|
447
|
-
// "ts": 1553846081210004941 // Filled time - nanosecond
|
|
448
|
-
// }
|
|
449
|
-
//
|
|
450
|
-
// {
|
|
451
|
-
// "volume": 30449670, //24h Volume
|
|
452
|
-
// "turnover": 845169919063, //24h Turnover
|
|
453
|
-
// "lastPrice": 3551, //Last price
|
|
454
|
-
// "priceChgPct": 0.0043, //24h Change
|
|
455
|
-
// "ts": 1547697294838004923 //Snapshot time (nanosecond)
|
|
456
|
-
// }
|
|
457
|
-
//
|
|
458
|
-
const marketId = this.safeString(ticker, 'symbol');
|
|
459
|
-
const symbol = this.safeSymbol(marketId, market);
|
|
460
|
-
const timestampString = this.safeString(ticker, 'ts');
|
|
461
|
-
let multiplier = undefined;
|
|
462
|
-
if (timestampString.length === 16) {
|
|
463
|
-
// 16 digits: https://app.travis-ci.com/github/ccxt/ccxt/builds/270587157#L5454
|
|
464
|
-
multiplier = 0.001;
|
|
465
|
-
}
|
|
466
|
-
else if (timestampString.length === 17) {
|
|
467
|
-
// 17 digits: https://app.travis-ci.com/github/ccxt/ccxt/builds/269959181#L4011
|
|
468
|
-
multiplier = 0.0001;
|
|
469
|
-
}
|
|
470
|
-
else if (timestampString.length === 18) {
|
|
471
|
-
multiplier = 0.00001;
|
|
472
|
-
}
|
|
473
|
-
else {
|
|
474
|
-
// 19 length default
|
|
475
|
-
multiplier = 0.000001;
|
|
476
|
-
}
|
|
477
|
-
const timestamp = this.safeIntegerProduct(ticker, 'ts', multiplier);
|
|
478
|
-
const last = this.safeString2(ticker, 'price', 'lastPrice');
|
|
479
|
-
const percentage = Precise.stringMul(this.safeString(ticker, 'priceChgPct'), '100');
|
|
480
|
-
return this.safeTicker({
|
|
481
|
-
'symbol': symbol,
|
|
482
|
-
'timestamp': timestamp,
|
|
483
|
-
'datetime': this.iso8601(timestamp),
|
|
484
|
-
'high': undefined,
|
|
485
|
-
'low': undefined,
|
|
486
|
-
'bid': this.safeString(ticker, 'bestBidPrice'),
|
|
487
|
-
'bidVolume': this.safeString(ticker, 'bestBidSize'),
|
|
488
|
-
'ask': this.safeString(ticker, 'bestAskPrice'),
|
|
489
|
-
'askVolume': this.safeString(ticker, 'bestAskSize'),
|
|
490
|
-
'vwap': undefined,
|
|
491
|
-
'open': undefined,
|
|
492
|
-
'close': last,
|
|
493
|
-
'last': last,
|
|
494
|
-
'previousClose': undefined,
|
|
495
|
-
'change': undefined,
|
|
496
|
-
'percentage': percentage,
|
|
497
|
-
'average': undefined,
|
|
498
|
-
'baseVolume': this.safeString2(ticker, 'size', 'volume'),
|
|
499
|
-
'quoteVolume': this.safeString(ticker, 'turnover'),
|
|
500
|
-
'info': ticker,
|
|
501
|
-
}, market);
|
|
502
|
-
}
|
|
503
|
-
/**
|
|
504
|
-
* @method
|
|
505
|
-
* @name poloniexfutures#fetchTicker
|
|
506
|
-
* @description fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
|
|
507
|
-
* @see https://api-docs.poloniex.com/futures/api/ticker#get-real-time-ticker-20
|
|
508
|
-
* @param {string} symbol unified symbol of the market to fetch the ticker for
|
|
509
|
-
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
510
|
-
* @returns {object} a [ticker structure]{@link https://docs.ccxt.com/#/?id=ticker-structure}
|
|
511
|
-
*/
|
|
512
|
-
async fetchTicker(symbol, params = {}) {
|
|
513
|
-
await this.loadMarkets();
|
|
514
|
-
const market = this.market(symbol);
|
|
515
|
-
const request = {
|
|
516
|
-
'symbol': market['id'],
|
|
517
|
-
};
|
|
518
|
-
const response = await this.publicGetTicker(this.extend(request, params));
|
|
519
|
-
//
|
|
520
|
-
// {
|
|
521
|
-
// "code": "200000",
|
|
522
|
-
// "data": {
|
|
523
|
-
// "sequence": "11574719",
|
|
524
|
-
// "symbol": "BTCUSDTPERP",
|
|
525
|
-
// "side": "sell",
|
|
526
|
-
// "size": "1",
|
|
527
|
-
// "price": "16990.1",
|
|
528
|
-
// "bestBidSize": "3",
|
|
529
|
-
// "bestBidPrice": "16990.1",
|
|
530
|
-
// "bestAskPrice": "16991.0",
|
|
531
|
-
// "tradeId": "639c8a529fd7cf0001af4157",
|
|
532
|
-
// "bestAskSize": "505",
|
|
533
|
-
// "ts": "1671203410721232337"
|
|
534
|
-
// }
|
|
535
|
-
// }
|
|
536
|
-
//
|
|
537
|
-
return this.parseTicker(this.safeValue(response, 'data', {}), market);
|
|
538
|
-
}
|
|
539
|
-
/**
|
|
540
|
-
* @method
|
|
541
|
-
* @name poloniexfutures#fetchTickers
|
|
542
|
-
* @description fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market
|
|
543
|
-
* @see https://api-docs.poloniex.com/futures/api/ticker#get-real-time-ticker-of-all-symbols
|
|
544
|
-
* @param {string[]|undefined} symbols unified symbols of the markets to fetch the ticker for, all market tickers are returned if not assigned
|
|
545
|
-
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
546
|
-
* @returns {object} a dictionary of [ticker structures]{@link https://docs.ccxt.com/#/?id=ticker-structure}
|
|
547
|
-
*/
|
|
548
|
-
async fetchTickers(symbols = undefined, params = {}) {
|
|
549
|
-
await this.loadMarkets();
|
|
550
|
-
const response = await this.publicGetTickers(params);
|
|
551
|
-
const data = this.safeList(response, 'data', []);
|
|
552
|
-
return this.parseTickers(data, symbols);
|
|
553
|
-
}
|
|
554
|
-
/**
|
|
555
|
-
* @method
|
|
556
|
-
* @name poloniexfuturesfutures#fetchOrderBook
|
|
557
|
-
* @description fetches information on open orders with bid (buy) and ask (sell) prices, volumes and other data
|
|
558
|
-
* @see https://api-docs.poloniex.com/futures/api/orderbook#get-full-order-book---level-2
|
|
559
|
-
* @see https://api-docs.poloniex.com/futures/api/orderbook#get-full-order-book--level-3
|
|
560
|
-
* @param {string} symbol unified symbol of the market to fetch the order book for
|
|
561
|
-
* @param {int} [limit] the maximum amount of order book entries to return
|
|
562
|
-
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
563
|
-
* @returns {object} A dictionary of [order book structures]{@link https://docs.ccxt.com/#/?id=order-book-structure} indexed by market symbols
|
|
564
|
-
*/
|
|
565
|
-
async fetchOrderBook(symbol, limit = undefined, params = {}) {
|
|
566
|
-
await this.loadMarkets();
|
|
567
|
-
const level = this.safeNumber(params, 'level');
|
|
568
|
-
params = this.omit(params, 'level');
|
|
569
|
-
if (level !== undefined && level !== 2 && level !== 3) {
|
|
570
|
-
throw new BadRequest(this.id + ' fetchOrderBook() can only return level 2 & 3');
|
|
571
|
-
}
|
|
572
|
-
const market = this.market(symbol);
|
|
573
|
-
const request = {
|
|
574
|
-
'symbol': market['id'],
|
|
575
|
-
};
|
|
576
|
-
let response = undefined;
|
|
577
|
-
if (level === 3) {
|
|
578
|
-
response = await this.publicGetLevel3Snapshot(this.extend(request, params));
|
|
579
|
-
}
|
|
580
|
-
else {
|
|
581
|
-
response = await this.publicGetLevel2Snapshot(this.extend(request, params));
|
|
582
|
-
}
|
|
583
|
-
// L2
|
|
584
|
-
//
|
|
585
|
-
// {
|
|
586
|
-
// "code": "200000",
|
|
587
|
-
// "data": {
|
|
588
|
-
// "symbol": "BTCUSDTPERP",
|
|
589
|
-
// "sequence": 1669149851334,
|
|
590
|
-
// "asks": [
|
|
591
|
-
// [
|
|
592
|
-
// 16952,
|
|
593
|
-
// 12
|
|
594
|
-
// ],
|
|
595
|
-
// ],
|
|
596
|
-
// "bids": [
|
|
597
|
-
// [
|
|
598
|
-
// 16951.9,
|
|
599
|
-
// 13
|
|
600
|
-
// ],
|
|
601
|
-
// ],
|
|
602
|
-
// }
|
|
603
|
-
//
|
|
604
|
-
// L3
|
|
605
|
-
//
|
|
606
|
-
// {
|
|
607
|
-
// "code": "200000",
|
|
608
|
-
// "data": {
|
|
609
|
-
// "symbol": "BTCUSDTPERP",
|
|
610
|
-
// "sequence": 1669149851334,
|
|
611
|
-
// "asks": [
|
|
612
|
-
// [
|
|
613
|
-
// "639c95388cba5100084eabce",
|
|
614
|
-
// "16952.0",
|
|
615
|
-
// "1",
|
|
616
|
-
// 1671206200542484700
|
|
617
|
-
// ],
|
|
618
|
-
// ],
|
|
619
|
-
// "bids": [
|
|
620
|
-
// [
|
|
621
|
-
// "626659d83385c200072e690b",
|
|
622
|
-
// "17.0",
|
|
623
|
-
// "1000",
|
|
624
|
-
// 1650874840161291000
|
|
625
|
-
// ],
|
|
626
|
-
// ],
|
|
627
|
-
// }
|
|
628
|
-
//
|
|
629
|
-
const data = this.safeValue(response, 'data', {});
|
|
630
|
-
const timestamp = this.safeIntegerProduct(data, 'ts', 0.000001);
|
|
631
|
-
let orderbook = undefined;
|
|
632
|
-
if (level === 3) {
|
|
633
|
-
orderbook = this.parseOrderBook(data, market['symbol'], timestamp, 'bids', 'asks', 1, 2);
|
|
634
|
-
}
|
|
635
|
-
else {
|
|
636
|
-
orderbook = this.parseOrderBook(data, market['symbol'], timestamp, 'bids', 'asks', 0, 1);
|
|
637
|
-
}
|
|
638
|
-
orderbook['nonce'] = this.safeInteger(data, 'sequence');
|
|
639
|
-
return orderbook;
|
|
640
|
-
}
|
|
641
|
-
/**
|
|
642
|
-
* @method
|
|
643
|
-
* @name poloniexfutures#fetchL3OrderBook
|
|
644
|
-
* @description fetches level 3 information on open orders with bid (buy) and ask (sell) prices, volumes and other data
|
|
645
|
-
* @see https://api-docs.poloniex.com/futures/api/orderbook#get-full-order-book--level-3
|
|
646
|
-
* @param {string} symbol unified market symbol
|
|
647
|
-
* @param {int} [limit] max number of orders to return, default is undefined
|
|
648
|
-
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
649
|
-
* @returns {object} an [order book structure]{@link https://docs.ccxt.com/#/?id=order-book-structure}
|
|
650
|
-
*/
|
|
651
|
-
async fetchL3OrderBook(symbol, limit = undefined, params = {}) {
|
|
652
|
-
await this.loadMarkets();
|
|
653
|
-
const market = this.market(symbol);
|
|
654
|
-
return this.fetchOrderBook(market['id'], undefined, { 'level': 3 });
|
|
655
|
-
}
|
|
656
|
-
parseTrade(trade, market = undefined) {
|
|
657
|
-
//
|
|
658
|
-
// fetchTrades (public)
|
|
659
|
-
//
|
|
660
|
-
// {
|
|
661
|
-
// "sequence": 11827985,
|
|
662
|
-
// "side": "buy",
|
|
663
|
-
// "size": 101,
|
|
664
|
-
// "price": "16864.0000000000",
|
|
665
|
-
// "takerOrderId": "639c986f0ac2470007be75ee",
|
|
666
|
-
// "makerOrderId": "639c986fa69d280007b76111",
|
|
667
|
-
// "tradeId": "639c986f9fd7cf0001afd7ee",
|
|
668
|
-
// "ts": 1671207023485924400
|
|
669
|
-
// }
|
|
670
|
-
//
|
|
671
|
-
// fetchMyTrades
|
|
672
|
-
//
|
|
673
|
-
// {
|
|
674
|
-
// "symbol": "BTCUSDTPERP", //Ticker symbol of the contract
|
|
675
|
-
// "tradeId": "5ce24c1f0c19fc3c58edc47c", //Trade ID
|
|
676
|
-
// "orderId": "5ce24c16b210233c36ee321d", // Order ID
|
|
677
|
-
// "side": "sell", //Transaction side
|
|
678
|
-
// "liquidity": "taker", //Liquidity- taker or maker
|
|
679
|
-
// "price": "8302", //Filled price
|
|
680
|
-
// "size": 10, //Filled amount
|
|
681
|
-
// "value": "0.001204529", //Order value
|
|
682
|
-
// "feeRate": "0.0005", //Floating fees
|
|
683
|
-
// "fixFee": "0.00000006", //Fixed fees
|
|
684
|
-
// "feeCurrency": "XBT", //Charging currency
|
|
685
|
-
// "stop": "", //A mark to the stop order type
|
|
686
|
-
// "fee": "0.0000012022", //Transaction fee
|
|
687
|
-
// "orderType": "limit", //Order type
|
|
688
|
-
// "tradeType": "trade", //Trade type (trade, liquidation, ADL or settlement)
|
|
689
|
-
// "createdAt": 1558334496000, //Time the order created
|
|
690
|
-
// "settleCurrency": "XBT", //settlement currency
|
|
691
|
-
// "tradeTime": 1558334496000000000 //trade time in nanosecond
|
|
692
|
-
// }
|
|
693
|
-
//
|
|
694
|
-
const marketId = this.safeString(trade, 'symbol');
|
|
695
|
-
market = this.safeMarket(marketId, market, '-');
|
|
696
|
-
const id = this.safeString(trade, 'tradeId');
|
|
697
|
-
const orderId = this.safeString(trade, 'orderId');
|
|
698
|
-
const takerOrMaker = this.safeString(trade, 'liquidity');
|
|
699
|
-
let timestamp = this.safeInteger(trade, 'ts');
|
|
700
|
-
if (timestamp !== undefined) {
|
|
701
|
-
timestamp = this.parseToInt(timestamp / 1000000);
|
|
702
|
-
}
|
|
703
|
-
else {
|
|
704
|
-
timestamp = this.safeInteger(trade, 'createdAt');
|
|
705
|
-
// if it's a historical v1 trade, the exchange returns timestamp in seconds
|
|
706
|
-
if (('dealValue' in trade) && (timestamp !== undefined)) {
|
|
707
|
-
timestamp = timestamp * 1000;
|
|
708
|
-
}
|
|
709
|
-
}
|
|
710
|
-
const priceString = this.safeString(trade, 'price');
|
|
711
|
-
const amountString = this.safeString(trade, 'size');
|
|
712
|
-
const side = this.safeString(trade, 'side');
|
|
713
|
-
let fee = undefined;
|
|
714
|
-
const feeCostString = this.safeString(trade, 'fee');
|
|
715
|
-
if (feeCostString !== undefined) {
|
|
716
|
-
const feeCurrencyId = this.safeString(trade, 'feeCurrency');
|
|
717
|
-
let feeCurrency = this.safeCurrencyCode(feeCurrencyId);
|
|
718
|
-
if (feeCurrency === undefined) {
|
|
719
|
-
feeCurrency = (side === 'sell') ? market['quote'] : market['base'];
|
|
720
|
-
}
|
|
721
|
-
fee = {
|
|
722
|
-
'cost': feeCostString,
|
|
723
|
-
'currency': feeCurrency,
|
|
724
|
-
'rate': this.safeString(trade, 'feeRate'),
|
|
725
|
-
};
|
|
726
|
-
}
|
|
727
|
-
let type = this.safeString(trade, 'orderType');
|
|
728
|
-
if (type === 'match') {
|
|
729
|
-
type = undefined;
|
|
730
|
-
}
|
|
731
|
-
const costString = this.safeString(trade, 'value');
|
|
732
|
-
return this.safeTrade({
|
|
733
|
-
'info': trade,
|
|
734
|
-
'id': id,
|
|
735
|
-
'order': orderId,
|
|
736
|
-
'timestamp': timestamp,
|
|
737
|
-
'datetime': this.iso8601(timestamp),
|
|
738
|
-
'symbol': market['symbol'],
|
|
739
|
-
'type': type,
|
|
740
|
-
'takerOrMaker': takerOrMaker,
|
|
741
|
-
'side': side,
|
|
742
|
-
'price': priceString,
|
|
743
|
-
'amount': amountString,
|
|
744
|
-
'cost': costString,
|
|
745
|
-
'fee': fee,
|
|
746
|
-
}, market);
|
|
747
|
-
}
|
|
748
|
-
/**
|
|
749
|
-
* @method
|
|
750
|
-
* @name poloniexfutures#fetchTrades
|
|
751
|
-
* @description get the list of most recent trades for a particular symbol
|
|
752
|
-
* @see https://api-docs.poloniex.com/futures/api/historical#transaction-history
|
|
753
|
-
* @param {string} symbol unified symbol of the market to fetch trades for
|
|
754
|
-
* @param {int} [since] timestamp in ms of the earliest trade to fetch
|
|
755
|
-
* @param {int} [limit] the maximum amount of trades to fetch
|
|
756
|
-
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
757
|
-
* @returns {Trade[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=public-trades}
|
|
758
|
-
*/
|
|
759
|
-
async fetchTrades(symbol, since = undefined, limit = undefined, params = {}) {
|
|
760
|
-
await this.loadMarkets();
|
|
761
|
-
const market = this.market(symbol);
|
|
762
|
-
const request = {
|
|
763
|
-
'symbol': market['id'],
|
|
764
|
-
};
|
|
765
|
-
const response = await this.publicGetTradeHistory(this.extend(request, params));
|
|
766
|
-
//
|
|
767
|
-
// {
|
|
768
|
-
// "code": "200000",
|
|
769
|
-
// "data": [
|
|
770
|
-
// {
|
|
771
|
-
// "sequence": 11827985,
|
|
772
|
-
// "side": "buy",
|
|
773
|
-
// "size": 101,
|
|
774
|
-
// "price": "16864.0000000000",
|
|
775
|
-
// "takerOrderId": "639c986f0ac2470007be75ee",
|
|
776
|
-
// "makerOrderId": "639c986fa69d280007b76111",
|
|
777
|
-
// "tradeId": "639c986f9fd7cf0001afd7ee",
|
|
778
|
-
// "ts": 1671207023485924400
|
|
779
|
-
// },
|
|
780
|
-
// }
|
|
781
|
-
//
|
|
782
|
-
const trades = this.safeList(response, 'data', []);
|
|
783
|
-
return this.parseTrades(trades, market, since, limit);
|
|
784
|
-
}
|
|
785
|
-
/**
|
|
786
|
-
* @method
|
|
787
|
-
* @name poloniexfutures#fetchTime
|
|
788
|
-
* @description fetches the current integer timestamp in milliseconds from the poloniexfutures server
|
|
789
|
-
* @see https://api-docs.poloniex.com/futures/api/time#server-time
|
|
790
|
-
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
791
|
-
* @returns {int} the current integer timestamp in milliseconds from the poloniexfutures server
|
|
792
|
-
*/
|
|
793
|
-
async fetchTime(params = {}) {
|
|
794
|
-
const response = await this.publicGetTimestamp(params);
|
|
795
|
-
//
|
|
796
|
-
// {
|
|
797
|
-
// "code":"200000",
|
|
798
|
-
// "msg":"success",
|
|
799
|
-
// "data":1546837113087
|
|
800
|
-
// }
|
|
801
|
-
//
|
|
802
|
-
return this.safeInteger(response, 'data');
|
|
803
|
-
}
|
|
804
|
-
/**
|
|
805
|
-
* @method
|
|
806
|
-
* @name poloniexfutures#fetchOHLCV
|
|
807
|
-
* @description fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market
|
|
808
|
-
* @see https://api-docs.poloniex.com/futures/api/kline#get-k-line-data-of-contract
|
|
809
|
-
* @param {string} symbol unified symbol of the market to fetch OHLCV data for
|
|
810
|
-
* @param {string} timeframe the length of time each candle represents
|
|
811
|
-
* @param {int} [since] timestamp in ms of the earliest candle to fetch
|
|
812
|
-
* @param {int} [limit] the maximum amount of candles to fetch
|
|
813
|
-
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
814
|
-
* @returns {int[][]} A list of candles ordered as timestamp, open, high, low, close, volume
|
|
815
|
-
*/
|
|
816
|
-
async fetchOHLCV(symbol, timeframe = '1m', since = undefined, limit = undefined, params = {}) {
|
|
817
|
-
await this.loadMarkets();
|
|
818
|
-
const market = this.market(symbol);
|
|
819
|
-
const marketId = market['id'];
|
|
820
|
-
const parsedTimeframe = this.safeInteger(this.timeframes, timeframe);
|
|
821
|
-
const request = {
|
|
822
|
-
'symbol': marketId,
|
|
823
|
-
};
|
|
824
|
-
if (parsedTimeframe !== undefined) {
|
|
825
|
-
request['granularity'] = parsedTimeframe;
|
|
826
|
-
}
|
|
827
|
-
else {
|
|
828
|
-
request['granularity'] = timeframe;
|
|
829
|
-
}
|
|
830
|
-
const duration = this.parseTimeframe(timeframe) * 1000;
|
|
831
|
-
let endAt = this.milliseconds();
|
|
832
|
-
if (since !== undefined) {
|
|
833
|
-
request['from'] = since;
|
|
834
|
-
if (limit === undefined) {
|
|
835
|
-
limit = this.safeInteger(this.options, 'fetchOHLCVLimit', 200);
|
|
836
|
-
}
|
|
837
|
-
endAt = this.sum(since, limit * duration);
|
|
838
|
-
request['to'] = endAt;
|
|
839
|
-
}
|
|
840
|
-
else if (limit !== undefined) {
|
|
841
|
-
since = endAt - limit * duration;
|
|
842
|
-
request['from'] = since;
|
|
843
|
-
}
|
|
844
|
-
const response = await this.publicGetKlineQuery(this.extend(request, params));
|
|
845
|
-
//
|
|
846
|
-
// {
|
|
847
|
-
// "code": "200000",
|
|
848
|
-
// "data": [
|
|
849
|
-
// [1636459200000, 4779.3, 4792.1, 4768.7, 4770.3, 78051],
|
|
850
|
-
// [1636460100000, 4770.25, 4778.55, 4757.55, 4777.25, 80164],
|
|
851
|
-
// [1636461000000, 4777.25, 4791.45, 4774.5, 4791.3, 51555]
|
|
852
|
-
// ]
|
|
853
|
-
// }
|
|
854
|
-
//
|
|
855
|
-
const data = this.safeList(response, 'data', []);
|
|
856
|
-
return this.parseOHLCVs(data, market, timeframe, since, limit);
|
|
857
|
-
}
|
|
858
|
-
parseBalance(response) {
|
|
859
|
-
const result = {
|
|
860
|
-
'info': response,
|
|
861
|
-
'timestamp': undefined,
|
|
862
|
-
'datetime': undefined,
|
|
863
|
-
};
|
|
864
|
-
const data = this.safeValue(response, 'data');
|
|
865
|
-
const currencyId = this.safeString(data, 'currency');
|
|
866
|
-
const code = this.safeCurrencyCode(currencyId);
|
|
867
|
-
const account = this.account();
|
|
868
|
-
account['free'] = this.safeString(data, 'availableBalance');
|
|
869
|
-
account['total'] = this.safeString(data, 'accountEquity');
|
|
870
|
-
result[code] = account;
|
|
871
|
-
return this.safeBalance(result);
|
|
872
|
-
}
|
|
873
|
-
/**
|
|
874
|
-
* @method
|
|
875
|
-
* @name poloniexfutures#fetchBalance
|
|
876
|
-
* @description query for balance and get the amount of funds available for trading or funds locked in orders
|
|
877
|
-
* @see https://api-docs.poloniex.com/futures/api/account#get-account-overview
|
|
878
|
-
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
879
|
-
* @returns {object} a [balance structure]{@link https://docs.ccxt.com/#/?id=balance-structure}
|
|
880
|
-
*/
|
|
881
|
-
async fetchBalance(params = {}) {
|
|
882
|
-
await this.loadMarkets();
|
|
883
|
-
const currencyId = this.safeString(params, 'currency');
|
|
884
|
-
let request = {};
|
|
885
|
-
if (currencyId !== undefined) {
|
|
886
|
-
const currency = this.currency(currencyId);
|
|
887
|
-
request = {
|
|
888
|
-
'currency': currency['id'],
|
|
889
|
-
};
|
|
890
|
-
}
|
|
891
|
-
const response = await this.privateGetAccountOverview(this.extend(request, params));
|
|
892
|
-
//
|
|
893
|
-
// {
|
|
894
|
-
// "code": "200000",
|
|
895
|
-
// "data": {
|
|
896
|
-
// "accountEquity": 0.00005,
|
|
897
|
-
// "unrealisedPNL": 0,
|
|
898
|
-
// "marginBalance": 0.00005,
|
|
899
|
-
// "positionMargin": 0,
|
|
900
|
-
// "orderMargin": 0,
|
|
901
|
-
// "frozenFunds": 0,
|
|
902
|
-
// "availableBalance": 0.00005,
|
|
903
|
-
// "currency": "XBT"
|
|
904
|
-
// }
|
|
905
|
-
// }
|
|
906
|
-
//
|
|
907
|
-
return this.parseBalance(response);
|
|
908
|
-
}
|
|
909
|
-
/**
|
|
910
|
-
* @method
|
|
911
|
-
* @name poloniexfutures#createOrder
|
|
912
|
-
* @description Create an order on the exchange
|
|
913
|
-
* @see https://api-docs.poloniex.com/futures/api/orders#place-an-order
|
|
914
|
-
* @param {string} symbol Unified CCXT market symbol
|
|
915
|
-
* @param {string} type 'limit' or 'market'
|
|
916
|
-
* @param {string} side 'buy' or 'sell'
|
|
917
|
-
* @param {float} amount the amount of currency to trade
|
|
918
|
-
* @param {float} [price] the price at which the order is to be fulfilled, in units of the quote currency, ignored in market orders
|
|
919
|
-
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
920
|
-
* @param {float} [params.leverage] Leverage size of the order
|
|
921
|
-
* @param {float} [params.triggerPrice] The price at which a trigger order is triggered at
|
|
922
|
-
* @param {bool} [params.reduceOnly] A mark to reduce the position size only. Set to false by default. Need to set the position size when reduceOnly is true.
|
|
923
|
-
* @param {string} [params.timeInForce] GTC, GTT, IOC, or FOK, default is GTC, limit orders only
|
|
924
|
-
* @param {string} [params.postOnly] Post only flag, invalid when timeInForce is IOC or FOK
|
|
925
|
-
* @param {string} [params.clientOid] client order id, defaults to uuid if not passed
|
|
926
|
-
* @param {string} [params.remark] remark for the order, length cannot exceed 100 utf8 characters
|
|
927
|
-
* @param {string} [params.stop] 'up' or 'down', defaults to 'up' if side is sell and 'down' if side is buy, requires stopPrice
|
|
928
|
-
* @param {string} [params.stopPriceType] TP, IP or MP, defaults to TP
|
|
929
|
-
* @param {bool} [params.closeOrder] set to true to close position
|
|
930
|
-
* @param {bool} [params.forceHold] A mark to forcely hold the funds for an order, even though it's an order to reduce the position size. This helps the order stay on the order book and not get canceled when the position size changes. Set to false by default.
|
|
931
|
-
* @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
|
|
932
|
-
*/
|
|
933
|
-
async createOrder(symbol, type, side, amount, price = undefined, params = {}) {
|
|
934
|
-
await this.loadMarkets();
|
|
935
|
-
const market = this.market(symbol);
|
|
936
|
-
// required param, cannot be used twice
|
|
937
|
-
const clientOrderId = this.safeString2(params, 'clientOid', 'clientOrderId', this.uuid());
|
|
938
|
-
params = this.omit(params, ['clientOid', 'clientOrderId']);
|
|
939
|
-
if (amount < 1) {
|
|
940
|
-
throw new InvalidOrder(this.id + ' createOrder() minimum contract order amount is 1');
|
|
941
|
-
}
|
|
942
|
-
const preciseAmount = parseInt(this.amountToPrecision(symbol, amount));
|
|
943
|
-
const request = {
|
|
944
|
-
'clientOid': clientOrderId,
|
|
945
|
-
'side': side,
|
|
946
|
-
'symbol': market['id'],
|
|
947
|
-
'type': type,
|
|
948
|
-
'size': preciseAmount,
|
|
949
|
-
'leverage': 1,
|
|
950
|
-
};
|
|
951
|
-
const triggerPrice = this.safeValue2(params, 'triggerPrice', 'stopPrice');
|
|
952
|
-
if (triggerPrice) {
|
|
953
|
-
request['stop'] = (side === 'buy') ? 'up' : 'down';
|
|
954
|
-
const stopPriceType = this.safeString(params, 'stopPriceType', 'TP');
|
|
955
|
-
request['stopPriceType'] = stopPriceType;
|
|
956
|
-
request['stopPrice'] = this.priceToPrecision(symbol, triggerPrice);
|
|
957
|
-
}
|
|
958
|
-
const timeInForce = this.safeStringUpper(params, 'timeInForce');
|
|
959
|
-
if (type === 'limit') {
|
|
960
|
-
if (price === undefined) {
|
|
961
|
-
throw new ArgumentsRequired(this.id + ' createOrder() requires a price argument for limit orders');
|
|
962
|
-
}
|
|
963
|
-
else {
|
|
964
|
-
request['price'] = this.priceToPrecision(symbol, price);
|
|
965
|
-
}
|
|
966
|
-
if (timeInForce !== undefined) {
|
|
967
|
-
request['timeInForce'] = timeInForce;
|
|
968
|
-
}
|
|
969
|
-
}
|
|
970
|
-
const postOnly = this.safeBool(params, 'postOnly', false);
|
|
971
|
-
const hidden = this.safeValue(params, 'hidden');
|
|
972
|
-
if (postOnly && (hidden !== undefined)) {
|
|
973
|
-
throw new BadRequest(this.id + ' createOrder() does not support the postOnly parameter together with a hidden parameter');
|
|
974
|
-
}
|
|
975
|
-
const iceberg = this.safeValue(params, 'iceberg');
|
|
976
|
-
if (iceberg) {
|
|
977
|
-
const visibleSize = this.safeValue(params, 'visibleSize');
|
|
978
|
-
if (visibleSize === undefined) {
|
|
979
|
-
throw new ArgumentsRequired(this.id + ' createOrder() requires a visibleSize parameter for iceberg orders');
|
|
980
|
-
}
|
|
981
|
-
}
|
|
982
|
-
params = this.omit(params, ['timeInForce', 'stopPrice', 'triggerPrice']); // Time in force only valid for limit orders, exchange error when gtc for market orders
|
|
983
|
-
const response = await this.privatePostOrders(this.extend(request, params));
|
|
984
|
-
//
|
|
985
|
-
// {
|
|
986
|
-
// "code": "200000",
|
|
987
|
-
// "data": {
|
|
988
|
-
// "orderId": "619717484f1d010001510cde",
|
|
989
|
-
// },
|
|
990
|
-
// }
|
|
991
|
-
//
|
|
992
|
-
const data = this.safeValue(response, 'data', {});
|
|
993
|
-
return this.safeOrder({
|
|
994
|
-
'id': this.safeString(data, 'orderId'),
|
|
995
|
-
'clientOrderId': undefined,
|
|
996
|
-
'timestamp': undefined,
|
|
997
|
-
'datetime': undefined,
|
|
998
|
-
'lastTradeTimestamp': undefined,
|
|
999
|
-
'symbol': undefined,
|
|
1000
|
-
'type': undefined,
|
|
1001
|
-
'side': undefined,
|
|
1002
|
-
'price': undefined,
|
|
1003
|
-
'amount': undefined,
|
|
1004
|
-
'cost': undefined,
|
|
1005
|
-
'average': undefined,
|
|
1006
|
-
'filled': undefined,
|
|
1007
|
-
'remaining': undefined,
|
|
1008
|
-
'status': undefined,
|
|
1009
|
-
'fee': undefined,
|
|
1010
|
-
'trades': undefined,
|
|
1011
|
-
'timeInForce': undefined,
|
|
1012
|
-
'postOnly': undefined,
|
|
1013
|
-
'triggerPrice': undefined,
|
|
1014
|
-
'info': response,
|
|
1015
|
-
}, market);
|
|
1016
|
-
}
|
|
1017
|
-
/**
|
|
1018
|
-
* @method
|
|
1019
|
-
* @name poloniexfutures#cancelOrder
|
|
1020
|
-
* @description cancels an open order
|
|
1021
|
-
* @see https://api-docs.poloniex.com/futures/api/orders#cancel-an-order
|
|
1022
|
-
* @param {string} id order id
|
|
1023
|
-
* @param {string} symbol unified symbol of the market the order was made in
|
|
1024
|
-
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
1025
|
-
* @returns {object} An [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
|
|
1026
|
-
*/
|
|
1027
|
-
async cancelOrder(id, symbol = undefined, params = {}) {
|
|
1028
|
-
await this.loadMarkets();
|
|
1029
|
-
const request = {
|
|
1030
|
-
'order-id': id,
|
|
1031
|
-
};
|
|
1032
|
-
const response = await this.privateDeleteOrdersOrderId(this.extend(request, params));
|
|
1033
|
-
//
|
|
1034
|
-
// {
|
|
1035
|
-
// "code": "200000",
|
|
1036
|
-
// "data": {
|
|
1037
|
-
// "cancelledOrderIds": [
|
|
1038
|
-
// "619714b8b6353000014c505a",
|
|
1039
|
-
// ],
|
|
1040
|
-
// "cancelFailedOrders": [
|
|
1041
|
-
// {
|
|
1042
|
-
// "orderId": "63a9c5c2b9e7d70007eb0cd5",
|
|
1043
|
-
// "orderState": "2"
|
|
1044
|
-
// }
|
|
1045
|
-
// ],
|
|
1046
|
-
// },
|
|
1047
|
-
// }
|
|
1048
|
-
//
|
|
1049
|
-
const data = this.safeValue(response, 'data');
|
|
1050
|
-
const cancelledOrderIds = this.safeValue(data, 'cancelledOrderIds');
|
|
1051
|
-
const cancelledOrderIdsLength = cancelledOrderIds.length;
|
|
1052
|
-
if (cancelledOrderIdsLength === 0) {
|
|
1053
|
-
throw new InvalidOrder(this.id + ' cancelOrder() order already cancelled');
|
|
1054
|
-
}
|
|
1055
|
-
return this.parseOrder(data);
|
|
1056
|
-
}
|
|
1057
|
-
/**
|
|
1058
|
-
* @method
|
|
1059
|
-
* @name poloniexfutures#fetchPositions
|
|
1060
|
-
* @description fetch all open positions
|
|
1061
|
-
* @see https://api-docs.poloniex.com/futures/api/positions#get-position-list
|
|
1062
|
-
* @param {string[]|undefined} symbols list of unified market symbols
|
|
1063
|
-
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
1064
|
-
* @returns {object[]} a list of [position structure]{@link https://docs.ccxt.com/#/?id=position-structure}
|
|
1065
|
-
*/
|
|
1066
|
-
async fetchPositions(symbols = undefined, params = {}) {
|
|
1067
|
-
await this.loadMarkets();
|
|
1068
|
-
const response = await this.privateGetPositions(params);
|
|
1069
|
-
//
|
|
1070
|
-
// {
|
|
1071
|
-
// "code": "200000",
|
|
1072
|
-
// "data": [
|
|
1073
|
-
// {
|
|
1074
|
-
// "id": "615ba79f83a3410001cde321",
|
|
1075
|
-
// "symbol": "ETHUSDTM",
|
|
1076
|
-
// "autoDeposit": false,
|
|
1077
|
-
// "maintMarginReq": 0.005,
|
|
1078
|
-
// "riskLimit": 1000000,
|
|
1079
|
-
// "realLeverage": 18.61,
|
|
1080
|
-
// "crossMode": false,
|
|
1081
|
-
// "delevPercentage": 0.86,
|
|
1082
|
-
// "openingTimestamp": 1638563515618,
|
|
1083
|
-
// "currentTimestamp": 1638576872774,
|
|
1084
|
-
// "currentQty": 2,
|
|
1085
|
-
// "currentCost": 83.64200000,
|
|
1086
|
-
// "currentComm": 0.05018520,
|
|
1087
|
-
// "unrealisedCost": 83.64200000,
|
|
1088
|
-
// "realisedGrossCost": 0.00000000,
|
|
1089
|
-
// "realisedCost": 0.05018520,
|
|
1090
|
-
// "isOpen": true,
|
|
1091
|
-
// "markPrice": 4225.01,
|
|
1092
|
-
// "markValue": 84.50020000,
|
|
1093
|
-
// "posCost": 83.64200000,
|
|
1094
|
-
// "posCross": 0.0000000000,
|
|
1095
|
-
// "posInit": 3.63660870,
|
|
1096
|
-
// "posComm": 0.05236717,
|
|
1097
|
-
// "posLoss": 0.00000000,
|
|
1098
|
-
// "posMargin": 3.68897586,
|
|
1099
|
-
// "posMaint": 0.50637594,
|
|
1100
|
-
// "maintMargin": 4.54717586,
|
|
1101
|
-
// "realisedGrossPnl": 0.00000000,
|
|
1102
|
-
// "realisedPnl": -0.05018520,
|
|
1103
|
-
// "unrealisedPnl": 0.85820000,
|
|
1104
|
-
// "unrealisedPnlPcnt": 0.0103,
|
|
1105
|
-
// "unrealisedRoePcnt": 0.2360,
|
|
1106
|
-
// "avgEntryPrice": 4182.10,
|
|
1107
|
-
// "liquidationPrice": 4023.00,
|
|
1108
|
-
// "bankruptPrice": 4000.25,
|
|
1109
|
-
// "settleCurrency": "USDT",
|
|
1110
|
-
// "isInverse": false
|
|
1111
|
-
// }
|
|
1112
|
-
// ]
|
|
1113
|
-
// }
|
|
1114
|
-
//
|
|
1115
|
-
const data = this.safeList(response, 'data');
|
|
1116
|
-
return this.parsePositions(data, symbols);
|
|
1117
|
-
}
|
|
1118
|
-
parsePosition(position, market = undefined) {
|
|
1119
|
-
//
|
|
1120
|
-
// {
|
|
1121
|
-
// "code": "200000",
|
|
1122
|
-
// "data": [
|
|
1123
|
-
// {
|
|
1124
|
-
// "id": "615ba79f83a3410001cde321", // Position ID
|
|
1125
|
-
// "symbol": "ETHUSDTM", // Symbol
|
|
1126
|
-
// "autoDeposit": false, // Auto deposit margin or not
|
|
1127
|
-
// "maintMarginReq": 0.005, // Maintenance margin requirement
|
|
1128
|
-
// "riskLimit": 1000000, // Risk limit
|
|
1129
|
-
// "realLeverage": 25.92, // Leverage of the order
|
|
1130
|
-
// "crossMode": false, // Cross mode or not
|
|
1131
|
-
// "delevPercentage": 0.76, // ADL ranking percentile
|
|
1132
|
-
// "openingTimestamp": 1638578546031, // Open time
|
|
1133
|
-
// "currentTimestamp": 1638578563580, // Current timestamp
|
|
1134
|
-
// "currentQty": 2, // Current postion quantity
|
|
1135
|
-
// "currentCost": 83.787, // Current postion value
|
|
1136
|
-
// "currentComm": 0.0167574, // Current commission
|
|
1137
|
-
// "unrealisedCost": 83.787, // Unrealised value
|
|
1138
|
-
// "realisedGrossCost": 0.0, // Accumulated realised gross profit value
|
|
1139
|
-
// "realisedCost": 0.0167574, // Current realised position value
|
|
1140
|
-
// "isOpen": true, // Opened position or not
|
|
1141
|
-
// "markPrice": 4183.38, // Mark price
|
|
1142
|
-
// "markValue": 83.6676, // Mark value
|
|
1143
|
-
// "posCost": 83.787, // Position value
|
|
1144
|
-
// "posCross": 0.0, // added margin
|
|
1145
|
-
// "posInit": 3.35148, // Leverage margin
|
|
1146
|
-
// "posComm": 0.05228309, // Bankruptcy cost
|
|
1147
|
-
// "posLoss": 0.0, // Funding fees paid out
|
|
1148
|
-
// "posMargin": 3.40376309, // Position margin
|
|
1149
|
-
// "posMaint": 0.50707892, // Maintenance margin
|
|
1150
|
-
// "maintMargin": 3.28436309, // Position margin
|
|
1151
|
-
// "realisedGrossPnl": 0.0, // Accumulated realised gross profit value
|
|
1152
|
-
// "realisedPnl": -0.0167574, // Realised profit and loss
|
|
1153
|
-
// "unrealisedPnl": -0.1194, // Unrealised profit and loss
|
|
1154
|
-
// "unrealisedPnlPcnt": -0.0014, // Profit-loss ratio of the position
|
|
1155
|
-
// "unrealisedRoePcnt": -0.0356, // Rate of return on investment
|
|
1156
|
-
// "avgEntryPrice": 4189.35, // Average entry price
|
|
1157
|
-
// "liquidationPrice": 4044.55, // Liquidation price
|
|
1158
|
-
// "bankruptPrice": 4021.75, // Bankruptcy price
|
|
1159
|
-
// "settleCurrency": "USDT", // Currency used to clear and settle the trades
|
|
1160
|
-
// "isInverse": false
|
|
1161
|
-
// }
|
|
1162
|
-
// ]
|
|
1163
|
-
// }
|
|
1164
|
-
//
|
|
1165
|
-
const symbol = this.safeString(position, 'symbol');
|
|
1166
|
-
market = this.safeMarket(symbol, market);
|
|
1167
|
-
const timestamp = this.safeInteger(position, 'currentTimestamp');
|
|
1168
|
-
const size = this.safeString(position, 'currentQty');
|
|
1169
|
-
let side;
|
|
1170
|
-
if (Precise.stringGt(size, '0')) {
|
|
1171
|
-
side = 'long';
|
|
1172
|
-
}
|
|
1173
|
-
else if (Precise.stringLt(size, '0')) {
|
|
1174
|
-
side = 'short';
|
|
1175
|
-
}
|
|
1176
|
-
const notional = Precise.stringAbs(this.safeString(position, 'posCost'));
|
|
1177
|
-
const initialMargin = this.safeString(position, 'posInit');
|
|
1178
|
-
const initialMarginPercentage = Precise.stringDiv(initialMargin, notional);
|
|
1179
|
-
// const marginRatio = Precise.stringDiv (maintenanceRate, collateral);
|
|
1180
|
-
const unrealisedPnl = this.safeString(position, 'unrealisedPnl');
|
|
1181
|
-
const crossMode = this.safeValue(position, 'crossMode');
|
|
1182
|
-
// currently crossMode is always set to false and only isolated positions are supported
|
|
1183
|
-
const marginMode = crossMode ? 'cross' : 'isolated';
|
|
1184
|
-
return {
|
|
1185
|
-
'info': position,
|
|
1186
|
-
'id': undefined,
|
|
1187
|
-
'symbol': this.safeString(market, 'symbol'),
|
|
1188
|
-
'timestamp': timestamp,
|
|
1189
|
-
'datetime': this.iso8601(timestamp),
|
|
1190
|
-
'initialMargin': this.parseNumber(initialMargin),
|
|
1191
|
-
'initialMarginPercentage': this.parseNumber(initialMarginPercentage),
|
|
1192
|
-
'maintenanceMargin': this.safeNumber(position, 'posMaint'),
|
|
1193
|
-
'maintenanceMarginPercentage': this.safeNumber(position, 'maintMarginReq'),
|
|
1194
|
-
'entryPrice': this.safeNumber(position, 'avgEntryPrice'),
|
|
1195
|
-
'notional': this.parseNumber(notional),
|
|
1196
|
-
'leverage': this.safeNumber(position, 'realLeverage'),
|
|
1197
|
-
'unrealizedPnl': this.parseNumber(unrealisedPnl),
|
|
1198
|
-
'contracts': this.parseNumber(Precise.stringAbs(size)),
|
|
1199
|
-
'contractSize': this.safeValue(market, 'contractSize'),
|
|
1200
|
-
'marginRatio': undefined,
|
|
1201
|
-
'liquidationPrice': this.safeNumber(position, 'liquidationPrice'),
|
|
1202
|
-
'markPrice': this.safeNumber(position, 'markPrice'),
|
|
1203
|
-
'collateral': this.safeNumber(position, 'maintMargin'),
|
|
1204
|
-
'marginMode': marginMode,
|
|
1205
|
-
'side': side,
|
|
1206
|
-
'percentage': this.parseNumber(Precise.stringDiv(unrealisedPnl, initialMargin)),
|
|
1207
|
-
'stopLossPrice': undefined,
|
|
1208
|
-
'takeProfitPrice': undefined,
|
|
1209
|
-
};
|
|
1210
|
-
}
|
|
1211
|
-
/**
|
|
1212
|
-
* @method
|
|
1213
|
-
* @name poloniexfutures#fetchFundingHistory
|
|
1214
|
-
* @description fetch the history of funding payments paid and received on this account
|
|
1215
|
-
* @see https://api-docs.poloniex.com/futures/api/funding-fees#get-funding-history
|
|
1216
|
-
* @param {string} symbol unified market symbol
|
|
1217
|
-
* @param {int} [since] the earliest time in ms to fetch funding history for
|
|
1218
|
-
* @param {int} [limit] the maximum number of funding history structures to retrieve
|
|
1219
|
-
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
1220
|
-
* @returns {object} a [funding history structure]{@link https://docs.ccxt.com/#/?id=funding-history-structure}
|
|
1221
|
-
*/
|
|
1222
|
-
async fetchFundingHistory(symbol = undefined, since = undefined, limit = undefined, params = {}) {
|
|
1223
|
-
if (symbol === undefined) {
|
|
1224
|
-
throw new ArgumentsRequired(this.id + ' fetchFundingHistory() requires a symbol argument');
|
|
1225
|
-
}
|
|
1226
|
-
await this.loadMarkets();
|
|
1227
|
-
const market = this.market(symbol);
|
|
1228
|
-
const request = {
|
|
1229
|
-
'symbol': market['id'],
|
|
1230
|
-
};
|
|
1231
|
-
if (since !== undefined) {
|
|
1232
|
-
request['startAt'] = since;
|
|
1233
|
-
}
|
|
1234
|
-
if (limit !== undefined) {
|
|
1235
|
-
// * Since is ignored if limit is defined
|
|
1236
|
-
request['maxCount'] = limit;
|
|
1237
|
-
}
|
|
1238
|
-
const response = await this.privateGetFundingHistory(this.extend(request, params));
|
|
1239
|
-
//
|
|
1240
|
-
// {
|
|
1241
|
-
// "code": "200000",
|
|
1242
|
-
// "data": {
|
|
1243
|
-
// "dataList": [
|
|
1244
|
-
// {
|
|
1245
|
-
// "id": 239471298749817,
|
|
1246
|
-
// "symbol": "ETHUSDTM",
|
|
1247
|
-
// "timePoint": 1638532800000,
|
|
1248
|
-
// "fundingRate": 0.000100,
|
|
1249
|
-
// "markPrice": 4612.8300000000,
|
|
1250
|
-
// "positionQty": 12,
|
|
1251
|
-
// "positionCost": 553.5396000000,
|
|
1252
|
-
// "funding": -0.0553539600,
|
|
1253
|
-
// "settleCurrency": "USDT"
|
|
1254
|
-
// },
|
|
1255
|
-
// ...
|
|
1256
|
-
// ],
|
|
1257
|
-
// "hasMore": true
|
|
1258
|
-
// }
|
|
1259
|
-
// }
|
|
1260
|
-
//
|
|
1261
|
-
const data = this.safeValue(response, 'data');
|
|
1262
|
-
const dataList = this.safeValue(data, 'dataList', []);
|
|
1263
|
-
const dataListLength = dataList.length;
|
|
1264
|
-
const fees = [];
|
|
1265
|
-
for (let i = 0; i < dataListLength; i++) {
|
|
1266
|
-
const listItem = dataList[i];
|
|
1267
|
-
const timestamp = this.safeInteger(listItem, 'timePoint');
|
|
1268
|
-
fees.push({
|
|
1269
|
-
'info': listItem,
|
|
1270
|
-
'symbol': symbol,
|
|
1271
|
-
'code': this.safeCurrencyCode(this.safeString(listItem, 'settleCurrency')),
|
|
1272
|
-
'timestamp': timestamp,
|
|
1273
|
-
'datetime': this.iso8601(timestamp),
|
|
1274
|
-
'id': this.safeNumber(listItem, 'id'),
|
|
1275
|
-
'amount': this.safeNumber(listItem, 'funding'),
|
|
1276
|
-
'fundingRate': this.safeNumber(listItem, 'fundingRate'),
|
|
1277
|
-
'markPrice': this.safeNumber(listItem, 'markPrice'),
|
|
1278
|
-
'positionQty': this.safeNumber(listItem, 'positionQty'),
|
|
1279
|
-
'positionCost': this.safeNumber(listItem, 'positionCost'),
|
|
1280
|
-
});
|
|
1281
|
-
}
|
|
1282
|
-
return fees;
|
|
1283
|
-
}
|
|
1284
|
-
/**
|
|
1285
|
-
* @method
|
|
1286
|
-
* @name poloniexfutures#cancelAllOrders
|
|
1287
|
-
* @description cancel all open orders
|
|
1288
|
-
* @param {string} symbol unified market symbol, only orders in the market of this symbol are cancelled when symbol is not undefined
|
|
1289
|
-
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
1290
|
-
* @param {object} [params.trigger] When true, all the trigger orders will be cancelled
|
|
1291
|
-
* @returns {object[]} a list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
|
|
1292
|
-
*/
|
|
1293
|
-
async cancelAllOrders(symbol = undefined, params = {}) {
|
|
1294
|
-
await this.loadMarkets();
|
|
1295
|
-
const request = {};
|
|
1296
|
-
if (symbol !== undefined) {
|
|
1297
|
-
request['symbol'] = this.marketId(symbol);
|
|
1298
|
-
}
|
|
1299
|
-
const trigger = this.safeValue2(params, 'stop', 'trigger');
|
|
1300
|
-
params = this.omit(params, ['stop', 'trigger']);
|
|
1301
|
-
let response = undefined;
|
|
1302
|
-
if (trigger) {
|
|
1303
|
-
response = await this.privateDeleteStopOrders(this.extend(request, params));
|
|
1304
|
-
}
|
|
1305
|
-
else {
|
|
1306
|
-
response = await this.privateDeleteOrders(this.extend(request, params));
|
|
1307
|
-
}
|
|
1308
|
-
//
|
|
1309
|
-
// {
|
|
1310
|
-
// "code": "200000",
|
|
1311
|
-
// "data": {
|
|
1312
|
-
// "cancelledOrderIds": [
|
|
1313
|
-
// "619714b8b6353000014c505a",
|
|
1314
|
-
// ],
|
|
1315
|
-
// },
|
|
1316
|
-
// }
|
|
1317
|
-
//
|
|
1318
|
-
const data = this.safeValue(response, 'data');
|
|
1319
|
-
const result = [];
|
|
1320
|
-
const cancelledOrderIds = this.safeValue(data, 'cancelledOrderIds');
|
|
1321
|
-
const cancelledOrderIdsLength = cancelledOrderIds.length;
|
|
1322
|
-
for (let i = 0; i < cancelledOrderIdsLength; i++) {
|
|
1323
|
-
const cancelledOrderId = this.safeString(cancelledOrderIds, i);
|
|
1324
|
-
result.push(this.safeOrder({
|
|
1325
|
-
'id': cancelledOrderId,
|
|
1326
|
-
'clientOrderId': undefined,
|
|
1327
|
-
'timestamp': undefined,
|
|
1328
|
-
'datetime': undefined,
|
|
1329
|
-
'lastTradeTimestamp': undefined,
|
|
1330
|
-
'symbol': undefined,
|
|
1331
|
-
'type': undefined,
|
|
1332
|
-
'side': undefined,
|
|
1333
|
-
'price': undefined,
|
|
1334
|
-
'amount': undefined,
|
|
1335
|
-
'cost': undefined,
|
|
1336
|
-
'average': undefined,
|
|
1337
|
-
'filled': undefined,
|
|
1338
|
-
'remaining': undefined,
|
|
1339
|
-
'status': undefined,
|
|
1340
|
-
'fee': undefined,
|
|
1341
|
-
'trades': undefined,
|
|
1342
|
-
'timeInForce': undefined,
|
|
1343
|
-
'postOnly': undefined,
|
|
1344
|
-
'triggerPrice': undefined,
|
|
1345
|
-
'info': response,
|
|
1346
|
-
}));
|
|
1347
|
-
}
|
|
1348
|
-
return result;
|
|
1349
|
-
}
|
|
1350
|
-
/**
|
|
1351
|
-
* @method
|
|
1352
|
-
* @name poloniexfutures#fetchOrdersByStatus
|
|
1353
|
-
* @description fetches a list of orders placed on the exchange
|
|
1354
|
-
* @see https://api-docs.poloniex.com/futures/api/orders#get-order-listdeprecated
|
|
1355
|
-
* @see https://api-docs.poloniex.com/futures/api/orders#get-untriggered-stop-order-list
|
|
1356
|
-
* @param {string} status 'active' or 'closed', only 'active' is valid for stop orders
|
|
1357
|
-
* @param {string} symbol unified symbol for the market to retrieve orders from
|
|
1358
|
-
* @param {int} [since] timestamp in ms of the earliest order to retrieve
|
|
1359
|
-
* @param {int} [limit] The maximum number of orders to retrieve
|
|
1360
|
-
* @param {object} [params] exchange specific parameters
|
|
1361
|
-
* @param {bool} [params.stop] set to true to retrieve untriggered stop orders
|
|
1362
|
-
* @param {int} [params.until] End time in ms
|
|
1363
|
-
* @param {string} [params.side] buy or sell
|
|
1364
|
-
* @param {string} [params.type] limit or market
|
|
1365
|
-
* @returns An [array of order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
|
|
1366
|
-
*/
|
|
1367
|
-
async fetchOrdersByStatus(status, symbol = undefined, since = undefined, limit = undefined, params = {}) {
|
|
1368
|
-
await this.loadMarkets();
|
|
1369
|
-
const trigger = this.safeValue2(params, 'stop', 'trigger');
|
|
1370
|
-
const until = this.safeInteger(params, 'until');
|
|
1371
|
-
params = this.omit(params, ['trigger', 'stop', 'until']);
|
|
1372
|
-
if (status === 'closed') {
|
|
1373
|
-
status = 'done';
|
|
1374
|
-
}
|
|
1375
|
-
const request = {};
|
|
1376
|
-
if (!trigger) {
|
|
1377
|
-
request['status'] = (status === 'open') ? 'active' : 'done';
|
|
1378
|
-
}
|
|
1379
|
-
else if (status !== 'open') {
|
|
1380
|
-
throw new BadRequest(this.id + ' fetchOrdersByStatus() can only fetch untriggered stop orders');
|
|
1381
|
-
}
|
|
1382
|
-
let market = undefined;
|
|
1383
|
-
if (symbol !== undefined) {
|
|
1384
|
-
market = this.market(symbol);
|
|
1385
|
-
request['symbol'] = market['id'];
|
|
1386
|
-
}
|
|
1387
|
-
if (since !== undefined) {
|
|
1388
|
-
request['startAt'] = since;
|
|
1389
|
-
}
|
|
1390
|
-
if (until !== undefined) {
|
|
1391
|
-
request['endAt'] = until;
|
|
1392
|
-
}
|
|
1393
|
-
let response = undefined;
|
|
1394
|
-
if (trigger) {
|
|
1395
|
-
response = await this.privateGetStopOrders(this.extend(request, params));
|
|
1396
|
-
}
|
|
1397
|
-
else {
|
|
1398
|
-
response = await this.privateGetOrders(this.extend(request, params));
|
|
1399
|
-
}
|
|
1400
|
-
//
|
|
1401
|
-
// {
|
|
1402
|
-
// "code": "200000",
|
|
1403
|
-
// "data": {
|
|
1404
|
-
// "totalNum": 1,
|
|
1405
|
-
// "totalPage": 1,
|
|
1406
|
-
// "pageSize": 50,
|
|
1407
|
-
// "currentPage": 1,
|
|
1408
|
-
// "items": [
|
|
1409
|
-
// {
|
|
1410
|
-
// "symbol": "ADAUSDTPERP",
|
|
1411
|
-
// "leverage": "1",
|
|
1412
|
-
// "hidden": false,
|
|
1413
|
-
// "forceHold": false,
|
|
1414
|
-
// "closeOrder": false,
|
|
1415
|
-
// "type": "limit",
|
|
1416
|
-
// "isActive": true,
|
|
1417
|
-
// "createdAt": 1678936920000,
|
|
1418
|
-
// "orderTime": 1678936920480905922,
|
|
1419
|
-
// "price": "0.3",
|
|
1420
|
-
// "iceberg": false,
|
|
1421
|
-
// "stopTriggered": false,
|
|
1422
|
-
// "id": "64128b582cc0710007a3c840",
|
|
1423
|
-
// "value": "3",
|
|
1424
|
-
// "timeInForce": "GTC",
|
|
1425
|
-
// "updatedAt": 1678936920000,
|
|
1426
|
-
// "side": "buy",
|
|
1427
|
-
// "stopPriceType": "",
|
|
1428
|
-
// "dealValue": "0",
|
|
1429
|
-
// "dealSize": 0,
|
|
1430
|
-
// "settleCurrency": "USDT",
|
|
1431
|
-
// "stp": "",
|
|
1432
|
-
// "filledValue": "0",
|
|
1433
|
-
// "postOnly": false,
|
|
1434
|
-
// "size": 1,
|
|
1435
|
-
// "stop": "",
|
|
1436
|
-
// "filledSize": 0,
|
|
1437
|
-
// "reduceOnly": false,
|
|
1438
|
-
// "marginType": 1,
|
|
1439
|
-
// "cancelExist": false,
|
|
1440
|
-
// "clientOid": "ba669f39-dfcc-4664-9801-a42d06e59c2e",
|
|
1441
|
-
// "status": "open"
|
|
1442
|
-
// }
|
|
1443
|
-
// ]
|
|
1444
|
-
// }
|
|
1445
|
-
// }
|
|
1446
|
-
//
|
|
1447
|
-
const responseData = this.safeValue(response, 'data', {});
|
|
1448
|
-
const orders = this.safeValue(responseData, 'items', []);
|
|
1449
|
-
const ordersLength = orders.length;
|
|
1450
|
-
const result = [];
|
|
1451
|
-
for (let i = 0; i < ordersLength; i++) {
|
|
1452
|
-
const order = orders[i];
|
|
1453
|
-
const orderStatus = this.safeString(order, 'status');
|
|
1454
|
-
if (status === orderStatus) {
|
|
1455
|
-
result.push(orders[i]);
|
|
1456
|
-
}
|
|
1457
|
-
}
|
|
1458
|
-
return this.parseOrders(result, market, since, limit);
|
|
1459
|
-
}
|
|
1460
|
-
/**
|
|
1461
|
-
* @method
|
|
1462
|
-
* @name poloniexfutures#fetchOpenOrders
|
|
1463
|
-
* @description fetch all unfilled currently open orders
|
|
1464
|
-
* @see https://api-docs.poloniex.com/futures/api/orders#get-order-listdeprecated
|
|
1465
|
-
* @see https://api-docs.poloniex.com/futures/api/orders#get-untriggered-stop-order-list
|
|
1466
|
-
* @param {string} symbol unified market symbol
|
|
1467
|
-
* @param {int} [since] the earliest time in ms to fetch open orders for
|
|
1468
|
-
* @param {int} [limit] the maximum number of open orders structures to retrieve
|
|
1469
|
-
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
1470
|
-
* @param {int} [params.until] end time in ms
|
|
1471
|
-
* @param {string} [params.side] buy or sell
|
|
1472
|
-
* @param {string} [params.type] limit, or market
|
|
1473
|
-
* @returns {Order[]} a list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
|
|
1474
|
-
*/
|
|
1475
|
-
async fetchOpenOrders(symbol = undefined, since = undefined, limit = undefined, params = {}) {
|
|
1476
|
-
return await this.fetchOrdersByStatus('open', symbol, since, limit, params);
|
|
1477
|
-
}
|
|
1478
|
-
/**
|
|
1479
|
-
* @method
|
|
1480
|
-
* @name poloniexfutures#fetchClosedOrders
|
|
1481
|
-
* @description fetches information on multiple closed orders made by the user
|
|
1482
|
-
* @see https://api-docs.poloniex.com/futures/api/orders#get-order-listdeprecated
|
|
1483
|
-
* @see https://api-docs.poloniex.com/futures/api/orders#get-untriggered-stop-order-list
|
|
1484
|
-
* @param {string} symbol unified market symbol of the market orders were made in
|
|
1485
|
-
* @param {int} [since] the earliest time in ms to fetch orders for
|
|
1486
|
-
* @param {int} [limit] the maximum number of order structures to retrieve
|
|
1487
|
-
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
1488
|
-
* @param {int} [params.until] end time in ms
|
|
1489
|
-
* @param {string} [params.side] buy or sell
|
|
1490
|
-
* @param {string} [params.type] limit, or market
|
|
1491
|
-
* @returns {Order[]} a list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
|
|
1492
|
-
*/
|
|
1493
|
-
async fetchClosedOrders(symbol = undefined, since = undefined, limit = undefined, params = {}) {
|
|
1494
|
-
return await this.fetchOrdersByStatus('closed', symbol, since, limit, params);
|
|
1495
|
-
}
|
|
1496
|
-
/**
|
|
1497
|
-
* @method
|
|
1498
|
-
* @name poloniexfutures#fetchOrder
|
|
1499
|
-
* @description fetches information on an order made by the user
|
|
1500
|
-
* @see https://api-docs.poloniex.com/futures/api/orders#get-details-of-a-single-order
|
|
1501
|
-
* @see https://api-docs.poloniex.com/futures/api/orders#get-single-order-by-clientoid
|
|
1502
|
-
* @param {string} id the order id
|
|
1503
|
-
* @param {string} symbol unified symbol of the market the order was made in
|
|
1504
|
-
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
1505
|
-
* @returns {object} An [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
|
|
1506
|
-
*/
|
|
1507
|
-
async fetchOrder(id, symbol = undefined, params = {}) {
|
|
1508
|
-
await this.loadMarkets();
|
|
1509
|
-
const request = {};
|
|
1510
|
-
let response = undefined;
|
|
1511
|
-
if (id === undefined) {
|
|
1512
|
-
const clientOrderId = this.safeString2(params, 'clientOid', 'clientOrderId');
|
|
1513
|
-
if (clientOrderId === undefined) {
|
|
1514
|
-
throw new InvalidOrder(this.id + ' fetchOrder() requires parameter id or params.clientOid');
|
|
1515
|
-
}
|
|
1516
|
-
request['clientOid'] = clientOrderId;
|
|
1517
|
-
params = this.omit(params, ['clientOid', 'clientOrderId']);
|
|
1518
|
-
response = await this.privateGetClientOrderIdClientOid(this.extend(request, params));
|
|
1519
|
-
}
|
|
1520
|
-
else {
|
|
1521
|
-
request['order-id'] = id;
|
|
1522
|
-
response = await this.privateGetOrdersOrderId(this.extend(request, params));
|
|
1523
|
-
}
|
|
1524
|
-
//
|
|
1525
|
-
// {
|
|
1526
|
-
// "code": "200000",
|
|
1527
|
-
// "data": {
|
|
1528
|
-
// "symbol": "ADAUSDTPERP",
|
|
1529
|
-
// "leverage": "1",
|
|
1530
|
-
// "hidden": false,
|
|
1531
|
-
// "forceHold": false,
|
|
1532
|
-
// "closeOrder": false,
|
|
1533
|
-
// "type": "market",
|
|
1534
|
-
// "isActive": false,
|
|
1535
|
-
// "createdAt": 1678929587000,
|
|
1536
|
-
// "orderTime": 1678929587248115582,
|
|
1537
|
-
// "iceberg": false,
|
|
1538
|
-
// "stopTriggered": false,
|
|
1539
|
-
// "id": "64126eb38c6919000737dcdc",
|
|
1540
|
-
// "value": "3.1783",
|
|
1541
|
-
// "timeInForce": "GTC",
|
|
1542
|
-
// "updatedAt": 1678929587000,
|
|
1543
|
-
// "side": "buy",
|
|
1544
|
-
// "stopPriceType": "",
|
|
1545
|
-
// "dealValue": "3.1783",
|
|
1546
|
-
// "dealSize": 1,
|
|
1547
|
-
// "settleCurrency": "USDT",
|
|
1548
|
-
// "trades": [
|
|
1549
|
-
// {
|
|
1550
|
-
// "feePay": "0.00158915",
|
|
1551
|
-
// "tradeId": "64126eb36803eb0001ff99bc"
|
|
1552
|
-
// }
|
|
1553
|
-
// ],
|
|
1554
|
-
// "endAt": 1678929587000,
|
|
1555
|
-
// "stp": "",
|
|
1556
|
-
// "filledValue": "3.1783",
|
|
1557
|
-
// "postOnly": false,
|
|
1558
|
-
// "size": 1,
|
|
1559
|
-
// "stop": "",
|
|
1560
|
-
// "filledSize": 1,
|
|
1561
|
-
// "reduceOnly": false,
|
|
1562
|
-
// "marginType": 1,
|
|
1563
|
-
// "cancelExist": false,
|
|
1564
|
-
// "clientOid": "d19e8fcb-2df4-44bc-afd4-67dd42048246",
|
|
1565
|
-
// "status": "done"
|
|
1566
|
-
// }
|
|
1567
|
-
// }
|
|
1568
|
-
//
|
|
1569
|
-
const market = (symbol !== undefined) ? this.market(symbol) : undefined;
|
|
1570
|
-
const responseData = this.safeDict(response, 'data');
|
|
1571
|
-
return this.parseOrder(responseData, market);
|
|
1572
|
-
}
|
|
1573
|
-
parseOrder(order, market = undefined) {
|
|
1574
|
-
//
|
|
1575
|
-
// createOrder
|
|
1576
|
-
//
|
|
1577
|
-
// {
|
|
1578
|
-
// "code": "200000",
|
|
1579
|
-
// "data": {
|
|
1580
|
-
// "orderId": "619717484f1d010001510cde",
|
|
1581
|
-
// },
|
|
1582
|
-
// }
|
|
1583
|
-
//
|
|
1584
|
-
// fetchOrder
|
|
1585
|
-
//
|
|
1586
|
-
// {
|
|
1587
|
-
// "symbol": "ADAUSDTPERP",
|
|
1588
|
-
// "leverage": "1",
|
|
1589
|
-
// "hidden": false,
|
|
1590
|
-
// "forceHold": false,
|
|
1591
|
-
// "closeOrder": false,
|
|
1592
|
-
// "type": "market",
|
|
1593
|
-
// "isActive": false,
|
|
1594
|
-
// "createdAt": 1678929587000,
|
|
1595
|
-
// "orderTime": 1678929587248115582,
|
|
1596
|
-
// "iceberg": false,
|
|
1597
|
-
// "stopTriggered": false,
|
|
1598
|
-
// "id": "64126eb38c6919000737dcdc",
|
|
1599
|
-
// "value": "3.1783",
|
|
1600
|
-
// "timeInForce": "GTC",
|
|
1601
|
-
// "updatedAt": 1678929587000,
|
|
1602
|
-
// "side": "buy",
|
|
1603
|
-
// "stopPriceType": "",
|
|
1604
|
-
// "dealValue": "3.1783",
|
|
1605
|
-
// "dealSize": 1,
|
|
1606
|
-
// "settleCurrency": "USDT",
|
|
1607
|
-
// "trades": [
|
|
1608
|
-
// {
|
|
1609
|
-
// "feePay": "0.00158915",
|
|
1610
|
-
// "tradeId": "64126eb36803eb0001ff99bc"
|
|
1611
|
-
// }
|
|
1612
|
-
// ],
|
|
1613
|
-
// "endAt": 1678929587000,
|
|
1614
|
-
// "stp": "",
|
|
1615
|
-
// "filledValue": "3.1783",
|
|
1616
|
-
// "postOnly": false,
|
|
1617
|
-
// "size": 1,
|
|
1618
|
-
// "stop": "",
|
|
1619
|
-
// "filledSize": 1,
|
|
1620
|
-
// "reduceOnly": false,
|
|
1621
|
-
// "marginType": 1,
|
|
1622
|
-
// "cancelExist": false,
|
|
1623
|
-
// "clientOid": "d19e8fcb-2df4-44bc-afd4-67dd42048246",
|
|
1624
|
-
// "status": "done"
|
|
1625
|
-
// }
|
|
1626
|
-
//
|
|
1627
|
-
// cancelOrder
|
|
1628
|
-
//
|
|
1629
|
-
// {
|
|
1630
|
-
// "cancelledOrderIds": [
|
|
1631
|
-
// "619714b8b6353000014c505a",
|
|
1632
|
-
// ],
|
|
1633
|
-
// "cancelFailedOrders": [
|
|
1634
|
-
// {
|
|
1635
|
-
// "orderId": "63a9c5c2b9e7d70007eb0cd5",
|
|
1636
|
-
// "orderState": "2"
|
|
1637
|
-
// }
|
|
1638
|
-
// ],
|
|
1639
|
-
// },
|
|
1640
|
-
//
|
|
1641
|
-
const marketId = this.safeString(order, 'symbol');
|
|
1642
|
-
market = this.safeMarket(marketId, market);
|
|
1643
|
-
const timestamp = this.safeInteger(order, 'createdAt');
|
|
1644
|
-
// price is zero for market order
|
|
1645
|
-
// omitZero is called in safeOrder2
|
|
1646
|
-
const feeCurrencyId = this.safeString(order, 'feeCurrency');
|
|
1647
|
-
const filled = this.safeString(order, 'dealSize');
|
|
1648
|
-
const rawCost = this.safeString2(order, 'dealFunds', 'filledValue');
|
|
1649
|
-
let average = undefined;
|
|
1650
|
-
if (Precise.stringGt(filled, '0')) {
|
|
1651
|
-
const contractSize = this.safeString(market, 'contractSize');
|
|
1652
|
-
if (market['linear']) {
|
|
1653
|
-
average = Precise.stringDiv(rawCost, Precise.stringMul(contractSize, filled));
|
|
1654
|
-
}
|
|
1655
|
-
else {
|
|
1656
|
-
average = Precise.stringDiv(Precise.stringMul(contractSize, filled), rawCost);
|
|
1657
|
-
}
|
|
1658
|
-
}
|
|
1659
|
-
// precision reported by their api is 8 d.p.
|
|
1660
|
-
// const average = Precise.stringDiv (rawCost, Precise.stringMul (filled, market['contractSize']));
|
|
1661
|
-
// bool
|
|
1662
|
-
const isActive = this.safeBool(order, 'isActive', false);
|
|
1663
|
-
const cancelExist = this.safeBool(order, 'cancelExist', false);
|
|
1664
|
-
const status = isActive ? 'open' : 'closed';
|
|
1665
|
-
let id = this.safeString(order, 'id');
|
|
1666
|
-
if ('cancelledOrderIds' in order) {
|
|
1667
|
-
const cancelledOrderIds = this.safeValue(order, 'cancelledOrderIds');
|
|
1668
|
-
id = this.safeString(cancelledOrderIds, 0);
|
|
1669
|
-
}
|
|
1670
|
-
return this.safeOrder({
|
|
1671
|
-
'info': order,
|
|
1672
|
-
'id': id,
|
|
1673
|
-
'clientOrderId': this.safeString(order, 'clientOid'),
|
|
1674
|
-
'symbol': this.safeString(market, 'symbol'),
|
|
1675
|
-
'type': this.safeString(order, 'type'),
|
|
1676
|
-
'timeInForce': this.safeString(order, 'timeInForce'),
|
|
1677
|
-
'postOnly': this.safeValue(order, 'postOnly'),
|
|
1678
|
-
'side': this.safeString(order, 'side'),
|
|
1679
|
-
'amount': this.safeString(order, 'size'),
|
|
1680
|
-
'price': this.safeString(order, 'price'),
|
|
1681
|
-
'triggerPrice': this.safeString(order, 'stopPrice'),
|
|
1682
|
-
'cost': this.safeString(order, 'dealValue'),
|
|
1683
|
-
'filled': filled,
|
|
1684
|
-
'remaining': undefined,
|
|
1685
|
-
'timestamp': timestamp,
|
|
1686
|
-
'datetime': this.iso8601(timestamp),
|
|
1687
|
-
'fee': {
|
|
1688
|
-
'currency': this.safeCurrencyCode(feeCurrencyId),
|
|
1689
|
-
'cost': this.safeString(order, 'fee'),
|
|
1690
|
-
},
|
|
1691
|
-
'status': cancelExist ? 'canceled' : status,
|
|
1692
|
-
'lastTradeTimestamp': undefined,
|
|
1693
|
-
'average': average,
|
|
1694
|
-
'trades': undefined,
|
|
1695
|
-
}, market);
|
|
1696
|
-
}
|
|
1697
|
-
/**
|
|
1698
|
-
* @method
|
|
1699
|
-
* @name poloniexfutures#fetchFundingRate
|
|
1700
|
-
* @description fetch the current funding rate
|
|
1701
|
-
* @see https://api-docs.poloniex.com/futures/api/futures-index#get-premium-index
|
|
1702
|
-
* @param {string} symbol unified market symbol
|
|
1703
|
-
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
1704
|
-
* @returns {object} a [funding rate structure]{@link https://docs.ccxt.com/#/?id=funding-rate-structure}
|
|
1705
|
-
*/
|
|
1706
|
-
async fetchFundingRate(symbol, params = {}) {
|
|
1707
|
-
await this.loadMarkets();
|
|
1708
|
-
const market = this.market(symbol);
|
|
1709
|
-
const request = {
|
|
1710
|
-
'symbol': market['id'],
|
|
1711
|
-
};
|
|
1712
|
-
const response = await this.publicGetFundingRateSymbolCurrent(this.extend(request, params));
|
|
1713
|
-
//
|
|
1714
|
-
// {
|
|
1715
|
-
// "symbol": ".BTCUSDTPERPFPI8H",
|
|
1716
|
-
// "granularity": 28800000,
|
|
1717
|
-
// "timePoint": 1558000800000,
|
|
1718
|
-
// "value": 0.00375,
|
|
1719
|
-
// "predictedValue": 0.00375
|
|
1720
|
-
// }
|
|
1721
|
-
//
|
|
1722
|
-
const data = this.safeDict(response, 'data', {});
|
|
1723
|
-
return this.parseFundingRate(data, market);
|
|
1724
|
-
}
|
|
1725
|
-
/**
|
|
1726
|
-
* @method
|
|
1727
|
-
* @name poloniexfutures#fetchFundingInterval
|
|
1728
|
-
* @description fetch the current funding rate interval
|
|
1729
|
-
* @see https://api-docs.poloniex.com/futures/api/futures-index#get-premium-index
|
|
1730
|
-
* @param {string} symbol unified market symbol
|
|
1731
|
-
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
1732
|
-
* @returns {object} a [funding rate structure]{@link https://docs.ccxt.com/#/?id=funding-rate-structure}
|
|
1733
|
-
*/
|
|
1734
|
-
async fetchFundingInterval(symbol, params = {}) {
|
|
1735
|
-
return await this.fetchFundingRate(symbol, params);
|
|
1736
|
-
}
|
|
1737
|
-
parseFundingRate(data, market = undefined) {
|
|
1738
|
-
//
|
|
1739
|
-
// {
|
|
1740
|
-
// "symbol": ".ETHUSDTMFPI8H",
|
|
1741
|
-
// "granularity": 28800000,
|
|
1742
|
-
// "timePoint": 1637380800000,
|
|
1743
|
-
// "value": 0.0001,
|
|
1744
|
-
// "predictedValue": 0.0001,
|
|
1745
|
-
// }
|
|
1746
|
-
//
|
|
1747
|
-
const fundingTimestamp = this.safeInteger(data, 'timePoint');
|
|
1748
|
-
const marketId = this.safeString(data, 'symbol');
|
|
1749
|
-
return {
|
|
1750
|
-
'info': data,
|
|
1751
|
-
'symbol': this.safeSymbol(marketId, market, undefined, 'contract'),
|
|
1752
|
-
'markPrice': undefined,
|
|
1753
|
-
'indexPrice': undefined,
|
|
1754
|
-
'interestRate': undefined,
|
|
1755
|
-
'estimatedSettlePrice': undefined,
|
|
1756
|
-
'timestamp': undefined,
|
|
1757
|
-
'datetime': undefined,
|
|
1758
|
-
'fundingRate': this.safeNumber(data, 'value'),
|
|
1759
|
-
'fundingTimestamp': fundingTimestamp,
|
|
1760
|
-
'fundingDatetime': this.iso8601(fundingTimestamp),
|
|
1761
|
-
'nextFundingRate': this.safeNumber(data, 'predictedValue'),
|
|
1762
|
-
'nextFundingTimestamp': undefined,
|
|
1763
|
-
'nextFundingDatetime': undefined,
|
|
1764
|
-
'previousFundingRate': undefined,
|
|
1765
|
-
'previousFundingTimestamp': undefined,
|
|
1766
|
-
'previousFundingDatetime': undefined,
|
|
1767
|
-
'interval': this.parseFundingInterval(this.safeString(data, 'granularity')),
|
|
1768
|
-
};
|
|
1769
|
-
}
|
|
1770
|
-
parseFundingInterval(interval) {
|
|
1771
|
-
const intervals = {
|
|
1772
|
-
'3600000': '1h',
|
|
1773
|
-
'14400000': '4h',
|
|
1774
|
-
'28800000': '8h',
|
|
1775
|
-
'57600000': '16h',
|
|
1776
|
-
'86400000': '24h',
|
|
1777
|
-
};
|
|
1778
|
-
return this.safeString(intervals, interval, interval);
|
|
1779
|
-
}
|
|
1780
|
-
/**
|
|
1781
|
-
* @method
|
|
1782
|
-
* @name poloniexfutures#fetchMyTrades
|
|
1783
|
-
* @description fetch all trades made by the user
|
|
1784
|
-
* @see https://api-docs.poloniex.com/futures/api/fills#get-fillsdeprecated
|
|
1785
|
-
* @param {string} symbol unified market symbol
|
|
1786
|
-
* @param {int} [since] the earliest time in ms to fetch trades for
|
|
1787
|
-
* @param {int} [limit] the maximum number of trades structures to retrieve
|
|
1788
|
-
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
1789
|
-
* @param {string} [params.orderIdFills] filles for a specific order (other parameters can be ignored if specified)
|
|
1790
|
-
* @param {string} [params.side] buy or sell
|
|
1791
|
-
* @param {string} [params.type] limit, market, limit_stop or market_stop
|
|
1792
|
-
* @param {int} [params.endAt] end time (milisecond)
|
|
1793
|
-
* @returns {Trade[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=trade-structure}
|
|
1794
|
-
*/
|
|
1795
|
-
async fetchMyTrades(symbol = undefined, since = undefined, limit = undefined, params = {}) {
|
|
1796
|
-
await this.loadMarkets();
|
|
1797
|
-
const request = {};
|
|
1798
|
-
let market = undefined;
|
|
1799
|
-
if (symbol !== undefined) {
|
|
1800
|
-
market = this.market(symbol);
|
|
1801
|
-
request['symbol'] = market['id'];
|
|
1802
|
-
}
|
|
1803
|
-
if (since !== undefined) {
|
|
1804
|
-
request['startAt'] = since;
|
|
1805
|
-
}
|
|
1806
|
-
const response = await this.privateGetFills(this.extend(request, params));
|
|
1807
|
-
//
|
|
1808
|
-
// {
|
|
1809
|
-
// "code": "200000",
|
|
1810
|
-
// "data": {
|
|
1811
|
-
// "currentPage":1,
|
|
1812
|
-
// "pageSize":1,
|
|
1813
|
-
// "totalNum":251915,
|
|
1814
|
-
// "totalPage":251915,
|
|
1815
|
-
// "items":[
|
|
1816
|
-
// {
|
|
1817
|
-
// "symbol": "BTCUSDTPERP", //Ticker symbol of the contract
|
|
1818
|
-
// "tradeId": "5ce24c1f0c19fc3c58edc47c", //Trade ID
|
|
1819
|
-
// "orderId": "5ce24c16b210233c36ee321d", // Order ID
|
|
1820
|
-
// "side": "sell", //Transaction side
|
|
1821
|
-
// "liquidity": "taker", //Liquidity- taker or maker
|
|
1822
|
-
// "price": "8302", //Filled price
|
|
1823
|
-
// "size": 10, //Filled amount
|
|
1824
|
-
// "value": "0.001204529", //Order value
|
|
1825
|
-
// "feeRate": "0.0005", //Floating fees
|
|
1826
|
-
// "fixFee": "0.00000006", //Fixed fees
|
|
1827
|
-
// "feeCurrency": "XBT", //Charging currency
|
|
1828
|
-
// "stop": "", //A mark to the stop order type
|
|
1829
|
-
// "fee": "0.0000012022", //Transaction fee
|
|
1830
|
-
// "orderType": "limit", //Order type
|
|
1831
|
-
// "tradeType": "trade", //Trade type (trade, liquidation, ADL or settlement)
|
|
1832
|
-
// "createdAt": 1558334496000, //Time the order created
|
|
1833
|
-
// "settleCurrency": "XBT", //settlement currency
|
|
1834
|
-
// "tradeTime": 1558334496000000000 //trade time in nanosecond
|
|
1835
|
-
// }
|
|
1836
|
-
// ]
|
|
1837
|
-
// }
|
|
1838
|
-
// }
|
|
1839
|
-
//
|
|
1840
|
-
const data = this.safeValue(response, 'data', {});
|
|
1841
|
-
const trades = this.safeList(data, 'items', []);
|
|
1842
|
-
return this.parseTrades(trades, market, since, limit);
|
|
1843
|
-
}
|
|
1844
|
-
/**
|
|
1845
|
-
* @method
|
|
1846
|
-
* @name poloniexfutures#setMarginMode
|
|
1847
|
-
* @description set margin mode to 'cross' or 'isolated'
|
|
1848
|
-
* @see https://api-docs.poloniex.com/futures/api/margin-mode#change-margin-mode
|
|
1849
|
-
* @param {string} marginMode "0" (isolated) or "1" (cross)
|
|
1850
|
-
* @param {string} symbol unified market symbol
|
|
1851
|
-
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
1852
|
-
* @returns {object} response from the exchange
|
|
1853
|
-
*/
|
|
1854
|
-
async setMarginMode(marginMode, symbol = undefined, params = {}) {
|
|
1855
|
-
if (symbol === undefined) {
|
|
1856
|
-
throw new ArgumentsRequired(this.id + ' setMarginMode() requires a symbol argument');
|
|
1857
|
-
}
|
|
1858
|
-
if ((marginMode !== '0') && (marginMode !== '1') && (marginMode !== 'isolated') && (marginMode !== 'cross')) {
|
|
1859
|
-
throw new ArgumentsRequired(this.id + ' setMarginMode() marginMode must be 0/isolated or 1/cross');
|
|
1860
|
-
}
|
|
1861
|
-
await this.loadMarkets();
|
|
1862
|
-
if (marginMode === 'isolated') {
|
|
1863
|
-
marginMode = '0';
|
|
1864
|
-
}
|
|
1865
|
-
if (marginMode === 'cross') {
|
|
1866
|
-
marginMode = '1';
|
|
1867
|
-
}
|
|
1868
|
-
const market = this.market(symbol);
|
|
1869
|
-
const request = {
|
|
1870
|
-
'symbol': market['id'],
|
|
1871
|
-
'marginType': this.parseToInt(marginMode),
|
|
1872
|
-
};
|
|
1873
|
-
return await this.privatePostMarginTypeChange(request);
|
|
1874
|
-
}
|
|
1875
|
-
sign(path, api = 'public', method = 'GET', params = {}, headers = undefined, body = undefined) {
|
|
1876
|
-
let url = this.urls['api'][api];
|
|
1877
|
-
const versions = this.safeValue(this.options, 'versions', {});
|
|
1878
|
-
const apiVersions = this.safeValue(versions, api, {});
|
|
1879
|
-
const methodVersions = this.safeValue(apiVersions, method, {});
|
|
1880
|
-
const defaultVersion = this.safeString(methodVersions, path, this.version);
|
|
1881
|
-
const version = this.safeString(params, 'version', defaultVersion);
|
|
1882
|
-
const tail = '/api/' + version + '/' + this.implodeParams(path, params);
|
|
1883
|
-
url += tail;
|
|
1884
|
-
const query = this.omit(params, this.extractParams(path));
|
|
1885
|
-
const queryLength = Object.keys(query).length;
|
|
1886
|
-
if (api === 'public') {
|
|
1887
|
-
if (queryLength) {
|
|
1888
|
-
url += '?' + this.urlencode(query);
|
|
1889
|
-
}
|
|
1890
|
-
}
|
|
1891
|
-
else {
|
|
1892
|
-
this.checkRequiredCredentials();
|
|
1893
|
-
let endpoint = '/api/v1/' + this.implodeParams(path, params);
|
|
1894
|
-
const bodyEncoded = this.urlencode(query);
|
|
1895
|
-
if (method !== 'GET' && method !== 'HEAD') {
|
|
1896
|
-
body = query;
|
|
1897
|
-
}
|
|
1898
|
-
else {
|
|
1899
|
-
if (queryLength && bodyEncoded !== '') {
|
|
1900
|
-
url += '?' + bodyEncoded;
|
|
1901
|
-
endpoint += '?' + bodyEncoded;
|
|
1902
|
-
}
|
|
1903
|
-
}
|
|
1904
|
-
const now = this.milliseconds().toString();
|
|
1905
|
-
let endpart = '';
|
|
1906
|
-
if (body !== undefined) {
|
|
1907
|
-
body = this.json(query);
|
|
1908
|
-
endpart = body;
|
|
1909
|
-
}
|
|
1910
|
-
const payload = now + method + endpoint + endpart;
|
|
1911
|
-
const signature = this.hmac(this.encode(payload), this.encode(this.secret), sha256, 'base64');
|
|
1912
|
-
headers = {
|
|
1913
|
-
'PF-API-SIGN': signature,
|
|
1914
|
-
'PF-API-TIMESTAMP': now,
|
|
1915
|
-
'PF-API-KEY': this.apiKey,
|
|
1916
|
-
'PF-API-PASSPHRASE': this.password,
|
|
1917
|
-
};
|
|
1918
|
-
headers['Content-Type'] = 'application/json';
|
|
1919
|
-
}
|
|
1920
|
-
return { 'url': url, 'method': method, 'body': body, 'headers': headers };
|
|
1921
|
-
}
|
|
1922
|
-
handleErrors(code, reason, url, method, headers, body, response, requestHeaders, requestBody) {
|
|
1923
|
-
if (!response) {
|
|
1924
|
-
this.throwBroadlyMatchedException(this.exceptions['broad'], body, body);
|
|
1925
|
-
return undefined;
|
|
1926
|
-
}
|
|
1927
|
-
//
|
|
1928
|
-
// bad
|
|
1929
|
-
// { "code": "400100", "msg": "validation.createOrder.clientOidIsRequired" }
|
|
1930
|
-
// good
|
|
1931
|
-
// { code: "200000", data: { ... }}
|
|
1932
|
-
//
|
|
1933
|
-
const errorCode = this.safeString(response, 'code');
|
|
1934
|
-
const message = this.safeString(response, 'msg', '');
|
|
1935
|
-
const feedback = this.id + ' ' + message;
|
|
1936
|
-
this.throwExactlyMatchedException(this.exceptions['exact'], message, feedback);
|
|
1937
|
-
this.throwExactlyMatchedException(this.exceptions['exact'], errorCode, feedback);
|
|
1938
|
-
this.throwBroadlyMatchedException(this.exceptions['broad'], body, feedback);
|
|
1939
|
-
return undefined;
|
|
1940
|
-
}
|
|
1941
|
-
}
|