ccxt 4.3.71 → 4.3.73
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 -1
- package/dist/cjs/src/base/ws/Client.js +2 -2
- package/dist/cjs/src/paradex.js +1 -1
- package/dist/cjs/src/pro/binance.js +16 -1
- package/dist/cjs/src/pro/kucoin.js +7 -2
- package/dist/cjs/src/pro/woo.js +129 -12
- package/examples/js/cli.js +8 -4
- package/js/ccxt.d.ts +1 -1
- package/js/ccxt.js +1 -1
- package/js/src/base/types.d.ts +10 -10
- package/js/src/base/ws/Client.js +2 -2
- package/js/src/paradex.js +1 -1
- package/js/src/pro/binance.js +16 -1
- package/js/src/pro/kucoin.js +7 -2
- package/js/src/pro/woo.d.ts +5 -0
- package/js/src/pro/woo.js +129 -12
- package/package.json +1 -1
package/js/src/pro/woo.js
CHANGED
|
@@ -88,32 +88,49 @@ export default class woo extends wooRest {
|
|
|
88
88
|
/**
|
|
89
89
|
* @method
|
|
90
90
|
* @name woo#watchOrderBook
|
|
91
|
+
* @see https://docs.woo.org/#orderbookupdate
|
|
91
92
|
* @see https://docs.woo.org/#orderbook
|
|
92
93
|
* @description watches information on open orders with bid (buy) and ask (sell) prices, volumes and other data
|
|
93
94
|
* @param {string} symbol unified symbol of the market to fetch the order book for
|
|
94
95
|
* @param {int} [limit] the maximum amount of order book entries to return.
|
|
95
96
|
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
97
|
+
* @param {string} [params.method] either (default) 'orderbook' or 'orderbookupdate', default is 'orderbook'
|
|
96
98
|
* @returns {object} A dictionary of [order book structures]{@link https://docs.ccxt.com/#/?id=order-book-structure} indexed by market symbols
|
|
97
99
|
*/
|
|
98
100
|
await this.loadMarkets();
|
|
99
|
-
|
|
101
|
+
let method = undefined;
|
|
102
|
+
[method, params] = this.handleOptionAndParams(params, 'watchOrderBook', 'method', 'orderbook');
|
|
100
103
|
const market = this.market(symbol);
|
|
101
|
-
const topic = market['id'] + '@' +
|
|
104
|
+
const topic = market['id'] + '@' + method;
|
|
105
|
+
const urlUid = (this.uid) ? '/' + this.uid : '';
|
|
106
|
+
const url = this.urls['api']['ws']['public'] + urlUid;
|
|
107
|
+
const requestId = this.requestId(url);
|
|
102
108
|
const request = {
|
|
103
109
|
'event': 'subscribe',
|
|
104
110
|
'topic': topic,
|
|
111
|
+
'id': requestId,
|
|
105
112
|
};
|
|
106
|
-
const
|
|
107
|
-
|
|
113
|
+
const subscription = {
|
|
114
|
+
'id': requestId.toString(),
|
|
115
|
+
'name': method,
|
|
116
|
+
'symbol': symbol,
|
|
117
|
+
'limit': limit,
|
|
118
|
+
'params': params,
|
|
119
|
+
};
|
|
120
|
+
if (method === 'orderbookupdate') {
|
|
121
|
+
subscription['method'] = this.handleOrderBookSubscription;
|
|
122
|
+
}
|
|
123
|
+
const orderbook = await this.watch(url, topic, this.extend(request, params), topic, subscription);
|
|
108
124
|
return orderbook.limit();
|
|
109
125
|
}
|
|
110
126
|
handleOrderBook(client, message) {
|
|
111
127
|
//
|
|
112
128
|
// {
|
|
113
|
-
// "topic": "PERP_BTC_USDT@
|
|
114
|
-
// "ts":
|
|
129
|
+
// "topic": "PERP_BTC_USDT@orderbookupdate",
|
|
130
|
+
// "ts": 1722500373999,
|
|
115
131
|
// "data": {
|
|
116
132
|
// "symbol": "PERP_BTC_USDT",
|
|
133
|
+
// "prevTs": 1722500373799,
|
|
117
134
|
// "bids": [
|
|
118
135
|
// [
|
|
119
136
|
// 0.30891,
|
|
@@ -134,14 +151,106 @@ export default class woo extends wooRest {
|
|
|
134
151
|
const market = this.safeMarket(marketId);
|
|
135
152
|
const symbol = market['symbol'];
|
|
136
153
|
const topic = this.safeString(message, 'topic');
|
|
137
|
-
|
|
138
|
-
|
|
154
|
+
const method = this.safeString(topic.split('@'), 1);
|
|
155
|
+
if (method === 'orderbookupdate') {
|
|
156
|
+
if (!(symbol in this.orderbooks)) {
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
const orderbook = this.orderbooks[symbol];
|
|
160
|
+
const timestamp = this.safeInteger(orderbook, 'timestamp');
|
|
161
|
+
if (timestamp === undefined) {
|
|
162
|
+
orderbook.cache.push(message);
|
|
163
|
+
}
|
|
164
|
+
else {
|
|
165
|
+
try {
|
|
166
|
+
const ts = this.safeInteger(message, 'ts');
|
|
167
|
+
if (ts > timestamp) {
|
|
168
|
+
this.handleOrderBookMessage(client, message, orderbook);
|
|
169
|
+
client.resolve(orderbook, topic);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
catch (e) {
|
|
173
|
+
delete this.orderbooks[symbol];
|
|
174
|
+
delete client.subscriptions[topic];
|
|
175
|
+
client.reject(e, topic);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
else {
|
|
180
|
+
if (!(symbol in this.orderbooks)) {
|
|
181
|
+
const defaultLimit = this.safeInteger(this.options, 'watchOrderBookLimit', 1000);
|
|
182
|
+
const subscription = client.subscriptions[topic];
|
|
183
|
+
const limit = this.safeInteger(subscription, 'limit', defaultLimit);
|
|
184
|
+
this.orderbooks[symbol] = this.orderBook({}, limit);
|
|
185
|
+
}
|
|
186
|
+
const orderbook = this.orderbooks[symbol];
|
|
187
|
+
const timestamp = this.safeInteger(message, 'ts');
|
|
188
|
+
const snapshot = this.parseOrderBook(data, symbol, timestamp, 'bids', 'asks');
|
|
189
|
+
orderbook.reset(snapshot);
|
|
190
|
+
client.resolve(orderbook, topic);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
handleOrderBookSubscription(client, message, subscription) {
|
|
194
|
+
const defaultLimit = this.safeInteger(this.options, 'watchOrderBookLimit', 1000);
|
|
195
|
+
const limit = this.safeInteger(subscription, 'limit', defaultLimit);
|
|
196
|
+
const symbol = this.safeString(subscription, 'symbol'); // watchOrderBook
|
|
197
|
+
if (symbol in this.orderbooks) {
|
|
198
|
+
delete this.orderbooks[symbol];
|
|
139
199
|
}
|
|
140
|
-
|
|
200
|
+
this.orderbooks[symbol] = this.orderBook({}, limit);
|
|
201
|
+
this.spawn(this.fetchOrderBookSnapshot, client, message, subscription);
|
|
202
|
+
}
|
|
203
|
+
async fetchOrderBookSnapshot(client, message, subscription) {
|
|
204
|
+
const symbol = this.safeString(subscription, 'symbol');
|
|
205
|
+
const messageHash = this.safeString(message, 'topic');
|
|
206
|
+
try {
|
|
207
|
+
const defaultLimit = this.safeInteger(this.options, 'watchOrderBookLimit', 1000);
|
|
208
|
+
const limit = this.safeInteger(subscription, 'limit', defaultLimit);
|
|
209
|
+
const params = this.safeValue(subscription, 'params');
|
|
210
|
+
const snapshot = await this.fetchRestOrderBookSafe(symbol, limit, params);
|
|
211
|
+
if (this.safeValue(this.orderbooks, symbol) === undefined) {
|
|
212
|
+
// if the orderbook is dropped before the snapshot is received
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
const orderbook = this.orderbooks[symbol];
|
|
216
|
+
orderbook.reset(snapshot);
|
|
217
|
+
const messages = orderbook.cache;
|
|
218
|
+
for (let i = 0; i < messages.length; i++) {
|
|
219
|
+
const messageItem = messages[i];
|
|
220
|
+
const ts = this.safeInteger(messageItem, 'ts');
|
|
221
|
+
if (ts < orderbook['timestamp']) {
|
|
222
|
+
continue;
|
|
223
|
+
}
|
|
224
|
+
else {
|
|
225
|
+
this.handleOrderBookMessage(client, messageItem, orderbook);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
this.orderbooks[symbol] = orderbook;
|
|
229
|
+
client.resolve(orderbook, messageHash);
|
|
230
|
+
}
|
|
231
|
+
catch (e) {
|
|
232
|
+
delete client.subscriptions[messageHash];
|
|
233
|
+
client.reject(e, messageHash);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
handleOrderBookMessage(client, message, orderbook) {
|
|
237
|
+
const data = this.safeDict(message, 'data');
|
|
238
|
+
this.handleDeltas(orderbook['asks'], this.safeValue(data, 'asks', []));
|
|
239
|
+
this.handleDeltas(orderbook['bids'], this.safeValue(data, 'bids', []));
|
|
141
240
|
const timestamp = this.safeInteger(message, 'ts');
|
|
142
|
-
|
|
143
|
-
orderbook.
|
|
144
|
-
|
|
241
|
+
orderbook['timestamp'] = timestamp;
|
|
242
|
+
orderbook['datetime'] = this.iso8601(timestamp);
|
|
243
|
+
return orderbook;
|
|
244
|
+
}
|
|
245
|
+
handleDelta(bookside, delta) {
|
|
246
|
+
const price = this.safeFloat2(delta, 'price', 0);
|
|
247
|
+
const amount = this.safeFloat2(delta, 'quantity', 1);
|
|
248
|
+
bookside.store(price, amount);
|
|
249
|
+
}
|
|
250
|
+
handleDeltas(bookside, deltas) {
|
|
251
|
+
for (let i = 0; i < deltas.length; i++) {
|
|
252
|
+
this.handleDelta(bookside, deltas[i]);
|
|
253
|
+
}
|
|
145
254
|
}
|
|
146
255
|
async watchTicker(symbol, params = {}) {
|
|
147
256
|
/**
|
|
@@ -1064,6 +1173,7 @@ export default class woo extends wooRest {
|
|
|
1064
1173
|
'pong': this.handlePong,
|
|
1065
1174
|
'subscribe': this.handleSubscribe,
|
|
1066
1175
|
'orderbook': this.handleOrderBook,
|
|
1176
|
+
'orderbookupdate': this.handleOrderBook,
|
|
1067
1177
|
'ticker': this.handleTicker,
|
|
1068
1178
|
'tickers': this.handleTickers,
|
|
1069
1179
|
'kline': this.handleOHLCV,
|
|
@@ -1129,6 +1239,13 @@ export default class woo extends wooRest {
|
|
|
1129
1239
|
// "ts": 1657117712212
|
|
1130
1240
|
// }
|
|
1131
1241
|
//
|
|
1242
|
+
const id = this.safeString(message, 'id');
|
|
1243
|
+
const subscriptionsById = this.indexBy(client.subscriptions, 'id');
|
|
1244
|
+
const subscription = this.safeValue(subscriptionsById, id, {});
|
|
1245
|
+
const method = this.safeValue(subscription, 'method');
|
|
1246
|
+
if (method !== undefined) {
|
|
1247
|
+
method.call(this, client, message, subscription);
|
|
1248
|
+
}
|
|
1132
1249
|
return message;
|
|
1133
1250
|
}
|
|
1134
1251
|
handleAuth(client, message) {
|
package/package.json
CHANGED