ccxt 4.2.90 → 4.2.91
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/CHANGELOG.md +44 -16
- package/README.md +3 -3
- package/dist/ccxt.browser.js +339 -161
- package/dist/ccxt.browser.min.js +2 -2
- package/dist/cjs/ccxt.js +1 -1
- package/dist/cjs/src/base/Exchange.js +1 -9
- package/dist/cjs/src/coinbase.js +3 -1
- package/dist/cjs/src/gemini.js +2 -1
- package/dist/cjs/src/kraken.js +11 -9
- package/dist/cjs/src/okx.js +30 -30
- package/dist/cjs/src/pro/bitmex.js +39 -18
- package/dist/cjs/src/pro/kucoin.js +91 -0
- package/dist/cjs/src/pro/kucoinfutures.js +151 -82
- package/js/ccxt.d.ts +1 -1
- package/js/ccxt.js +1 -1
- package/js/src/base/Exchange.js +1 -9
- package/js/src/coinbase.js +3 -1
- package/js/src/gemini.js +2 -1
- package/js/src/kraken.js +11 -9
- package/js/src/okx.js +30 -30
- package/js/src/pro/bitmex.d.ts +1 -0
- package/js/src/pro/bitmex.js +39 -18
- package/js/src/pro/kucoin.d.ts +4 -0
- package/js/src/pro/kucoin.js +91 -0
- package/js/src/pro/kucoinfutures.d.ts +9 -5
- package/js/src/pro/kucoinfutures.js +151 -82
- package/package.json +1 -1
package/js/src/okx.js
CHANGED
|
@@ -1222,7 +1222,7 @@ export default class okx extends Exchange {
|
|
|
1222
1222
|
// ]
|
|
1223
1223
|
// }
|
|
1224
1224
|
//
|
|
1225
|
-
const data = this.
|
|
1225
|
+
const data = this.safeList(response, 'data', []);
|
|
1226
1226
|
const dataLength = data.length;
|
|
1227
1227
|
const update = {
|
|
1228
1228
|
'updated': undefined,
|
|
@@ -1270,8 +1270,8 @@ export default class okx extends Exchange {
|
|
|
1270
1270
|
// "msg": ""
|
|
1271
1271
|
// }
|
|
1272
1272
|
//
|
|
1273
|
-
const data = this.
|
|
1274
|
-
const first = this.
|
|
1273
|
+
const data = this.safeList(response, 'data', []);
|
|
1274
|
+
const first = this.safeDict(data, 0, {});
|
|
1275
1275
|
return this.safeInteger(first, 'ts');
|
|
1276
1276
|
}
|
|
1277
1277
|
async fetchAccounts(params = {}) {
|
|
@@ -1303,7 +1303,7 @@ export default class okx extends Exchange {
|
|
|
1303
1303
|
// "msg": ""
|
|
1304
1304
|
// }
|
|
1305
1305
|
//
|
|
1306
|
-
const data = this.
|
|
1306
|
+
const data = this.safeList(response, 'data', []);
|
|
1307
1307
|
const result = [];
|
|
1308
1308
|
for (let i = 0; i < data.length; i++) {
|
|
1309
1309
|
const account = data[i];
|
|
@@ -1328,7 +1328,7 @@ export default class okx extends Exchange {
|
|
|
1328
1328
|
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
1329
1329
|
* @returns {object[]} an array of objects representing market data
|
|
1330
1330
|
*/
|
|
1331
|
-
const types = this.
|
|
1331
|
+
const types = this.safeList(this.options, 'fetchMarkets', []);
|
|
1332
1332
|
let promises = [];
|
|
1333
1333
|
let result = [];
|
|
1334
1334
|
for (let i = 0; i < types.length; i++) {
|
|
@@ -1432,7 +1432,7 @@ export default class okx extends Exchange {
|
|
|
1432
1432
|
}
|
|
1433
1433
|
}
|
|
1434
1434
|
const tickSize = this.safeString(market, 'tickSz');
|
|
1435
|
-
const fees = this.
|
|
1435
|
+
const fees = this.safeDict2(this.fees, type, 'trading', {});
|
|
1436
1436
|
let maxLeverage = this.safeString(market, 'lever', '1');
|
|
1437
1437
|
maxLeverage = Precise.stringMax(maxLeverage, '1');
|
|
1438
1438
|
const maxSpotCost = this.safeNumber(market, 'maxMktSz');
|
|
@@ -1491,7 +1491,7 @@ export default class okx extends Exchange {
|
|
|
1491
1491
|
'instType': this.convertToInstrumentType(type),
|
|
1492
1492
|
};
|
|
1493
1493
|
if (type === 'option') {
|
|
1494
|
-
const optionsUnderlying = this.
|
|
1494
|
+
const optionsUnderlying = this.safeList(this.options, 'defaultUnderlying', ['BTC-USD', 'ETH-USD']);
|
|
1495
1495
|
const promises = [];
|
|
1496
1496
|
for (let i = 0; i < optionsUnderlying.length; i++) {
|
|
1497
1497
|
const underlying = optionsUnderlying[i];
|
|
@@ -1501,8 +1501,8 @@ export default class okx extends Exchange {
|
|
|
1501
1501
|
const promisesResult = await Promise.all(promises);
|
|
1502
1502
|
let markets = [];
|
|
1503
1503
|
for (let i = 0; i < promisesResult.length; i++) {
|
|
1504
|
-
const res = this.
|
|
1505
|
-
const options = this.
|
|
1504
|
+
const res = this.safeDict(promisesResult, i, {});
|
|
1505
|
+
const options = this.safeList(res, 'data', []);
|
|
1506
1506
|
markets = this.arrayConcat(markets, options);
|
|
1507
1507
|
}
|
|
1508
1508
|
return this.parseMarkets(markets);
|
|
@@ -1541,7 +1541,7 @@ export default class okx extends Exchange {
|
|
|
1541
1541
|
// "msg": ""
|
|
1542
1542
|
// }
|
|
1543
1543
|
//
|
|
1544
|
-
const dataResponse = this.
|
|
1544
|
+
const dataResponse = this.safeList(response, 'data', []);
|
|
1545
1545
|
return this.parseMarkets(dataResponse);
|
|
1546
1546
|
}
|
|
1547
1547
|
safeNetwork(networkId) {
|
|
@@ -1618,7 +1618,7 @@ export default class okx extends Exchange {
|
|
|
1618
1618
|
// "msg": ""
|
|
1619
1619
|
// }
|
|
1620
1620
|
//
|
|
1621
|
-
const data = this.
|
|
1621
|
+
const data = this.safeList(response, 'data', []);
|
|
1622
1622
|
const result = {};
|
|
1623
1623
|
const dataByCurrencyId = this.groupBy(data, 'ccy');
|
|
1624
1624
|
const currencyIds = Object.keys(dataByCurrencyId);
|
|
@@ -1634,11 +1634,11 @@ export default class okx extends Exchange {
|
|
|
1634
1634
|
let maxPrecision = undefined;
|
|
1635
1635
|
for (let j = 0; j < chains.length; j++) {
|
|
1636
1636
|
const chain = chains[j];
|
|
1637
|
-
const canDeposit = this.
|
|
1637
|
+
const canDeposit = this.safeBool(chain, 'canDep');
|
|
1638
1638
|
depositEnabled = (canDeposit) ? canDeposit : depositEnabled;
|
|
1639
|
-
const canWithdraw = this.
|
|
1639
|
+
const canWithdraw = this.safeBool(chain, 'canWd');
|
|
1640
1640
|
withdrawEnabled = (canWithdraw) ? canWithdraw : withdrawEnabled;
|
|
1641
|
-
const canInternal = this.
|
|
1641
|
+
const canInternal = this.safeBool(chain, 'canInternal');
|
|
1642
1642
|
const active = (canDeposit && canWithdraw && canInternal) ? true : false;
|
|
1643
1643
|
currencyActive = (active) ? active : currencyActive;
|
|
1644
1644
|
const networkId = this.safeString(chain, 'chain');
|
|
@@ -1671,7 +1671,7 @@ export default class okx extends Exchange {
|
|
|
1671
1671
|
};
|
|
1672
1672
|
}
|
|
1673
1673
|
}
|
|
1674
|
-
const firstChain = this.
|
|
1674
|
+
const firstChain = this.safeDict(chains, 0, {});
|
|
1675
1675
|
result[code] = {
|
|
1676
1676
|
'info': undefined,
|
|
1677
1677
|
'code': code,
|
|
@@ -1747,8 +1747,8 @@ export default class okx extends Exchange {
|
|
|
1747
1747
|
// ]
|
|
1748
1748
|
// }
|
|
1749
1749
|
//
|
|
1750
|
-
const data = this.
|
|
1751
|
-
const first = this.
|
|
1750
|
+
const data = this.safeList(response, 'data', []);
|
|
1751
|
+
const first = this.safeDict(data, 0, {});
|
|
1752
1752
|
const timestamp = this.safeInteger(first, 'ts');
|
|
1753
1753
|
return this.parseOrderBook(first, symbol, timestamp);
|
|
1754
1754
|
}
|
|
@@ -1849,7 +1849,7 @@ export default class okx extends Exchange {
|
|
|
1849
1849
|
// ]
|
|
1850
1850
|
// }
|
|
1851
1851
|
//
|
|
1852
|
-
const data = this.
|
|
1852
|
+
const data = this.safeList(response, 'data', []);
|
|
1853
1853
|
const first = this.safeDict(data, 0, {});
|
|
1854
1854
|
return this.parseTicker(first, market);
|
|
1855
1855
|
}
|
|
@@ -1872,7 +1872,7 @@ export default class okx extends Exchange {
|
|
|
1872
1872
|
'instType': this.convertToInstrumentType(marketType),
|
|
1873
1873
|
};
|
|
1874
1874
|
if (marketType === 'option') {
|
|
1875
|
-
const defaultUnderlying = this.
|
|
1875
|
+
const defaultUnderlying = this.safeString(this.options, 'defaultUnderlying', 'BTC-USD');
|
|
1876
1876
|
const currencyId = this.safeString2(params, 'uly', 'marketId', defaultUnderlying);
|
|
1877
1877
|
if (currencyId === undefined) {
|
|
1878
1878
|
throw new ArgumentsRequired(this.id + ' fetchTickers() requires an underlying uly or marketId parameter for options markets');
|
|
@@ -2138,7 +2138,7 @@ export default class okx extends Exchange {
|
|
|
2138
2138
|
}
|
|
2139
2139
|
const price = this.safeString(params, 'price');
|
|
2140
2140
|
params = this.omit(params, 'price');
|
|
2141
|
-
const options = this.
|
|
2141
|
+
const options = this.safeDict(this.options, 'fetchOHLCV', {});
|
|
2142
2142
|
const timezone = this.safeString(options, 'timezone', 'UTC');
|
|
2143
2143
|
if (limit === undefined) {
|
|
2144
2144
|
limit = 100; // default 100, max 100
|
|
@@ -2271,7 +2271,7 @@ export default class okx extends Exchange {
|
|
|
2271
2271
|
// }
|
|
2272
2272
|
//
|
|
2273
2273
|
const rates = [];
|
|
2274
|
-
const data = this.
|
|
2274
|
+
const data = this.safeList(response, 'data', []);
|
|
2275
2275
|
for (let i = 0; i < data.length; i++) {
|
|
2276
2276
|
const rate = data[i];
|
|
2277
2277
|
const timestamp = this.safeInteger(rate, 'fundingTime');
|
|
@@ -2296,10 +2296,10 @@ export default class okx extends Exchange {
|
|
|
2296
2296
|
}
|
|
2297
2297
|
parseTradingBalance(response) {
|
|
2298
2298
|
const result = { 'info': response };
|
|
2299
|
-
const data = this.
|
|
2300
|
-
const first = this.
|
|
2299
|
+
const data = this.safeList(response, 'data', []);
|
|
2300
|
+
const first = this.safeDict(data, 0, {});
|
|
2301
2301
|
const timestamp = this.safeInteger(first, 'uTime');
|
|
2302
|
-
const details = this.
|
|
2302
|
+
const details = this.safeList(first, 'details', []);
|
|
2303
2303
|
for (let i = 0; i < details.length; i++) {
|
|
2304
2304
|
const balance = details[i];
|
|
2305
2305
|
const currencyId = this.safeString(balance, 'ccy');
|
|
@@ -2324,7 +2324,7 @@ export default class okx extends Exchange {
|
|
|
2324
2324
|
}
|
|
2325
2325
|
parseFundingBalance(response) {
|
|
2326
2326
|
const result = { 'info': response };
|
|
2327
|
-
const data = this.
|
|
2327
|
+
const data = this.safeList(response, 'data', []);
|
|
2328
2328
|
for (let i = 0; i < data.length; i++) {
|
|
2329
2329
|
const balance = data[i];
|
|
2330
2330
|
const currencyId = this.safeString(balance, 'ccy');
|
|
@@ -2408,8 +2408,8 @@ export default class okx extends Exchange {
|
|
|
2408
2408
|
// "msg": ""
|
|
2409
2409
|
// }
|
|
2410
2410
|
//
|
|
2411
|
-
const data = this.
|
|
2412
|
-
const first = this.
|
|
2411
|
+
const data = this.safeList(response, 'data', []);
|
|
2412
|
+
const first = this.safeDict(data, 0, {});
|
|
2413
2413
|
return this.parseTradingFee(first, market);
|
|
2414
2414
|
}
|
|
2415
2415
|
async fetchBalance(params = {}) {
|
|
@@ -2897,8 +2897,8 @@ export default class okx extends Exchange {
|
|
|
2897
2897
|
else {
|
|
2898
2898
|
response = await this.privatePostTradeBatchOrders(request);
|
|
2899
2899
|
}
|
|
2900
|
-
const data = this.
|
|
2901
|
-
const first = this.
|
|
2900
|
+
const data = this.safeList(response, 'data', []);
|
|
2901
|
+
const first = this.safeDict(data, 0, {});
|
|
2902
2902
|
const order = this.parseOrder(first, market);
|
|
2903
2903
|
order['type'] = type;
|
|
2904
2904
|
order['side'] = side;
|
|
@@ -4409,7 +4409,7 @@ export default class okx extends Exchange {
|
|
|
4409
4409
|
// ]
|
|
4410
4410
|
// }
|
|
4411
4411
|
//
|
|
4412
|
-
const data = this.
|
|
4412
|
+
const data = this.safeList(response, 'data', []);
|
|
4413
4413
|
return this.parseLedger(data, currency, since, limit);
|
|
4414
4414
|
}
|
|
4415
4415
|
parseLedgerEntryType(type) {
|
package/js/src/pro/bitmex.d.ts
CHANGED
|
@@ -20,6 +20,7 @@ export default class bitmex extends bitmexRest {
|
|
|
20
20
|
handleMyTrades(client: Client, message: any): void;
|
|
21
21
|
watchOrderBook(symbol: string, limit?: Int, params?: {}): Promise<OrderBook>;
|
|
22
22
|
watchOrderBookForSymbols(symbols: string[], limit?: Int, params?: {}): Promise<OrderBook>;
|
|
23
|
+
watchTradesForSymbols(symbols: string[], since?: Int, limit?: Int, params?: {}): Promise<Trade[]>;
|
|
23
24
|
watchOHLCV(symbol: string, timeframe?: string, since?: Int, limit?: Int, params?: {}): Promise<OHLCV[]>;
|
|
24
25
|
handleOHLCV(client: Client, message: any): void;
|
|
25
26
|
watchHeartbeat(params?: {}): Promise<any>;
|
package/js/src/pro/bitmex.js
CHANGED
|
@@ -546,8 +546,8 @@ export default class bitmex extends bitmexRest {
|
|
|
546
546
|
for (let i = 0; i < marketIds.length; i++) {
|
|
547
547
|
const marketId = marketIds[i];
|
|
548
548
|
const market = this.safeMarket(marketId);
|
|
549
|
-
const messageHash = table + ':' + marketId;
|
|
550
549
|
const symbol = market['symbol'];
|
|
550
|
+
const messageHash = table + ':' + symbol;
|
|
551
551
|
const trades = this.parseTrades(dataByMarketIds[marketId], market);
|
|
552
552
|
let stored = this.safeValue(this.trades, symbol);
|
|
553
553
|
if (stored === undefined) {
|
|
@@ -572,23 +572,7 @@ export default class bitmex extends bitmexRest {
|
|
|
572
572
|
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
573
573
|
* @returns {object[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=public-trades}
|
|
574
574
|
*/
|
|
575
|
-
await this.
|
|
576
|
-
const market = this.market(symbol);
|
|
577
|
-
symbol = market['symbol'];
|
|
578
|
-
const table = 'trade';
|
|
579
|
-
const messageHash = table + ':' + market['id'];
|
|
580
|
-
const url = this.urls['api']['ws'];
|
|
581
|
-
const request = {
|
|
582
|
-
'op': 'subscribe',
|
|
583
|
-
'args': [
|
|
584
|
-
messageHash,
|
|
585
|
-
],
|
|
586
|
-
};
|
|
587
|
-
const trades = await this.watch(url, messageHash, this.extend(request, params), messageHash);
|
|
588
|
-
if (this.newUpdates) {
|
|
589
|
-
limit = trades.getLimit(symbol, limit);
|
|
590
|
-
}
|
|
591
|
-
return this.filterBySinceLimit(trades, since, limit, 'timestamp', true);
|
|
575
|
+
return await this.watchTradesForSymbols([symbol], since, limit, params);
|
|
592
576
|
}
|
|
593
577
|
async authenticate(params = {}) {
|
|
594
578
|
const url = this.urls['api']['ws'];
|
|
@@ -1221,6 +1205,43 @@ export default class bitmex extends bitmexRest {
|
|
|
1221
1205
|
const orderbook = await this.watchMultiple(url, messageHashes, this.deepExtend(request, params), topics);
|
|
1222
1206
|
return orderbook.limit();
|
|
1223
1207
|
}
|
|
1208
|
+
async watchTradesForSymbols(symbols, since = undefined, limit = undefined, params = {}) {
|
|
1209
|
+
/**
|
|
1210
|
+
* @method
|
|
1211
|
+
* @name bitmex#watchTradesForSymbols
|
|
1212
|
+
* @description get the list of most recent trades for a list of symbols
|
|
1213
|
+
* @param {string[]} symbols unified symbol of the market to fetch trades for
|
|
1214
|
+
* @param {int} [since] timestamp in ms of the earliest trade to fetch
|
|
1215
|
+
* @param {int} [limit] the maximum amount of trades to fetch
|
|
1216
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
1217
|
+
* @returns {object[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=public-trades}
|
|
1218
|
+
*/
|
|
1219
|
+
await this.loadMarkets();
|
|
1220
|
+
symbols = this.marketSymbols(symbols, undefined, false);
|
|
1221
|
+
const table = 'trade';
|
|
1222
|
+
const topics = [];
|
|
1223
|
+
const messageHashes = [];
|
|
1224
|
+
for (let i = 0; i < symbols.length; i++) {
|
|
1225
|
+
const symbol = symbols[i];
|
|
1226
|
+
const market = this.market(symbol);
|
|
1227
|
+
const topic = table + ':' + market['id'];
|
|
1228
|
+
topics.push(topic);
|
|
1229
|
+
const messageHash = table + ':' + symbol;
|
|
1230
|
+
messageHashes.push(messageHash);
|
|
1231
|
+
}
|
|
1232
|
+
const url = this.urls['api']['ws'];
|
|
1233
|
+
const request = {
|
|
1234
|
+
'op': 'subscribe',
|
|
1235
|
+
'args': topics,
|
|
1236
|
+
};
|
|
1237
|
+
const trades = await this.watchMultiple(url, messageHashes, this.deepExtend(request, params), topics);
|
|
1238
|
+
if (this.newUpdates) {
|
|
1239
|
+
const first = this.safeValue(trades, 0);
|
|
1240
|
+
const tradeSymbol = this.safeString(first, 'symbol');
|
|
1241
|
+
limit = trades.getLimit(tradeSymbol, limit);
|
|
1242
|
+
}
|
|
1243
|
+
return this.filterBySinceLimit(trades, since, limit, 'timestamp', true);
|
|
1244
|
+
}
|
|
1224
1245
|
async watchOHLCV(symbol, timeframe = '1m', since = undefined, limit = undefined, params = {}) {
|
|
1225
1246
|
/**
|
|
1226
1247
|
* @method
|
package/js/src/pro/kucoin.d.ts
CHANGED
|
@@ -11,6 +11,10 @@ export default class kucoin extends kucoinRest {
|
|
|
11
11
|
watchTicker(symbol: string, params?: {}): Promise<Ticker>;
|
|
12
12
|
watchTickers(symbols?: Strings, params?: {}): Promise<Tickers>;
|
|
13
13
|
handleTicker(client: Client, message: any): void;
|
|
14
|
+
watchBidsAsks(symbols?: Strings, params?: {}): Promise<Tickers>;
|
|
15
|
+
watchMultiHelper(methodName: any, channelName: string, symbols?: Strings, params?: {}): Promise<any>;
|
|
16
|
+
handleBidAsk(client: Client, message: any): void;
|
|
17
|
+
parseWsBidAsk(ticker: any, market?: any): Ticker;
|
|
14
18
|
watchOHLCV(symbol: string, timeframe?: string, since?: Int, limit?: Int, params?: {}): Promise<OHLCV[]>;
|
|
15
19
|
handleOHLCV(client: Client, message: any): void;
|
|
16
20
|
watchTrades(symbol: string, since?: Int, limit?: Int, params?: {}): Promise<Trade[]>;
|
package/js/src/pro/kucoin.js
CHANGED
|
@@ -21,6 +21,7 @@ export default class kucoin extends kucoinRest {
|
|
|
21
21
|
'cancelOrderWs': false,
|
|
22
22
|
'cancelOrdersWs': false,
|
|
23
23
|
'cancelAllOrdersWs': false,
|
|
24
|
+
'watchBidsAsks': true,
|
|
24
25
|
'watchOrderBook': true,
|
|
25
26
|
'watchOrders': true,
|
|
26
27
|
'watchMyTrades': true,
|
|
@@ -288,6 +289,92 @@ export default class kucoin extends kucoinRest {
|
|
|
288
289
|
}
|
|
289
290
|
}
|
|
290
291
|
}
|
|
292
|
+
async watchBidsAsks(symbols = undefined, params = {}) {
|
|
293
|
+
/**
|
|
294
|
+
* @method
|
|
295
|
+
* @name kucoin#watchBidsAsks
|
|
296
|
+
* @see https://www.kucoin.com/docs/websocket/spot-trading/public-channels/level1-bbo-market-data
|
|
297
|
+
* @description watches best bid & ask for symbols
|
|
298
|
+
* @param {string[]} symbols unified symbol of the market to fetch the ticker for
|
|
299
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
300
|
+
* @returns {object} a [ticker structure]{@link https://docs.ccxt.com/#/?id=ticker-structure}
|
|
301
|
+
*/
|
|
302
|
+
const ticker = await this.watchMultiHelper('watchBidsAsks', '/spotMarket/level1:', symbols, params);
|
|
303
|
+
if (this.newUpdates) {
|
|
304
|
+
const tickers = {};
|
|
305
|
+
tickers[ticker['symbol']] = ticker;
|
|
306
|
+
return tickers;
|
|
307
|
+
}
|
|
308
|
+
return this.filterByArray(this.bidsasks, 'symbol', symbols);
|
|
309
|
+
}
|
|
310
|
+
async watchMultiHelper(methodName, channelName, symbols = undefined, params = {}) {
|
|
311
|
+
await this.loadMarkets();
|
|
312
|
+
symbols = this.marketSymbols(symbols, undefined, false, true, false);
|
|
313
|
+
const length = symbols.length;
|
|
314
|
+
if (length > 100) {
|
|
315
|
+
throw new ArgumentsRequired(this.id + ' ' + methodName + '() accepts a maximum of 100 symbols');
|
|
316
|
+
}
|
|
317
|
+
const messageHashes = [];
|
|
318
|
+
for (let i = 0; i < symbols.length; i++) {
|
|
319
|
+
const symbol = symbols[i];
|
|
320
|
+
const market = this.market(symbol);
|
|
321
|
+
messageHashes.push('bidask@' + market['symbol']);
|
|
322
|
+
}
|
|
323
|
+
const url = await this.negotiate(false);
|
|
324
|
+
const marketIds = this.marketIds(symbols);
|
|
325
|
+
const joined = marketIds.join(',');
|
|
326
|
+
const requestId = this.requestId().toString();
|
|
327
|
+
const request = {
|
|
328
|
+
'id': requestId,
|
|
329
|
+
'type': 'subscribe',
|
|
330
|
+
'topic': channelName + joined,
|
|
331
|
+
'response': true,
|
|
332
|
+
};
|
|
333
|
+
const message = this.extend(request, params);
|
|
334
|
+
return await this.watchMultiple(url, messageHashes, message, messageHashes);
|
|
335
|
+
}
|
|
336
|
+
handleBidAsk(client, message) {
|
|
337
|
+
//
|
|
338
|
+
// arrives one symbol dict
|
|
339
|
+
//
|
|
340
|
+
// {
|
|
341
|
+
// topic: '/spotMarket/level1:ETH-USDT',
|
|
342
|
+
// type: 'message',
|
|
343
|
+
// data: {
|
|
344
|
+
// asks: [ '3347.42', '2.0778387' ],
|
|
345
|
+
// bids: [ '3347.41', '6.0411697' ],
|
|
346
|
+
// timestamp: 1712231142085
|
|
347
|
+
// },
|
|
348
|
+
// subject: 'level1'
|
|
349
|
+
// }
|
|
350
|
+
//
|
|
351
|
+
const parsedTicker = this.parseWsBidAsk(message);
|
|
352
|
+
const symbol = parsedTicker['symbol'];
|
|
353
|
+
this.bidsasks[symbol] = parsedTicker;
|
|
354
|
+
const messageHash = 'bidask@' + symbol;
|
|
355
|
+
client.resolve(parsedTicker, messageHash);
|
|
356
|
+
}
|
|
357
|
+
parseWsBidAsk(ticker, market = undefined) {
|
|
358
|
+
const topic = this.safeString(ticker, 'topic');
|
|
359
|
+
const parts = topic.split(':');
|
|
360
|
+
const marketId = parts[1];
|
|
361
|
+
market = this.safeMarket(marketId, market);
|
|
362
|
+
const symbol = this.safeString(market, 'symbol');
|
|
363
|
+
const data = this.safeDict(ticker, 'data', {});
|
|
364
|
+
const ask = this.safeList(data, 'asks', []);
|
|
365
|
+
const bid = this.safeList(data, 'bids', []);
|
|
366
|
+
const timestamp = this.safeInteger(data, 'timestamp');
|
|
367
|
+
return this.safeTicker({
|
|
368
|
+
'symbol': symbol,
|
|
369
|
+
'timestamp': timestamp,
|
|
370
|
+
'datetime': this.iso8601(timestamp),
|
|
371
|
+
'ask': this.safeNumber(ask, 0),
|
|
372
|
+
'askVolume': this.safeNumber(ask, 1),
|
|
373
|
+
'bid': this.safeNumber(bid, 0),
|
|
374
|
+
'bidVolume': this.safeNumber(bid, 1),
|
|
375
|
+
'info': ticker,
|
|
376
|
+
}, market);
|
|
377
|
+
}
|
|
291
378
|
async watchOHLCV(symbol, timeframe = '1m', since = undefined, limit = undefined, params = {}) {
|
|
292
379
|
/**
|
|
293
380
|
* @method
|
|
@@ -679,6 +766,9 @@ export default class kucoin extends kucoinRest {
|
|
|
679
766
|
// }
|
|
680
767
|
//
|
|
681
768
|
const id = this.safeString(message, 'id');
|
|
769
|
+
if (!(id in client.subscriptions)) {
|
|
770
|
+
return;
|
|
771
|
+
}
|
|
682
772
|
const subscriptionHash = this.safeString(client.subscriptions, id);
|
|
683
773
|
const subscription = this.safeValue(client.subscriptions, subscriptionHash);
|
|
684
774
|
delete client.subscriptions[id];
|
|
@@ -1052,6 +1142,7 @@ export default class kucoin extends kucoinRest {
|
|
|
1052
1142
|
}
|
|
1053
1143
|
const subject = this.safeString(message, 'subject');
|
|
1054
1144
|
const methods = {
|
|
1145
|
+
'level1': this.handleBidAsk,
|
|
1055
1146
|
'level2': this.handleOrderBook,
|
|
1056
1147
|
'trade.l2update': this.handleOrderBook,
|
|
1057
1148
|
'trade.ticker': this.handleTicker,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import kucoinfuturesRest from '../kucoinfutures.js';
|
|
2
|
-
import type { Int, Str, OrderBook, Order, Trade, Ticker, Balances, Position } from '../base/types.js';
|
|
2
|
+
import type { Int, Str, OrderBook, Order, Trade, Ticker, Balances, Position, Strings, Tickers } from '../base/types.js';
|
|
3
3
|
import Client from '../base/ws/Client.js';
|
|
4
4
|
export default class kucoinfutures extends kucoinfuturesRest {
|
|
5
5
|
describe(): any;
|
|
@@ -7,9 +7,14 @@ export default class kucoinfutures extends kucoinfuturesRest {
|
|
|
7
7
|
negotiateHelper(privateChannel: any, params?: {}): Promise<string>;
|
|
8
8
|
requestId(): any;
|
|
9
9
|
subscribe(url: any, messageHash: any, subscriptionHash: any, subscription: any, params?: {}): Promise<any>;
|
|
10
|
-
subscribeMultiple(url: any, messageHashes: any, topic: any, subscriptionHashes: any,
|
|
10
|
+
subscribeMultiple(url: any, messageHashes: any, topic: any, subscriptionHashes: any, subscriptionArgs: any, params?: {}): Promise<any>;
|
|
11
11
|
watchTicker(symbol: string, params?: {}): Promise<Ticker>;
|
|
12
|
-
|
|
12
|
+
watchTickers(symbols?: Strings, params?: {}): Promise<Tickers>;
|
|
13
|
+
handleTicker(client: Client, message: any): void;
|
|
14
|
+
watchBidsAsks(symbols?: Strings, params?: {}): Promise<Tickers>;
|
|
15
|
+
watchMultiRequest(methodName: any, channelName: string, symbols?: Strings, params?: {}): Promise<any>;
|
|
16
|
+
handleBidAsk(client: Client, message: any): void;
|
|
17
|
+
parseWsBidAsk(ticker: any, market?: any): Ticker;
|
|
13
18
|
watchPosition(symbol?: Str, params?: {}): Promise<Position>;
|
|
14
19
|
getCurrentPosition(symbol: any): any;
|
|
15
20
|
setPositionCache(client: Client, symbol: string): void;
|
|
@@ -24,8 +29,6 @@ export default class kucoinfutures extends kucoinfuturesRest {
|
|
|
24
29
|
handleDeltas(bookside: any, deltas: any): void;
|
|
25
30
|
handleOrderBook(client: Client, message: any): void;
|
|
26
31
|
getCacheIndex(orderbook: any, cache: any): any;
|
|
27
|
-
handleOrderBookSubscription(client: Client, message: any, subscription: any): void;
|
|
28
|
-
handleSubscriptionStatus(client: Client, message: any): void;
|
|
29
32
|
handleSystemStatus(client: Client, message: any): any;
|
|
30
33
|
watchOrders(symbol?: Str, since?: Int, limit?: Int, params?: {}): Promise<Order[]>;
|
|
31
34
|
parseWsOrderStatus(status: any): string;
|
|
@@ -36,6 +39,7 @@ export default class kucoinfutures extends kucoinfuturesRest {
|
|
|
36
39
|
handleBalanceSubscription(client: Client, message: any, subscription: any): void;
|
|
37
40
|
fetchBalanceSnapshot(client: any, message: any): Promise<void>;
|
|
38
41
|
handleSubject(client: Client, message: any): void;
|
|
42
|
+
getMessageHash(elementName: string, symbol?: Str): string;
|
|
39
43
|
ping(client: any): {
|
|
40
44
|
id: any;
|
|
41
45
|
type: string;
|