ccxt 4.1.62 → 4.1.63
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 +3 -3
- package/dist/ccxt.browser.js +466 -81
- package/dist/ccxt.browser.min.js +2 -2
- package/dist/cjs/ccxt.js +1 -1
- package/dist/cjs/src/alpaca.js +209 -48
- package/dist/cjs/src/binance.js +3 -3
- package/dist/cjs/src/kucoinfutures.js +34 -13
- package/dist/cjs/src/pro/poloniex.js +205 -2
- package/js/ccxt.d.ts +1 -1
- package/js/ccxt.js +1 -1
- package/js/src/abstract/binance.d.ts +3 -3
- package/js/src/abstract/binancecoinm.d.ts +3 -3
- package/js/src/abstract/binanceus.d.ts +3 -3
- package/js/src/abstract/binanceusdm.d.ts +3 -3
- package/js/src/alpaca.d.ts +4 -0
- package/js/src/alpaca.js +209 -48
- package/js/src/binance.js +3 -3
- package/js/src/kucoinfutures.js +34 -13
- package/js/src/pro/poloniex.d.ts +8 -1
- package/js/src/pro/poloniex.js +206 -3
- package/package.json +1 -1
package/js/src/pro/poloniex.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
// ---------------------------------------------------------------------------
|
|
8
8
|
import poloniexRest from '../poloniex.js';
|
|
9
|
-
import { BadRequest, AuthenticationError, ExchangeError } from '../base/errors.js';
|
|
9
|
+
import { BadRequest, AuthenticationError, ExchangeError, ArgumentsRequired } from '../base/errors.js';
|
|
10
10
|
import { ArrayCache, ArrayCacheByTimestamp, ArrayCacheBySymbolById } from '../base/ws/Cache.js';
|
|
11
11
|
import { Precise } from '../base/Precise.js';
|
|
12
12
|
import { sha256 } from '../static_dependencies/noble-hashes/sha256.js';
|
|
@@ -25,6 +25,15 @@ export default class poloniex extends poloniexRest {
|
|
|
25
25
|
'watchStatus': false,
|
|
26
26
|
'watchOrders': true,
|
|
27
27
|
'watchMyTrades': true,
|
|
28
|
+
'createOrderWs': true,
|
|
29
|
+
'editOrderWs': false,
|
|
30
|
+
'fetchOpenOrdersWs': false,
|
|
31
|
+
'fetchOrderWs': false,
|
|
32
|
+
'cancelOrderWs': true,
|
|
33
|
+
'cancelOrdersWs': true,
|
|
34
|
+
'cancelAllOrdersWs': true,
|
|
35
|
+
'fetchTradesWs': false,
|
|
36
|
+
'fetchBalanceWs': false,
|
|
28
37
|
},
|
|
29
38
|
'urls': {
|
|
30
39
|
'api': {
|
|
@@ -35,6 +44,7 @@ export default class poloniex extends poloniexRest {
|
|
|
35
44
|
},
|
|
36
45
|
},
|
|
37
46
|
'options': {
|
|
47
|
+
'createMarketBuyOrderRequiresPrice': true,
|
|
38
48
|
'tradesLimit': 1000,
|
|
39
49
|
'ordersLimit': 1000,
|
|
40
50
|
'OHLCVLimit': 1000,
|
|
@@ -154,6 +164,164 @@ export default class poloniex extends poloniexRest {
|
|
|
154
164
|
const request = this.extend(subscribe, params);
|
|
155
165
|
return await this.watch(url, messageHash, request, messageHash);
|
|
156
166
|
}
|
|
167
|
+
async tradeRequest(name, params = {}) {
|
|
168
|
+
/**
|
|
169
|
+
* @ignore
|
|
170
|
+
* @method
|
|
171
|
+
* @description Connects to a websocket channel
|
|
172
|
+
* @param {string} name name of the channel
|
|
173
|
+
* @param {string[]|undefined} symbols CCXT market symbols
|
|
174
|
+
* @param {object} [params] extra parameters specific to the poloniex api
|
|
175
|
+
* @returns {object} data from the websocket stream
|
|
176
|
+
*/
|
|
177
|
+
const url = this.urls['api']['ws']['private'];
|
|
178
|
+
const messageHash = this.nonce();
|
|
179
|
+
const subscribe = {
|
|
180
|
+
'id': messageHash,
|
|
181
|
+
'event': name,
|
|
182
|
+
'params': params,
|
|
183
|
+
};
|
|
184
|
+
return await this.watch(url, messageHash, subscribe, messageHash);
|
|
185
|
+
}
|
|
186
|
+
async createOrderWs(symbol, type, side, amount, price = undefined, params = {}) {
|
|
187
|
+
/**
|
|
188
|
+
* @method
|
|
189
|
+
* @name poloniex#createOrderWs
|
|
190
|
+
* @see https://docs.poloniex.com/#authenticated-channels-trade-requests-create-order
|
|
191
|
+
* @description create a trade order
|
|
192
|
+
* @param {string} symbol unified symbol of the market to create an order in
|
|
193
|
+
* @param {string} type 'market' or 'limit'
|
|
194
|
+
* @param {string} side 'buy' or 'sell'
|
|
195
|
+
* @param {float} amount how much of currency you want to trade in units of base currency
|
|
196
|
+
* @param {float} [price] the price at which the order is to be fullfilled, in units of the quote currency, ignored in market orders
|
|
197
|
+
* @param {object} [params] extra parameters specific to the poloniex api endpoint
|
|
198
|
+
* @param {string} [params.timeInForce] GTC (default), IOC, FOK
|
|
199
|
+
* @param {string} [params.clientOrderId] Maximum 64-character length.*
|
|
200
|
+
*
|
|
201
|
+
* EXCHANGE SPECIFIC PARAMETERS
|
|
202
|
+
* @param {string} [params.amount] quote units for the order
|
|
203
|
+
* @param {boolean} [params.allowBorrow] allow order to be placed by borrowing funds (Default: false)
|
|
204
|
+
* @param {string} [params.stpMode] self-trade prevention, defaults to expire_taker, none: enable self-trade; expire_taker: taker order will be canceled when self-trade happens
|
|
205
|
+
* @param {string} [params.slippageTolerance] used to control the maximum slippage ratio, the value range is greater than 0 and less than 1
|
|
206
|
+
* @returns {object} an [order structure]{@link https://github.com/ccxt/ccxt/wiki/Manual#order-structure}
|
|
207
|
+
*/
|
|
208
|
+
await this.loadMarkets();
|
|
209
|
+
await this.authenticate();
|
|
210
|
+
const market = this.market(symbol);
|
|
211
|
+
let uppercaseType = type.toUpperCase();
|
|
212
|
+
const uppercaseSide = side.toUpperCase();
|
|
213
|
+
const isPostOnly = this.isPostOnly(uppercaseType === 'MARKET', uppercaseType === 'LIMIT_MAKER', params);
|
|
214
|
+
if (isPostOnly) {
|
|
215
|
+
uppercaseType = 'LIMIT_MAKER';
|
|
216
|
+
}
|
|
217
|
+
const request = {
|
|
218
|
+
'symbol': market['id'],
|
|
219
|
+
'side': side.toUpperCase(),
|
|
220
|
+
'type': type.toUpperCase(),
|
|
221
|
+
};
|
|
222
|
+
if ((uppercaseType === 'MARKET') && (uppercaseSide === 'BUY')) {
|
|
223
|
+
let quoteAmount = this.safeString(params, 'amount');
|
|
224
|
+
if ((quoteAmount === undefined) && (this.options['createMarketBuyOrderRequiresPrice'])) {
|
|
225
|
+
const cost = this.safeNumber(params, 'cost');
|
|
226
|
+
params = this.omit(params, 'cost');
|
|
227
|
+
if (price === undefined && cost === undefined) {
|
|
228
|
+
throw new ArgumentsRequired(this.id + ' createOrder() requires the price argument with market buy orders to calculate total order cost (amount to spend), where cost = amount * price. Supply a price argument to createOrder() call if you want the cost to be calculated for you from price and amount, or, alternatively, add .options["createMarketBuyOrderRequiresPrice"] = false to supply the cost in the amount argument (the exchange-specific behaviour)');
|
|
229
|
+
}
|
|
230
|
+
else {
|
|
231
|
+
const amountString = this.numberToString(amount);
|
|
232
|
+
const priceString = this.numberToString(price);
|
|
233
|
+
const quote = Precise.stringMul(amountString, priceString);
|
|
234
|
+
amount = (cost !== undefined) ? cost : this.parseNumber(quote);
|
|
235
|
+
quoteAmount = this.costToPrecision(symbol, amount);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
else {
|
|
239
|
+
quoteAmount = this.costToPrecision(symbol, amount);
|
|
240
|
+
}
|
|
241
|
+
request['amount'] = this.amountToPrecision(market['symbol'], quoteAmount);
|
|
242
|
+
}
|
|
243
|
+
else {
|
|
244
|
+
request['quantity'] = this.amountToPrecision(market['symbol'], amount);
|
|
245
|
+
if (price !== undefined) {
|
|
246
|
+
request['price'] = this.priceToPrecision(symbol, price);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
return await this.tradeRequest('createOrder', this.extend(request, params));
|
|
250
|
+
}
|
|
251
|
+
async cancelOrderWs(id, symbol = undefined, params = {}) {
|
|
252
|
+
/**
|
|
253
|
+
* @method
|
|
254
|
+
* @name poloniex#cancelOrderWs
|
|
255
|
+
* @see https://docs.poloniex.com/#authenticated-channels-trade-requests-cancel-multiple-orders
|
|
256
|
+
* @description cancel multiple orders
|
|
257
|
+
* @param {string} id order id
|
|
258
|
+
* @param {string} [symbol] unified market symbol
|
|
259
|
+
* @param {object} [params] extra parameters specific to the poloniex api endpoint
|
|
260
|
+
* @param {string} [params.clientOrderId] client order id
|
|
261
|
+
* @returns {object} an list of [order structures]{@link https://github.com/ccxt/ccxt/wiki/Manual#order-structure}
|
|
262
|
+
*/
|
|
263
|
+
const clientOrderId = this.safeString(params, 'clientOrderId');
|
|
264
|
+
if (clientOrderId !== undefined) {
|
|
265
|
+
const clientOrderIds = this.safeValue(params, 'clientOrderId', []);
|
|
266
|
+
params['clientOrderIds'] = this.arrayConcat(clientOrderIds, [clientOrderId]);
|
|
267
|
+
}
|
|
268
|
+
return await this.cancelOrdersWs([id], symbol, params);
|
|
269
|
+
}
|
|
270
|
+
async cancelOrdersWs(ids, symbol = undefined, params = {}) {
|
|
271
|
+
/**
|
|
272
|
+
* @method
|
|
273
|
+
* @name poloniex#cancelOrdersWs
|
|
274
|
+
* @see https://docs.poloniex.com/#authenticated-channels-trade-requests-cancel-multiple-orders
|
|
275
|
+
* @description cancel multiple orders
|
|
276
|
+
* @param {string[]} ids order ids
|
|
277
|
+
* @param {string} symbol unified market symbol, default is undefined
|
|
278
|
+
* @param {object} [params] extra parameters specific to the poloniex api endpoint
|
|
279
|
+
* @param {string[]} [params.clientOrderIds] client order ids
|
|
280
|
+
* @returns {object} an list of [order structures]{@link https://github.com/ccxt/ccxt/wiki/Manual#order-structure}
|
|
281
|
+
*/
|
|
282
|
+
await this.loadMarkets();
|
|
283
|
+
await this.authenticate();
|
|
284
|
+
const request = {
|
|
285
|
+
'orderIds': ids,
|
|
286
|
+
};
|
|
287
|
+
return await this.tradeRequest('cancelOrders', this.extend(request, params));
|
|
288
|
+
}
|
|
289
|
+
async cancelAllOrdersWs(symbol = undefined, params = {}) {
|
|
290
|
+
/**
|
|
291
|
+
* @method
|
|
292
|
+
* @name poloniex#cancelAllOrdersWs
|
|
293
|
+
* @see https://docs.poloniex.com/#authenticated-channels-trade-requests-cancel-all-orders
|
|
294
|
+
* @description cancel all open orders of a type. Only applicable to Option in Portfolio Margin mode, and MMP privilege is required.
|
|
295
|
+
* @param {string} symbol unified market symbol, only orders in the market of this symbol are cancelled when symbol is not undefined
|
|
296
|
+
* @param {object} [params] extra parameters specific to the poloniex api endpoint
|
|
297
|
+
* @returns {object[]} a list of [order structures]{@link https://github.com/ccxt/ccxt/wiki/Manual#order-structure}
|
|
298
|
+
*/
|
|
299
|
+
await this.loadMarkets();
|
|
300
|
+
await this.authenticate();
|
|
301
|
+
return await this.tradeRequest('cancelAllOrders', params);
|
|
302
|
+
}
|
|
303
|
+
handleOrderRequest(client, message) {
|
|
304
|
+
//
|
|
305
|
+
// {
|
|
306
|
+
// "id": "1234567",
|
|
307
|
+
// "data": [{
|
|
308
|
+
// "orderId": 205343650954092544,
|
|
309
|
+
// "clientOrderId": "",
|
|
310
|
+
// "message": "",
|
|
311
|
+
// "code": 200
|
|
312
|
+
// }]
|
|
313
|
+
// }
|
|
314
|
+
//
|
|
315
|
+
const messageHash = this.safeInteger(message, 'id');
|
|
316
|
+
const data = this.safeValue(message, 'data', []);
|
|
317
|
+
const orders = [];
|
|
318
|
+
for (let i = 0; i < data.length; i++) {
|
|
319
|
+
const order = data[i];
|
|
320
|
+
const parsedOrder = this.parseWsOrder(order);
|
|
321
|
+
orders.push(parsedOrder);
|
|
322
|
+
}
|
|
323
|
+
client.resolve(orders, messageHash);
|
|
324
|
+
}
|
|
157
325
|
async watchOHLCV(symbol, timeframe = '1m', since = undefined, limit = undefined, params = {}) {
|
|
158
326
|
/**
|
|
159
327
|
* @method
|
|
@@ -960,6 +1128,9 @@ export default class poloniex extends poloniexRest {
|
|
|
960
1128
|
const symbolMessageHash = messageHash + ':' + symbol;
|
|
961
1129
|
client.resolve(trades, symbolMessageHash);
|
|
962
1130
|
}
|
|
1131
|
+
handlePong(client) {
|
|
1132
|
+
client.lastPong = this.milliseconds();
|
|
1133
|
+
}
|
|
963
1134
|
handleMessage(client, message) {
|
|
964
1135
|
if (this.handleErrorMessage(client, message)) {
|
|
965
1136
|
return;
|
|
@@ -990,11 +1161,26 @@ export default class poloniex extends poloniexRest {
|
|
|
990
1161
|
'trades': this.handleTrade,
|
|
991
1162
|
'orders': this.handleOrder,
|
|
992
1163
|
'balances': this.handleBalance,
|
|
1164
|
+
'createOrder': this.handleOrderRequest,
|
|
1165
|
+
'cancelOrder': this.handleOrderRequest,
|
|
1166
|
+
'cancelAllOrders': this.handleOrderRequest,
|
|
1167
|
+
'auth': this.handleAuthenticate,
|
|
993
1168
|
};
|
|
994
1169
|
const method = this.safeValue(methods, type);
|
|
995
1170
|
if (type === 'auth') {
|
|
996
1171
|
this.handleAuthenticate(client, message);
|
|
997
1172
|
}
|
|
1173
|
+
else if (type === undefined) {
|
|
1174
|
+
const data = this.safeValue(message, 'data');
|
|
1175
|
+
const item = this.safeValue(data, 0);
|
|
1176
|
+
const orderId = this.safeString(item, 'orderId');
|
|
1177
|
+
if (orderId === '0') {
|
|
1178
|
+
this.handleErrorMessage(client, item);
|
|
1179
|
+
}
|
|
1180
|
+
else {
|
|
1181
|
+
return this.handleOrderRequest(client, message);
|
|
1182
|
+
}
|
|
1183
|
+
}
|
|
998
1184
|
else {
|
|
999
1185
|
const data = this.safeValue(message, 'data', []);
|
|
1000
1186
|
const dataLength = data.length;
|
|
@@ -1005,9 +1191,26 @@ export default class poloniex extends poloniexRest {
|
|
|
1005
1191
|
}
|
|
1006
1192
|
handleErrorMessage(client, message) {
|
|
1007
1193
|
//
|
|
1008
|
-
//
|
|
1194
|
+
// {
|
|
1195
|
+
// message: 'Invalid channel value ["ordersss"]',
|
|
1196
|
+
// event: 'error'
|
|
1197
|
+
// }
|
|
1198
|
+
//
|
|
1199
|
+
// {
|
|
1200
|
+
// "orderId": 0,
|
|
1201
|
+
// "clientOrderId": null,
|
|
1202
|
+
// "message": "Currency trade disabled",
|
|
1203
|
+
// "code": 21352
|
|
1204
|
+
// }
|
|
1205
|
+
//
|
|
1206
|
+
// {
|
|
1207
|
+
// "event": "error",
|
|
1208
|
+
// "message": "Platform in maintenance mode"
|
|
1209
|
+
// }
|
|
1210
|
+
//
|
|
1009
1211
|
const event = this.safeString(message, 'event');
|
|
1010
|
-
|
|
1212
|
+
const orderId = this.safeString(message, 'orderId');
|
|
1213
|
+
if ((event === 'error') || (orderId === '0')) {
|
|
1011
1214
|
const error = this.safeString(message, 'message');
|
|
1012
1215
|
throw new ExchangeError(this.id + ' error: ' + this.json(error));
|
|
1013
1216
|
}
|
package/package.json
CHANGED