ccxt 4.2.29 → 4.2.30
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.js +1709 -533
- package/dist/ccxt.browser.min.js +7 -7
- package/dist/cjs/ccxt.js +3 -1
- package/dist/cjs/src/ascendex.js +5 -5
- package/dist/cjs/src/base/Exchange.js +21 -21
- package/dist/cjs/src/base/errors.js +3 -3
- package/dist/cjs/src/base/functions/type.js +12 -0
- package/dist/cjs/src/bigone.js +2 -2
- package/dist/cjs/src/binance.js +896 -217
- package/dist/cjs/src/bingx.js +1 -1
- package/dist/cjs/src/bitfinex.js +1 -1
- package/dist/cjs/src/bitfinex2.js +52 -62
- package/dist/cjs/src/bitget.js +8 -4
- package/dist/cjs/src/bitmart.js +3 -3
- package/dist/cjs/src/bitmex.js +4 -4
- package/dist/cjs/src/bitrue.js +1 -1
- package/dist/cjs/src/bitso.js +1 -1
- package/dist/cjs/src/bitteam.js +2 -2
- package/dist/cjs/src/btcalpha.js +1 -1
- package/dist/cjs/src/bybit.js +3 -3
- package/dist/cjs/src/coinbase.js +12 -5
- package/dist/cjs/src/coincheck.js +1 -1
- package/dist/cjs/src/coinex.js +2 -2
- package/dist/cjs/src/coinlist.js +1 -1
- package/dist/cjs/src/coinmate.js +1 -1
- package/dist/cjs/src/coinmetro.js +2 -2
- package/dist/cjs/src/coinsph.js +1 -1
- package/dist/cjs/src/cryptocom.js +3 -3
- package/dist/cjs/src/digifinex.js +6 -4
- package/dist/cjs/src/exmo.js +2 -2
- package/dist/cjs/src/gate.js +5 -5
- package/dist/cjs/src/gemini.js +3 -3
- package/dist/cjs/src/hitbtc.js +14 -20
- package/dist/cjs/src/hollaex.js +2 -2
- package/dist/cjs/src/htx.js +5 -5
- package/dist/cjs/src/huobijp.js +1 -1
- package/dist/cjs/src/krakenfutures.js +1 -1
- package/dist/cjs/src/kucoin.js +17 -17
- package/dist/cjs/src/kucoinfutures.js +3 -3
- package/dist/cjs/src/lbank.js +1 -1
- package/dist/cjs/src/mexc.js +7 -7
- package/dist/cjs/src/novadax.js +1 -1
- package/dist/cjs/src/okcoin.js +2 -2
- package/dist/cjs/src/okx.js +7 -6
- package/dist/cjs/src/p2b.js +1 -0
- package/dist/cjs/src/phemex.js +3 -3
- package/dist/cjs/src/poloniexfutures.js +3 -3
- package/dist/cjs/src/pro/alpaca.js +1 -1
- package/dist/cjs/src/pro/binance.js +4 -4
- package/dist/cjs/src/pro/bitget.js +1 -1
- package/dist/cjs/src/pro/bitmart.js +1 -1
- package/dist/cjs/src/pro/bitmex.js +49 -6
- package/dist/cjs/src/pro/bitvavo.js +1 -1
- package/dist/cjs/src/pro/bybit.js +2 -2
- package/dist/cjs/src/pro/cex.js +2 -2
- package/dist/cjs/src/pro/independentreserve.js +1 -1
- package/dist/cjs/src/pro/okx.js +1 -1
- package/dist/cjs/src/pro/onetrading.js +2 -2
- package/dist/cjs/src/pro/p2b.js +432 -0
- package/dist/cjs/src/pro/probit.js +5 -5
- package/dist/cjs/src/pro/whitebit.js +1 -1
- package/dist/cjs/src/probit.js +1 -1
- package/dist/cjs/src/timex.js +1 -1
- package/dist/cjs/src/tokocrypto.js +3 -3
- package/dist/cjs/src/wavesexchange.js +2 -2
- package/dist/cjs/src/whitebit.js +2 -2
- package/dist/cjs/src/woo.js +3 -3
- package/dist/cjs/src/yobit.js +1 -1
- package/dist/cjs/src/zaif.js +1 -1
- package/dist/cjs/src/zonda.js +3 -3
- package/js/ccxt.d.ts +4 -1
- package/js/ccxt.js +3 -1
- package/js/src/abstract/bybit.d.ts +2 -2
- package/js/src/ascendex.js +5 -5
- package/js/src/base/Exchange.d.ts +1 -1
- package/js/src/base/Exchange.js +21 -21
- package/js/src/base/errorHierarchy.d.ts +7 -6
- package/js/src/base/errorHierarchy.js +7 -6
- package/js/src/base/errors.d.ts +3 -3
- package/js/src/base/errors.js +3 -3
- package/js/src/base/functions/type.js +12 -0
- package/js/src/bigone.js +2 -2
- package/js/src/binance.d.ts +1 -0
- package/js/src/binance.js +897 -218
- package/js/src/bingx.js +1 -1
- package/js/src/bitfinex.js +1 -1
- package/js/src/bitfinex2.js +52 -62
- package/js/src/bitget.js +8 -4
- package/js/src/bitmart.js +3 -3
- package/js/src/bitmex.js +4 -4
- package/js/src/bitrue.js +1 -1
- package/js/src/bitso.d.ts +1 -1
- package/js/src/bitso.js +1 -1
- package/js/src/bitteam.js +2 -2
- package/js/src/btcalpha.js +1 -1
- package/js/src/bybit.js +3 -3
- package/js/src/coinbase.js +12 -5
- package/js/src/coincheck.js +1 -1
- package/js/src/coinex.js +2 -2
- package/js/src/coinlist.js +1 -1
- package/js/src/coinmate.js +1 -1
- package/js/src/coinmetro.d.ts +1 -1
- package/js/src/coinmetro.js +2 -2
- package/js/src/coinsph.js +1 -1
- package/js/src/cryptocom.js +3 -3
- package/js/src/digifinex.js +6 -4
- package/js/src/exmo.js +2 -2
- package/js/src/gate.js +5 -5
- package/js/src/gemini.d.ts +1 -1
- package/js/src/gemini.js +3 -3
- package/js/src/hitbtc.js +14 -20
- package/js/src/hollaex.js +2 -2
- package/js/src/htx.js +5 -5
- package/js/src/huobijp.js +1 -1
- package/js/src/krakenfutures.js +1 -1
- package/js/src/kucoin.js +17 -17
- package/js/src/kucoinfutures.js +3 -3
- package/js/src/lbank.js +1 -1
- package/js/src/mexc.js +7 -7
- package/js/src/novadax.js +1 -1
- package/js/src/okcoin.js +2 -2
- package/js/src/okx.js +7 -6
- package/js/src/p2b.js +1 -0
- package/js/src/phemex.js +3 -3
- package/js/src/poloniexfutures.js +3 -3
- package/js/src/pro/alpaca.js +1 -1
- package/js/src/pro/binance.js +4 -4
- package/js/src/pro/bitget.js +1 -1
- package/js/src/pro/bitmart.js +1 -1
- package/js/src/pro/bitmex.d.ts +2 -1
- package/js/src/pro/bitmex.js +49 -6
- package/js/src/pro/bitvavo.js +1 -1
- package/js/src/pro/bybit.js +2 -2
- package/js/src/pro/cex.js +2 -2
- package/js/src/pro/independentreserve.js +1 -1
- package/js/src/pro/okx.js +1 -1
- package/js/src/pro/onetrading.js +2 -2
- package/js/src/pro/p2b.d.ts +23 -0
- package/js/src/pro/p2b.js +433 -0
- package/js/src/pro/probit.js +5 -5
- package/js/src/pro/whitebit.js +1 -1
- package/js/src/probit.js +1 -1
- package/js/src/timex.js +1 -1
- package/js/src/tokocrypto.js +3 -3
- package/js/src/wavesexchange.js +2 -2
- package/js/src/whitebit.js +2 -2
- package/js/src/woo.js +3 -3
- package/js/src/yobit.js +1 -1
- package/js/src/zaif.js +1 -1
- package/js/src/zonda.d.ts +1 -1
- package/js/src/zonda.js +3 -3
- package/package.json +1 -1
- package/skip-tests.json +3 -10
|
@@ -143,7 +143,7 @@ class bitmart extends bitmart$1 {
|
|
|
143
143
|
return;
|
|
144
144
|
}
|
|
145
145
|
const options = this.safeValue(this.options, 'watchBalance');
|
|
146
|
-
const snapshot = this.
|
|
146
|
+
const snapshot = this.safeBool(options, 'fetchBalanceSnapshot', true);
|
|
147
147
|
if (snapshot) {
|
|
148
148
|
const messageHash = type + ':' + 'fetchBalanceSnapshot';
|
|
149
149
|
if (!(messageHash in client.futures)) {
|
|
@@ -20,7 +20,7 @@ class bitmex extends bitmex$1 {
|
|
|
20
20
|
'watchOrders': true,
|
|
21
21
|
'watchPostions': true,
|
|
22
22
|
'watchTicker': true,
|
|
23
|
-
'watchTickers':
|
|
23
|
+
'watchTickers': true,
|
|
24
24
|
'watchTrades': true,
|
|
25
25
|
'watchTradesForSymbols': true,
|
|
26
26
|
},
|
|
@@ -72,6 +72,46 @@ class bitmex extends bitmex$1 {
|
|
|
72
72
|
};
|
|
73
73
|
return await this.watch(url, messageHash, this.extend(request, params), messageHash);
|
|
74
74
|
}
|
|
75
|
+
async watchTickers(symbols = undefined, params = {}) {
|
|
76
|
+
/**
|
|
77
|
+
* @method
|
|
78
|
+
* @name bitmex#watchTickers
|
|
79
|
+
* @description watches a price ticker, a statistical calculation with the information calculated over the past 24 hours for all markets of a specific list
|
|
80
|
+
* @param {string[]} symbols unified symbol of the market to fetch the ticker for
|
|
81
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
82
|
+
* @returns {object} a [ticker structure]{@link https://docs.ccxt.com/#/?id=ticker-structure}
|
|
83
|
+
*/
|
|
84
|
+
await this.loadMarkets();
|
|
85
|
+
symbols = this.marketSymbols(symbols, undefined, true);
|
|
86
|
+
const name = 'instrument';
|
|
87
|
+
const url = this.urls['api']['ws'];
|
|
88
|
+
const messageHashes = [];
|
|
89
|
+
if (symbols !== undefined) {
|
|
90
|
+
for (let i = 0; i < symbols.length; i++) {
|
|
91
|
+
const symbol = symbols[i];
|
|
92
|
+
const market = this.market(symbol);
|
|
93
|
+
const hash = name + ':' + market['id'];
|
|
94
|
+
messageHashes.push(hash);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
messageHashes.push(name);
|
|
99
|
+
}
|
|
100
|
+
const request = {
|
|
101
|
+
'op': 'subscribe',
|
|
102
|
+
'args': messageHashes,
|
|
103
|
+
};
|
|
104
|
+
const ticker = await this.watchMultiple(url, messageHashes, this.extend(request, params), messageHashes);
|
|
105
|
+
if (this.newUpdates) {
|
|
106
|
+
if (symbols === undefined) {
|
|
107
|
+
return ticker;
|
|
108
|
+
}
|
|
109
|
+
const result = {};
|
|
110
|
+
result[ticker['symbol']] = ticker;
|
|
111
|
+
return result;
|
|
112
|
+
}
|
|
113
|
+
return this.filterByArray(this.tickers, 'symbol', symbols);
|
|
114
|
+
}
|
|
75
115
|
handleTicker(client, message) {
|
|
76
116
|
//
|
|
77
117
|
// {
|
|
@@ -300,19 +340,22 @@ class bitmex extends bitmex$1 {
|
|
|
300
340
|
// }
|
|
301
341
|
//
|
|
302
342
|
const table = this.safeString(message, 'table');
|
|
303
|
-
const data = this.
|
|
343
|
+
const data = this.safeList(message, 'data', []);
|
|
344
|
+
const tickers = {};
|
|
304
345
|
for (let i = 0; i < data.length; i++) {
|
|
305
346
|
const update = data[i];
|
|
306
|
-
const marketId = this.
|
|
347
|
+
const marketId = this.safeString(update, 'symbol');
|
|
307
348
|
const market = this.safeMarket(marketId);
|
|
308
349
|
const symbol = market['symbol'];
|
|
309
350
|
const messageHash = table + ':' + marketId;
|
|
310
|
-
let ticker = this.
|
|
311
|
-
const info = this.
|
|
351
|
+
let ticker = this.safeDict(this.tickers, symbol, {});
|
|
352
|
+
const info = this.safeDict(ticker, 'info', {});
|
|
312
353
|
ticker = this.parseTicker(this.extend(info, update), market);
|
|
354
|
+
tickers[symbol] = ticker;
|
|
313
355
|
this.tickers[symbol] = ticker;
|
|
314
356
|
client.resolve(ticker, messageHash);
|
|
315
357
|
}
|
|
358
|
+
client.resolve(tickers, 'instrument');
|
|
316
359
|
return message;
|
|
317
360
|
}
|
|
318
361
|
async watchBalance(params = {}) {
|
|
@@ -576,7 +619,7 @@ class bitmex extends bitmex$1 {
|
|
|
576
619
|
return future;
|
|
577
620
|
}
|
|
578
621
|
handleAuthenticationMessage(client, message) {
|
|
579
|
-
const authenticated = this.
|
|
622
|
+
const authenticated = this.safeBool(message, 'success', false);
|
|
580
623
|
const messageHash = 'authenticated';
|
|
581
624
|
if (authenticated) {
|
|
582
625
|
// we resolve the future here permanently so authentication only happens once
|
|
@@ -1225,7 +1225,7 @@ class bitvavo extends bitvavo$1 {
|
|
|
1225
1225
|
// }
|
|
1226
1226
|
//
|
|
1227
1227
|
const messageHash = 'authenticated';
|
|
1228
|
-
const authenticated = this.
|
|
1228
|
+
const authenticated = this.safeBool(message, 'authenticated', false);
|
|
1229
1229
|
if (authenticated) {
|
|
1230
1230
|
// we resolve the future here permanently so authentication only happens once
|
|
1231
1231
|
client.resolve(message, messageHash);
|
|
@@ -1342,8 +1342,8 @@ class bybit extends bybit$1 {
|
|
|
1342
1342
|
let subType = undefined;
|
|
1343
1343
|
[subType, params] = this.handleSubTypeAndParams('watchBalance', undefined, params);
|
|
1344
1344
|
const unified = await this.isUnifiedEnabled();
|
|
1345
|
-
const isUnifiedMargin = this.
|
|
1346
|
-
const isUnifiedAccount = this.
|
|
1345
|
+
const isUnifiedMargin = this.safeBool(unified, 0, false);
|
|
1346
|
+
const isUnifiedAccount = this.safeBool(unified, 1, false);
|
|
1347
1347
|
const url = this.getUrlByMarketType(undefined, true, method, params);
|
|
1348
1348
|
await this.authenticate(url);
|
|
1349
1349
|
const topicByMarket = {
|
package/dist/cjs/src/pro/cex.js
CHANGED
|
@@ -717,7 +717,7 @@ class cex extends cex$1 {
|
|
|
717
717
|
order = this.parseWsOrderUpdate(data, market);
|
|
718
718
|
}
|
|
719
719
|
order['remaining'] = remains;
|
|
720
|
-
const canceled = this.
|
|
720
|
+
const canceled = this.safeBool(data, 'cancel', false);
|
|
721
721
|
if (canceled) {
|
|
722
722
|
order['status'] = 'canceled';
|
|
723
723
|
}
|
|
@@ -806,7 +806,7 @@ class cex extends cex$1 {
|
|
|
806
806
|
if (isTransaction) {
|
|
807
807
|
timestamp = this.parse8601(time);
|
|
808
808
|
}
|
|
809
|
-
const canceled = this.
|
|
809
|
+
const canceled = this.safeBool(order, 'cancel', false);
|
|
810
810
|
let status = 'open';
|
|
811
811
|
if (canceled) {
|
|
812
812
|
status = 'canceled';
|
|
@@ -176,7 +176,7 @@ class independentreserve extends independentreserve$1 {
|
|
|
176
176
|
const orderBook = this.safeValue(message, 'Data', {});
|
|
177
177
|
const messageHash = 'orderbook:' + symbol + ':' + depth;
|
|
178
178
|
const subscription = this.safeValue(client.subscriptions, messageHash, {});
|
|
179
|
-
const receivedSnapshot = this.
|
|
179
|
+
const receivedSnapshot = this.safeBool(subscription, 'receivedSnapshot', false);
|
|
180
180
|
const timestamp = this.safeInteger(message, 'Time');
|
|
181
181
|
let storedOrderBook = this.safeValue(this.orderbooks, symbol);
|
|
182
182
|
if (storedOrderBook === undefined) {
|
package/dist/cjs/src/pro/okx.js
CHANGED
|
@@ -864,7 +864,7 @@ class okx extends okx$1 {
|
|
|
864
864
|
// By default, receive order updates from any instrument type
|
|
865
865
|
let type = undefined;
|
|
866
866
|
[type, params] = this.handleOptionAndParams(params, 'watchMyTrades', 'type', 'ANY');
|
|
867
|
-
const isStop = this.
|
|
867
|
+
const isStop = this.safeBool(params, 'stop', false);
|
|
868
868
|
params = this.omit(params, ['stop']);
|
|
869
869
|
await this.loadMarkets();
|
|
870
870
|
await this.authenticate({ 'access': isStop ? 'business' : 'private' });
|
|
@@ -1057,7 +1057,7 @@ class onetrading extends onetrading$1 {
|
|
|
1057
1057
|
subscription = this.safeValue(client.subscriptions, subscriptionHash);
|
|
1058
1058
|
if (subscription !== undefined) {
|
|
1059
1059
|
const ohlcvMarket = this.safeValue(subscription, marketId, {});
|
|
1060
|
-
const marketSubscribed = this.
|
|
1060
|
+
const marketSubscribed = this.safeBool(ohlcvMarket, timeframe, false);
|
|
1061
1061
|
if (!marketSubscribed) {
|
|
1062
1062
|
type = 'UPDATE_SUBSCRIPTION';
|
|
1063
1063
|
client.subscriptions[subscriptionHash] = undefined;
|
|
@@ -1298,7 +1298,7 @@ class onetrading extends onetrading$1 {
|
|
|
1298
1298
|
if (subscription !== undefined) {
|
|
1299
1299
|
for (let i = 0; i < marketIds.length; i++) {
|
|
1300
1300
|
const marketId = marketIds[i];
|
|
1301
|
-
const marketSubscribed = this.
|
|
1301
|
+
const marketSubscribed = this.safeBool(subscription, marketId, false);
|
|
1302
1302
|
if (!marketSubscribed) {
|
|
1303
1303
|
type = 'UPDATE_SUBSCRIPTION';
|
|
1304
1304
|
client.subscriptions[subscriptionHash] = undefined;
|
|
@@ -0,0 +1,432 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var p2b$1 = require('../p2b.js');
|
|
4
|
+
var errors = require('../base/errors.js');
|
|
5
|
+
var Cache = require('../base/ws/Cache.js');
|
|
6
|
+
|
|
7
|
+
// ---------------------------------------------------------------------------
|
|
8
|
+
// ---------------------------------------------------------------------------
|
|
9
|
+
class p2b extends p2b$1 {
|
|
10
|
+
describe() {
|
|
11
|
+
return this.deepExtend(super.describe(), {
|
|
12
|
+
'has': {
|
|
13
|
+
'ws': true,
|
|
14
|
+
'cancelAllOrdersWs': false,
|
|
15
|
+
'cancelOrdersWs': false,
|
|
16
|
+
'cancelOrderWs': false,
|
|
17
|
+
'createOrderWs': false,
|
|
18
|
+
'editOrderWs': false,
|
|
19
|
+
'fetchBalanceWs': false,
|
|
20
|
+
'fetchOpenOrdersWs': false,
|
|
21
|
+
'fetchOrderWs': false,
|
|
22
|
+
'fetchTradesWs': false,
|
|
23
|
+
'watchBalance': false,
|
|
24
|
+
'watchMyTrades': false,
|
|
25
|
+
'watchOHLCV': true,
|
|
26
|
+
'watchOrderBook': true,
|
|
27
|
+
'watchOrders': false,
|
|
28
|
+
// 'watchStatus': true,
|
|
29
|
+
'watchTicker': true,
|
|
30
|
+
'watchTickers': false,
|
|
31
|
+
'watchTrades': true,
|
|
32
|
+
},
|
|
33
|
+
'urls': {
|
|
34
|
+
'api': {
|
|
35
|
+
'ws': 'wss://apiws.p2pb2b.com/',
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
'options': {
|
|
39
|
+
'OHLCVLimit': 1000,
|
|
40
|
+
'tradesLimit': 1000,
|
|
41
|
+
'timeframes': {
|
|
42
|
+
'15m': 900,
|
|
43
|
+
'30m': 1800,
|
|
44
|
+
'1h': 3600,
|
|
45
|
+
'1d': 86400,
|
|
46
|
+
},
|
|
47
|
+
'watchTicker': {
|
|
48
|
+
'name': 'state', // or 'price'
|
|
49
|
+
},
|
|
50
|
+
'watchTickers': {
|
|
51
|
+
'name': 'state', // or 'price'
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
'streaming': {
|
|
55
|
+
'ping': this.ping,
|
|
56
|
+
},
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
async subscribe(name, messageHash, request, params = {}) {
|
|
60
|
+
/**
|
|
61
|
+
* @ignore
|
|
62
|
+
* @method
|
|
63
|
+
* @description Connects to a websocket channel
|
|
64
|
+
* @param {string} name name of the channel
|
|
65
|
+
* @param {string} messageHash string to look up in handler
|
|
66
|
+
* @param {string[]|float[]} request endpoint parameters
|
|
67
|
+
* @param {object} [params] extra parameters specific to the p2b api
|
|
68
|
+
* @returns {object} data from the websocket stream
|
|
69
|
+
*/
|
|
70
|
+
const url = this.urls['api']['ws'];
|
|
71
|
+
const subscribe = {
|
|
72
|
+
'method': name,
|
|
73
|
+
'params': request,
|
|
74
|
+
'id': this.milliseconds(),
|
|
75
|
+
};
|
|
76
|
+
const query = this.extend(subscribe, params);
|
|
77
|
+
return await this.watch(url, messageHash, query, messageHash);
|
|
78
|
+
}
|
|
79
|
+
async watchOHLCV(symbol, timeframe = '15m', since = undefined, limit = undefined, params = {}) {
|
|
80
|
+
/**
|
|
81
|
+
* @method
|
|
82
|
+
* @name p2b#watchOHLCV
|
|
83
|
+
* @description watches historical candlestick data containing the open, high, low, and close price, and the volume of a market. Can only subscribe to one timeframe at a time for each symbol
|
|
84
|
+
* @see https://github.com/P2B-team/P2B-WSS-Public/blob/main/wss_documentation.md#kline-candlestick
|
|
85
|
+
* @param {string} symbol unified symbol of the market to fetch OHLCV data for
|
|
86
|
+
* @param {string} timeframe 15m, 30m, 1h or 1d
|
|
87
|
+
* @param {int} [since] timestamp in ms of the earliest candle to fetch
|
|
88
|
+
* @param {int} [limit] the maximum amount of candles to fetch
|
|
89
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
90
|
+
* @returns {int[][]} A list of candles ordered as timestamp, open, high, low, close, volume
|
|
91
|
+
*/
|
|
92
|
+
await this.loadMarkets();
|
|
93
|
+
const timeframes = this.safeValue(this.options, 'timeframes', {});
|
|
94
|
+
const channel = this.safeInteger(timeframes, timeframe);
|
|
95
|
+
if (channel === undefined) {
|
|
96
|
+
throw new errors.BadRequest(this.id + ' watchOHLCV cannot take a timeframe of ' + timeframe);
|
|
97
|
+
}
|
|
98
|
+
const market = this.market(symbol);
|
|
99
|
+
const request = [
|
|
100
|
+
market['id'],
|
|
101
|
+
channel,
|
|
102
|
+
];
|
|
103
|
+
const messageHash = 'kline::' + market['symbol'];
|
|
104
|
+
const ohlcv = await this.subscribe('kline.subscribe', messageHash, request, params);
|
|
105
|
+
if (this.newUpdates) {
|
|
106
|
+
limit = ohlcv.getLimit(symbol, limit);
|
|
107
|
+
}
|
|
108
|
+
return this.filterBySinceLimit(ohlcv, since, limit, 0, true);
|
|
109
|
+
}
|
|
110
|
+
async watchTicker(symbol, params = {}) {
|
|
111
|
+
/**
|
|
112
|
+
* @method
|
|
113
|
+
* @name p2b#watchTicker
|
|
114
|
+
* @description watches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
|
|
115
|
+
* @see https://github.com/P2B-team/P2B-WSS-Public/blob/main/wss_documentation.md#last-price
|
|
116
|
+
* @see https://github.com/P2B-team/P2B-WSS-Public/blob/main/wss_documentation.md#market-status
|
|
117
|
+
* @param {string} symbol unified symbol of the market to fetch the ticker for
|
|
118
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
119
|
+
* @param {object} [params.method] 'state' (default) or 'price'
|
|
120
|
+
* @returns {object} a [ticker structure]{@link https://docs.ccxt.com/#/?id=ticker-structure}
|
|
121
|
+
*/
|
|
122
|
+
await this.loadMarkets();
|
|
123
|
+
const watchTickerOptions = this.safeValue(this.options, 'watchTicker');
|
|
124
|
+
let name = this.safeString(watchTickerOptions, 'name', 'state'); // or price
|
|
125
|
+
[name, params] = this.handleOptionAndParams(params, 'method', 'name', name);
|
|
126
|
+
const market = this.market(symbol);
|
|
127
|
+
const request = [
|
|
128
|
+
market['id'],
|
|
129
|
+
];
|
|
130
|
+
const messageHash = name + '::' + market['symbol'];
|
|
131
|
+
return await this.subscribe(name + '.subscribe', messageHash, request, params);
|
|
132
|
+
}
|
|
133
|
+
async watchTrades(symbol, since = undefined, limit = undefined, params = {}) {
|
|
134
|
+
/**
|
|
135
|
+
* @method
|
|
136
|
+
* @name p2b#watchTrades
|
|
137
|
+
* @description get the list of most recent trades for a particular symbol
|
|
138
|
+
* @see https://github.com/P2B-team/P2B-WSS-Public/blob/main/wss_documentation.md#deals
|
|
139
|
+
* @param {string} symbol unified symbol of the market to fetch trades for
|
|
140
|
+
* @param {int} [since] timestamp in ms of the earliest trade to fetch
|
|
141
|
+
* @param {int} [limit] the maximum amount of trades to fetch
|
|
142
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
143
|
+
* @returns {object[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=public-trades}
|
|
144
|
+
*/
|
|
145
|
+
await this.loadMarkets();
|
|
146
|
+
const market = this.market(symbol);
|
|
147
|
+
const request = [
|
|
148
|
+
market['id'],
|
|
149
|
+
];
|
|
150
|
+
const messageHash = 'deals::' + market['symbol'];
|
|
151
|
+
const trades = await this.subscribe('deals.subscribe', messageHash, request, params);
|
|
152
|
+
if (this.newUpdates) {
|
|
153
|
+
limit = trades.getLimit(symbol, limit);
|
|
154
|
+
}
|
|
155
|
+
return this.filterBySinceLimit(trades, since, limit, 'timestamp', true);
|
|
156
|
+
}
|
|
157
|
+
async watchOrderBook(symbol, limit = undefined, params = {}) {
|
|
158
|
+
/**
|
|
159
|
+
* @method
|
|
160
|
+
* @name p2b#watchOrderBook
|
|
161
|
+
* @description watches information on open orders with bid (buy) and ask (sell) prices, volumes and other data
|
|
162
|
+
* @see https://github.com/P2B-team/P2B-WSS-Public/blob/main/wss_documentation.md#depth-of-market
|
|
163
|
+
* @param {string} symbol unified symbol of the market to fetch the order book for
|
|
164
|
+
* @param {int} [limit] 1-100, default=100
|
|
165
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
166
|
+
* @param {float} [params.interval] 0, 0.00000001, 0.0000001, 0.000001, 0.00001, 0.0001, 0.001, 0.01, 0.1, interval of precision for order, default=0.001
|
|
167
|
+
* @returns {object} A dictionary of [order book structures]{@link https://docs.ccxt.com/#/?id=order-book-structure} indexed by market symbols
|
|
168
|
+
*/
|
|
169
|
+
await this.loadMarkets();
|
|
170
|
+
const market = this.market(symbol);
|
|
171
|
+
const name = 'depth.subscribe';
|
|
172
|
+
const messageHash = 'orderbook::' + market['symbol'];
|
|
173
|
+
const interval = this.safeString(params, 'interval', '0.001');
|
|
174
|
+
if (limit === undefined) {
|
|
175
|
+
limit = 100;
|
|
176
|
+
}
|
|
177
|
+
const request = [
|
|
178
|
+
market['id'],
|
|
179
|
+
limit,
|
|
180
|
+
interval,
|
|
181
|
+
];
|
|
182
|
+
const orderbook = await this.subscribe(name, messageHash, request, params);
|
|
183
|
+
return orderbook.limit();
|
|
184
|
+
}
|
|
185
|
+
handleOHLCV(client, message) {
|
|
186
|
+
//
|
|
187
|
+
// {
|
|
188
|
+
// "method": "kline.update",
|
|
189
|
+
// "params": [
|
|
190
|
+
// [
|
|
191
|
+
// 1657648800, // Kline start time
|
|
192
|
+
// "0.054146", // Kline open price
|
|
193
|
+
// "0.053938", // Kline close price (current price)
|
|
194
|
+
// "0.054146", // Kline high price
|
|
195
|
+
// "0.053911", // Kline low price
|
|
196
|
+
// "596.4674", // Volume for stock currency
|
|
197
|
+
// "32.2298758767", // Volume for money currency
|
|
198
|
+
// "ETH_BTC" // Market
|
|
199
|
+
// ]
|
|
200
|
+
// ],
|
|
201
|
+
// "id": null
|
|
202
|
+
// }
|
|
203
|
+
//
|
|
204
|
+
let data = this.safeList(message, 'params');
|
|
205
|
+
data = this.safeList(data, 0);
|
|
206
|
+
const method = this.safeString(message, 'method');
|
|
207
|
+
const splitMethod = method.split('.');
|
|
208
|
+
const channel = this.safeString(splitMethod, 0);
|
|
209
|
+
const marketId = this.safeString(data, 7);
|
|
210
|
+
const market = this.safeMarket(marketId);
|
|
211
|
+
const timeframes = this.safeDict(this.options, 'timeframes', {});
|
|
212
|
+
const timeframe = this.findTimeframe(channel, timeframes);
|
|
213
|
+
const symbol = this.safeString(market, 'symbol');
|
|
214
|
+
const messageHash = channel + '::' + symbol;
|
|
215
|
+
const parsed = this.parseOHLCV(data, market);
|
|
216
|
+
this.ohlcvs[symbol] = this.safeValue(this.ohlcvs, symbol, {});
|
|
217
|
+
let stored = this.safeValue(this.ohlcvs[symbol], timeframe);
|
|
218
|
+
if (symbol !== undefined) {
|
|
219
|
+
if (stored === undefined) {
|
|
220
|
+
const limit = this.safeInteger(this.options, 'OHLCVLimit', 1000);
|
|
221
|
+
stored = new Cache.ArrayCacheByTimestamp(limit);
|
|
222
|
+
this.ohlcvs[symbol][timeframe] = stored;
|
|
223
|
+
}
|
|
224
|
+
stored.append(parsed);
|
|
225
|
+
client.resolve(stored, messageHash);
|
|
226
|
+
}
|
|
227
|
+
return message;
|
|
228
|
+
}
|
|
229
|
+
handleTrade(client, message) {
|
|
230
|
+
//
|
|
231
|
+
// {
|
|
232
|
+
// "method": "deals.update",
|
|
233
|
+
// "params": [
|
|
234
|
+
// "ETH_BTC",
|
|
235
|
+
// [
|
|
236
|
+
// {
|
|
237
|
+
// "id": 4503032979, // Order_id
|
|
238
|
+
// "amount": "0.103",
|
|
239
|
+
// "type": "sell", // Side
|
|
240
|
+
// "time": 1657661950.8487639, // Creation time
|
|
241
|
+
// "price": "0.05361"
|
|
242
|
+
// },
|
|
243
|
+
// ...
|
|
244
|
+
// ]
|
|
245
|
+
// ],
|
|
246
|
+
// "id": null
|
|
247
|
+
// }
|
|
248
|
+
//
|
|
249
|
+
const data = this.safeList(message, 'params', []);
|
|
250
|
+
const trades = this.safeList(data, 1);
|
|
251
|
+
const marketId = this.safeString(data, 0);
|
|
252
|
+
const market = this.safeMarket(marketId);
|
|
253
|
+
const symbol = this.safeString(market, 'symbol');
|
|
254
|
+
let tradesArray = this.safeValue(this.trades, symbol);
|
|
255
|
+
if (tradesArray === undefined) {
|
|
256
|
+
const tradesLimit = this.safeInteger(this.options, 'tradesLimit', 1000);
|
|
257
|
+
tradesArray = new Cache.ArrayCache(tradesLimit);
|
|
258
|
+
this.trades[symbol] = tradesArray;
|
|
259
|
+
}
|
|
260
|
+
for (let i = 0; i < trades.length; i++) {
|
|
261
|
+
const item = trades[i];
|
|
262
|
+
const trade = this.parseTrade(item, market);
|
|
263
|
+
tradesArray.append(trade);
|
|
264
|
+
}
|
|
265
|
+
const messageHash = 'deals::' + symbol;
|
|
266
|
+
client.resolve(tradesArray, messageHash);
|
|
267
|
+
return message;
|
|
268
|
+
}
|
|
269
|
+
handleTicker(client, message) {
|
|
270
|
+
//
|
|
271
|
+
// state
|
|
272
|
+
//
|
|
273
|
+
// {
|
|
274
|
+
// "method": "state.update",
|
|
275
|
+
// "params": [
|
|
276
|
+
// "ETH_BTC",
|
|
277
|
+
// {
|
|
278
|
+
// "high": "0.055774", // High price for the last 24h
|
|
279
|
+
// "close": "0.053679", // Close price for the last 24h
|
|
280
|
+
// "low": "0.053462", // Low price for the last 24h
|
|
281
|
+
// "period": 86400, // Period 24h
|
|
282
|
+
// "last": "0.053679", // Last price for the last 24h
|
|
283
|
+
// "volume": "38463.6132", // Stock volume for the last 24h
|
|
284
|
+
// "open": "0.055682", // Open price for the last 24h
|
|
285
|
+
// "deal": "2091.0038055314" // Money volume for the last 24h
|
|
286
|
+
// }
|
|
287
|
+
// ],
|
|
288
|
+
// "id": null
|
|
289
|
+
// }
|
|
290
|
+
//
|
|
291
|
+
// price
|
|
292
|
+
//
|
|
293
|
+
// {
|
|
294
|
+
// "method": "price.update",
|
|
295
|
+
// "params": [
|
|
296
|
+
// "ETH_BTC", // market
|
|
297
|
+
// "0.053836" // last price
|
|
298
|
+
// ],
|
|
299
|
+
// "id": null
|
|
300
|
+
// }
|
|
301
|
+
//
|
|
302
|
+
const data = this.safeList(message, 'params', []);
|
|
303
|
+
const marketId = this.safeString(data, 0);
|
|
304
|
+
const market = this.safeMarket(marketId);
|
|
305
|
+
const method = this.safeString(message, 'method');
|
|
306
|
+
const splitMethod = method.split('.');
|
|
307
|
+
const messageHashStart = this.safeString(splitMethod, 0);
|
|
308
|
+
const tickerData = this.safeDict(data, 1);
|
|
309
|
+
let ticker = undefined;
|
|
310
|
+
if (method === 'price.update') {
|
|
311
|
+
const lastPrice = this.safeString(data, 1);
|
|
312
|
+
ticker = this.safeTicker({
|
|
313
|
+
'last': lastPrice,
|
|
314
|
+
'close': lastPrice,
|
|
315
|
+
'symbol': market['symbol'],
|
|
316
|
+
});
|
|
317
|
+
}
|
|
318
|
+
else {
|
|
319
|
+
ticker = this.parseTicker(tickerData, market);
|
|
320
|
+
}
|
|
321
|
+
const symbol = ticker['symbol'];
|
|
322
|
+
const messageHash = messageHashStart + '::' + symbol;
|
|
323
|
+
client.resolve(ticker, messageHash);
|
|
324
|
+
return message;
|
|
325
|
+
}
|
|
326
|
+
handleOrderBook(client, message) {
|
|
327
|
+
//
|
|
328
|
+
// {
|
|
329
|
+
// "method": "depth.update",
|
|
330
|
+
// "params": [
|
|
331
|
+
// false, // true - all records, false - new records
|
|
332
|
+
// {
|
|
333
|
+
// "asks": [ // side
|
|
334
|
+
// [
|
|
335
|
+
// "19509.81", // price
|
|
336
|
+
// "0.277" // amount
|
|
337
|
+
// ]
|
|
338
|
+
// ]
|
|
339
|
+
// },
|
|
340
|
+
// "BTC_USDT"
|
|
341
|
+
// ],
|
|
342
|
+
// "id": null
|
|
343
|
+
// }
|
|
344
|
+
//
|
|
345
|
+
const params = this.safeList(message, 'params', []);
|
|
346
|
+
const data = this.safeDict(params, 1);
|
|
347
|
+
const asks = this.safeList(data, 'asks');
|
|
348
|
+
const bids = this.safeList(data, 'bids');
|
|
349
|
+
const marketId = this.safeString(params, 2);
|
|
350
|
+
const market = this.safeMarket(marketId);
|
|
351
|
+
const symbol = market['symbol'];
|
|
352
|
+
const messageHash = 'orderbook::' + market['symbol'];
|
|
353
|
+
const subscription = this.safeValue(client.subscriptions, messageHash, {});
|
|
354
|
+
const limit = this.safeInteger(subscription, 'limit');
|
|
355
|
+
let orderbook = this.safeValue(this.orderbooks, symbol);
|
|
356
|
+
if (orderbook === undefined) {
|
|
357
|
+
this.orderbooks[symbol] = this.orderBook({}, limit);
|
|
358
|
+
orderbook = this.orderbooks[symbol];
|
|
359
|
+
}
|
|
360
|
+
if (bids !== undefined) {
|
|
361
|
+
for (let i = 0; i < bids.length; i++) {
|
|
362
|
+
const bid = this.safeValue(bids, i);
|
|
363
|
+
const price = this.safeNumber(bid, 0);
|
|
364
|
+
const amount = this.safeNumber(bid, 1);
|
|
365
|
+
orderbook['bids'].store(price, amount);
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
if (asks !== undefined) {
|
|
369
|
+
for (let i = 0; i < asks.length; i++) {
|
|
370
|
+
const ask = this.safeValue(asks, i);
|
|
371
|
+
const price = this.safeNumber(ask, 0);
|
|
372
|
+
const amount = this.safeNumber(ask, 1);
|
|
373
|
+
orderbook['asks'].store(price, amount);
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
orderbook['symbol'] = symbol;
|
|
377
|
+
client.resolve(orderbook, messageHash);
|
|
378
|
+
}
|
|
379
|
+
handleMessage(client, message) {
|
|
380
|
+
if (this.handleErrorMessage(client, message)) {
|
|
381
|
+
return;
|
|
382
|
+
}
|
|
383
|
+
const result = this.safeString(message, 'result');
|
|
384
|
+
if (result === 'pong') {
|
|
385
|
+
this.handlePong(client, message);
|
|
386
|
+
return;
|
|
387
|
+
}
|
|
388
|
+
const method = this.safeString(message, 'method');
|
|
389
|
+
const methods = {
|
|
390
|
+
'depth.update': this.handleOrderBook,
|
|
391
|
+
'price.update': this.handleTicker,
|
|
392
|
+
'kline.update': this.handleOHLCV,
|
|
393
|
+
'state.update': this.handleTicker,
|
|
394
|
+
'deals.update': this.handleTrade,
|
|
395
|
+
};
|
|
396
|
+
const endpoint = this.safeValue(methods, method);
|
|
397
|
+
if (endpoint !== undefined) {
|
|
398
|
+
return endpoint.call(this, client, message);
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
handleErrorMessage(client, message) {
|
|
402
|
+
const error = this.safeString(message, 'error');
|
|
403
|
+
if (error !== undefined) {
|
|
404
|
+
throw new errors.ExchangeError(this.id + ' error: ' + this.json(error));
|
|
405
|
+
}
|
|
406
|
+
return false;
|
|
407
|
+
}
|
|
408
|
+
ping(client) {
|
|
409
|
+
/**
|
|
410
|
+
* @see https://github.com/P2B-team/P2B-WSS-Public/blob/main/wss_documentation.md#ping
|
|
411
|
+
* @param client
|
|
412
|
+
*/
|
|
413
|
+
return {
|
|
414
|
+
'method': 'server.ping',
|
|
415
|
+
'params': [],
|
|
416
|
+
'id': this.milliseconds(),
|
|
417
|
+
};
|
|
418
|
+
}
|
|
419
|
+
handlePong(client, message) {
|
|
420
|
+
//
|
|
421
|
+
// {
|
|
422
|
+
// error: null,
|
|
423
|
+
// result: 'pong',
|
|
424
|
+
// id: 1706539608030
|
|
425
|
+
// }
|
|
426
|
+
//
|
|
427
|
+
client.lastPong = this.safeInteger(message, 'id');
|
|
428
|
+
return message;
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
module.exports = p2b;
|
|
@@ -95,7 +95,7 @@ class probit extends probit$1 {
|
|
|
95
95
|
// }
|
|
96
96
|
// }
|
|
97
97
|
//
|
|
98
|
-
const reset = this.
|
|
98
|
+
const reset = this.safeBool(message, 'reset', false);
|
|
99
99
|
const data = this.safeValue(message, 'data', {});
|
|
100
100
|
const currencyIds = Object.keys(data);
|
|
101
101
|
if (reset) {
|
|
@@ -201,7 +201,7 @@ class probit extends probit$1 {
|
|
|
201
201
|
const symbol = this.safeSymbol(marketId);
|
|
202
202
|
const market = this.safeMarket(marketId);
|
|
203
203
|
const trades = this.safeValue(message, 'recent_trades', []);
|
|
204
|
-
const reset = this.
|
|
204
|
+
const reset = this.safeBool(message, 'reset', false);
|
|
205
205
|
const messageHash = 'trades:' + symbol;
|
|
206
206
|
let stored = this.safeValue(this.trades, symbol);
|
|
207
207
|
if (stored === undefined || reset) {
|
|
@@ -274,7 +274,7 @@ class probit extends probit$1 {
|
|
|
274
274
|
if (length === 0) {
|
|
275
275
|
return;
|
|
276
276
|
}
|
|
277
|
-
const reset = this.
|
|
277
|
+
const reset = this.safeBool(message, 'reset', false);
|
|
278
278
|
const messageHash = 'myTrades';
|
|
279
279
|
let stored = this.myTrades;
|
|
280
280
|
if ((stored === undefined) || reset) {
|
|
@@ -362,7 +362,7 @@ class probit extends probit$1 {
|
|
|
362
362
|
return;
|
|
363
363
|
}
|
|
364
364
|
const messageHash = 'orders';
|
|
365
|
-
const reset = this.
|
|
365
|
+
const reset = this.safeBool(message, 'reset', false);
|
|
366
366
|
let stored = this.orders;
|
|
367
367
|
if (stored === undefined || reset) {
|
|
368
368
|
const limit = this.safeInteger(this.options, 'ordersLimit', 1000);
|
|
@@ -454,7 +454,7 @@ class probit extends probit$1 {
|
|
|
454
454
|
storedOrderBook = this.orderBook({});
|
|
455
455
|
this.orderbooks[symbol] = storedOrderBook;
|
|
456
456
|
}
|
|
457
|
-
const reset = this.
|
|
457
|
+
const reset = this.safeBool(message, 'reset', false);
|
|
458
458
|
if (reset) {
|
|
459
459
|
const snapshot = this.parseOrderBook(dataBySide, symbol, undefined, 'buy', 'sell', 'price', 'quantity');
|
|
460
460
|
storedOrderBook.reset(snapshot);
|
|
@@ -738,7 +738,7 @@ class whitebit extends whitebit$1 {
|
|
|
738
738
|
let hasSymbolSubscription = true;
|
|
739
739
|
const market = this.market(symbol);
|
|
740
740
|
const marketId = market['id'];
|
|
741
|
-
const isSubscribed = this.
|
|
741
|
+
const isSubscribed = this.safeBool(subscription, marketId, false);
|
|
742
742
|
if (!isSubscribed) {
|
|
743
743
|
subscription[marketId] = true;
|
|
744
744
|
hasSymbolSubscription = false;
|