ccxt 4.2.14 → 4.2.16
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 +805 -184
- package/dist/ccxt.browser.min.js +3 -3
- package/dist/cjs/ccxt.js +1 -1
- package/dist/cjs/js/ccxt.js +3 -1
- package/dist/cjs/js/src/ascendex.js +11 -6
- package/dist/cjs/js/src/base/Exchange.js +12 -12
- package/dist/cjs/js/src/binance.js +2 -2
- package/dist/cjs/js/src/bingx.js +41 -6
- package/dist/cjs/js/src/bitget.js +3 -3
- package/dist/cjs/js/src/bitmex.js +3 -6
- package/dist/cjs/js/src/bybit.js +3 -3
- package/dist/cjs/js/src/coinex.js +3 -3
- package/dist/cjs/js/src/coinone.js +1 -1
- package/dist/cjs/js/src/gate.js +3 -3
- package/dist/cjs/js/src/htx.js +2 -2
- package/dist/cjs/js/src/kraken.js +24 -2
- package/dist/cjs/js/src/kucoin.js +1 -1
- package/dist/cjs/js/src/kucoinfutures.js +2 -2
- package/dist/cjs/js/src/okx.js +1 -1
- package/dist/cjs/js/src/phemex.js +28 -25
- package/dist/cjs/js/src/pro/coinone.js +411 -0
- package/dist/cjs/js/src/pro/htx.js +6 -1
- package/dist/cjs/js/src/pro/krakenfutures.js +7 -1
- package/dist/cjs/js/src/pro/woo.js +126 -0
- package/dist/cjs/js/src/woo.js +3 -3
- package/js/ccxt.d.ts +4 -1
- package/js/ccxt.js +3 -1
- package/js/src/ascendex.js +11 -6
- package/js/src/base/Exchange.js +12 -12
- package/js/src/binance.js +2 -2
- package/js/src/bingx.d.ts +1 -0
- package/js/src/bingx.js +42 -7
- package/js/src/bitget.js +3 -3
- package/js/src/bitmex.js +3 -6
- package/js/src/bybit.js +3 -3
- package/js/src/coinex.js +3 -3
- package/js/src/coinone.js +1 -1
- package/js/src/gate.js +3 -3
- package/js/src/htx.js +2 -2
- package/js/src/kraken.d.ts +1 -0
- package/js/src/kraken.js +24 -2
- package/js/src/kucoin.js +1 -1
- package/js/src/kucoinfutures.js +2 -2
- package/js/src/okx.js +1 -1
- package/js/src/phemex.js +28 -25
- package/js/src/pro/coinone.d.ts +21 -0
- package/js/src/pro/coinone.js +412 -0
- package/js/src/pro/htx.js +6 -1
- package/js/src/pro/krakenfutures.js +7 -1
- package/js/src/pro/woo.d.ts +5 -1
- package/js/src/pro/woo.js +127 -1
- package/js/src/woo.js +3 -3
- package/package.json +1 -1
- package/skip-tests.json +1 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import coinoneRest from '../coinone.js';
|
|
2
|
+
import type { Int, Market, OrderBook, Ticker, Trade } from '../base/types.js';
|
|
3
|
+
import Client from '../base/ws/Client.js';
|
|
4
|
+
export default class coinone extends coinoneRest {
|
|
5
|
+
describe(): any;
|
|
6
|
+
watchOrderBook(symbol: string, limit?: Int, params?: {}): Promise<OrderBook>;
|
|
7
|
+
handleOrderBook(client: any, message: any): void;
|
|
8
|
+
handleDelta(bookside: any, delta: any): void;
|
|
9
|
+
watchTicker(symbol: string, params?: {}): Promise<Ticker>;
|
|
10
|
+
handleTicker(client: Client, message: any): void;
|
|
11
|
+
parseWsTicker(ticker: any, market?: Market): Ticker;
|
|
12
|
+
watchTrades(symbol: string, since?: Int, limit?: Int, params?: {}): Promise<Trade[]>;
|
|
13
|
+
handleTrades(client: Client, message: any): void;
|
|
14
|
+
parseWsTrade(trade: any, market?: Market): Trade;
|
|
15
|
+
handleErrorMessage(client: Client, message: any): boolean;
|
|
16
|
+
handleMessage(client: Client, message: any): void;
|
|
17
|
+
ping(client: any): {
|
|
18
|
+
request_type: string;
|
|
19
|
+
};
|
|
20
|
+
handlePong(client: Client, message: any): any;
|
|
21
|
+
}
|
|
@@ -0,0 +1,412 @@
|
|
|
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 coinoneRest from '../coinone.js';
|
|
9
|
+
import { AuthenticationError } from '../base/errors.js';
|
|
10
|
+
import { ArrayCache } from '../base/ws/Cache.js';
|
|
11
|
+
// ---------------------------------------------------------------------------
|
|
12
|
+
export default class coinone extends coinoneRest {
|
|
13
|
+
describe() {
|
|
14
|
+
return this.deepExtend(super.describe(), {
|
|
15
|
+
'has': {
|
|
16
|
+
'ws': true,
|
|
17
|
+
'watchOrderBook': true,
|
|
18
|
+
'watchOrders': false,
|
|
19
|
+
'watchTrades': true,
|
|
20
|
+
'watchOHLCV': false,
|
|
21
|
+
'watchTicker': true,
|
|
22
|
+
'watchTickers': false,
|
|
23
|
+
},
|
|
24
|
+
'urls': {
|
|
25
|
+
'api': {
|
|
26
|
+
'ws': 'wss://stream.coinone.co.kr',
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
'options': {
|
|
30
|
+
'expiresIn': '',
|
|
31
|
+
'userId': '',
|
|
32
|
+
'wsSessionToken': '',
|
|
33
|
+
'watchOrderBook': {
|
|
34
|
+
'snapshotDelay': 6,
|
|
35
|
+
'snapshotMaxRetries': 3,
|
|
36
|
+
},
|
|
37
|
+
'tradesLimit': 1000,
|
|
38
|
+
'OHLCVLimit': 1000,
|
|
39
|
+
},
|
|
40
|
+
'exceptions': {
|
|
41
|
+
'exact': {
|
|
42
|
+
'4009': AuthenticationError,
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
'streaming': {
|
|
46
|
+
'ping': this.ping,
|
|
47
|
+
'keepAlive': 20000,
|
|
48
|
+
},
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
async watchOrderBook(symbol, limit = undefined, params = {}) {
|
|
52
|
+
/**
|
|
53
|
+
* @method
|
|
54
|
+
* @name coinone#watchOrderBook
|
|
55
|
+
* @description watches information on open orders with bid (buy) and ask (sell) prices, volumes and other data
|
|
56
|
+
* @see https://docs.coinone.co.kr/reference/public-websocket-orderbook
|
|
57
|
+
* @param {string} symbol unified symbol of the market to fetch the order book for
|
|
58
|
+
* @param {int} [limit] the maximum amount of order book entries to return
|
|
59
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
60
|
+
* @returns {object} A dictionary of [order book structures]{@link https://docs.ccxt.com/#/?id=order-book-structure} indexed by market symbols
|
|
61
|
+
*/
|
|
62
|
+
await this.loadMarkets();
|
|
63
|
+
const market = this.market(symbol);
|
|
64
|
+
const messageHash = 'orderbook:' + market['symbol'];
|
|
65
|
+
const url = this.urls['api']['ws'];
|
|
66
|
+
const request = {
|
|
67
|
+
'request_type': 'SUBSCRIBE',
|
|
68
|
+
'channel': 'ORDERBOOK',
|
|
69
|
+
'topic': {
|
|
70
|
+
'quote_currency': market['quote'],
|
|
71
|
+
'target_currency': market['base'],
|
|
72
|
+
},
|
|
73
|
+
};
|
|
74
|
+
const message = this.extend(request, params);
|
|
75
|
+
const orderbook = await this.watch(url, messageHash, message, messageHash);
|
|
76
|
+
return orderbook.limit();
|
|
77
|
+
}
|
|
78
|
+
handleOrderBook(client, message) {
|
|
79
|
+
//
|
|
80
|
+
// {
|
|
81
|
+
// "response_type": "DATA",
|
|
82
|
+
// "channel": "ORDERBOOK",
|
|
83
|
+
// "data": {
|
|
84
|
+
// "quote_currency": "KRW",
|
|
85
|
+
// "target_currency": "BTC",
|
|
86
|
+
// "timestamp": 1705288918649,
|
|
87
|
+
// "id": "1705288918649001",
|
|
88
|
+
// "asks": [
|
|
89
|
+
// {
|
|
90
|
+
// "price": "58412000",
|
|
91
|
+
// "qty": "0.59919807"
|
|
92
|
+
// }
|
|
93
|
+
// ],
|
|
94
|
+
// "bids": [
|
|
95
|
+
// {
|
|
96
|
+
// "price": "58292000",
|
|
97
|
+
// "qty": "0.1045"
|
|
98
|
+
// }
|
|
99
|
+
// ]
|
|
100
|
+
// }
|
|
101
|
+
// }
|
|
102
|
+
//
|
|
103
|
+
const data = this.safeValue(message, 'data', {});
|
|
104
|
+
const baseId = this.safeStringUpper(data, 'target_currency');
|
|
105
|
+
const quoteId = this.safeStringUpper(data, 'quote_currency');
|
|
106
|
+
const base = this.safeCurrencyCode(baseId);
|
|
107
|
+
const quote = this.safeCurrencyCode(quoteId);
|
|
108
|
+
const symbol = this.symbol(base + '/' + quote);
|
|
109
|
+
const timestamp = this.safeInteger(data, 'timestamp');
|
|
110
|
+
let orderbook = this.safeValue(this.orderbooks, symbol);
|
|
111
|
+
if (orderbook === undefined) {
|
|
112
|
+
orderbook = this.orderBook();
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
orderbook.reset();
|
|
116
|
+
}
|
|
117
|
+
orderbook['symbol'] = symbol;
|
|
118
|
+
const asks = this.safeValue(data, 'asks', []);
|
|
119
|
+
const bids = this.safeValue(data, 'bids', []);
|
|
120
|
+
this.handleDeltas(orderbook['asks'], asks);
|
|
121
|
+
this.handleDeltas(orderbook['bids'], bids);
|
|
122
|
+
orderbook['timestamp'] = timestamp;
|
|
123
|
+
orderbook['datetime'] = this.iso8601(timestamp);
|
|
124
|
+
const messageHash = 'orderbook:' + symbol;
|
|
125
|
+
this.orderbooks[symbol] = orderbook;
|
|
126
|
+
client.resolve(orderbook, messageHash);
|
|
127
|
+
}
|
|
128
|
+
handleDelta(bookside, delta) {
|
|
129
|
+
const bidAsk = this.parseBidAsk(delta, 'price', 'qty');
|
|
130
|
+
bookside.storeArray(bidAsk);
|
|
131
|
+
}
|
|
132
|
+
async watchTicker(symbol, params = {}) {
|
|
133
|
+
/**
|
|
134
|
+
* @method
|
|
135
|
+
* @name coinone#watchTicker
|
|
136
|
+
* @description watches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
|
|
137
|
+
* @see https://docs.coinone.co.kr/reference/public-websocket-ticker
|
|
138
|
+
* @param {string} symbol unified symbol of the market to fetch the ticker for
|
|
139
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
140
|
+
* @returns {object} a [ticker structure]{@link https://docs.ccxt.com/#/?id=ticker-structure}
|
|
141
|
+
*/
|
|
142
|
+
await this.loadMarkets();
|
|
143
|
+
const market = this.market(symbol);
|
|
144
|
+
const messageHash = 'ticker:' + market['symbol'];
|
|
145
|
+
const url = this.urls['api']['ws'];
|
|
146
|
+
const request = {
|
|
147
|
+
'request_type': 'SUBSCRIBE',
|
|
148
|
+
'channel': 'TICKER',
|
|
149
|
+
'topic': {
|
|
150
|
+
'quote_currency': market['quote'],
|
|
151
|
+
'target_currency': market['base'],
|
|
152
|
+
},
|
|
153
|
+
};
|
|
154
|
+
const message = this.extend(request, params);
|
|
155
|
+
return await this.watch(url, messageHash, message, messageHash);
|
|
156
|
+
}
|
|
157
|
+
handleTicker(client, message) {
|
|
158
|
+
//
|
|
159
|
+
// {
|
|
160
|
+
// "response_type": "DATA",
|
|
161
|
+
// "channel": "TICKER",
|
|
162
|
+
// "data": {
|
|
163
|
+
// "quote_currency": "KRW",
|
|
164
|
+
// "target_currency": "BTC",
|
|
165
|
+
// "timestamp": 1705301117198,
|
|
166
|
+
// "quote_volume": "19521465345.504",
|
|
167
|
+
// "target_volume": "334.81445168",
|
|
168
|
+
// "high": "58710000",
|
|
169
|
+
// "low": "57276000",
|
|
170
|
+
// "first": "57293000",
|
|
171
|
+
// "last": "58532000",
|
|
172
|
+
// "volume_power": "100",
|
|
173
|
+
// "ask_best_price": "58537000",
|
|
174
|
+
// "ask_best_qty": "0.1961",
|
|
175
|
+
// "bid_best_price": "58532000",
|
|
176
|
+
// "bid_best_qty": "0.00009258",
|
|
177
|
+
// "id": "1705301117198001",
|
|
178
|
+
// "yesterday_high": "59140000",
|
|
179
|
+
// "yesterday_low": "57273000",
|
|
180
|
+
// "yesterday_first": "58897000",
|
|
181
|
+
// "yesterday_last": "57301000",
|
|
182
|
+
// "yesterday_quote_volume": "12967227517.4262",
|
|
183
|
+
// "yesterday_target_volume": "220.09232233"
|
|
184
|
+
// }
|
|
185
|
+
// }
|
|
186
|
+
//
|
|
187
|
+
const data = this.safeValue(message, 'data', {});
|
|
188
|
+
const ticker = this.parseWsTicker(data);
|
|
189
|
+
const symbol = ticker['symbol'];
|
|
190
|
+
this.tickers[symbol] = ticker;
|
|
191
|
+
const messageHash = 'ticker:' + symbol;
|
|
192
|
+
client.resolve(this.tickers[symbol], messageHash);
|
|
193
|
+
}
|
|
194
|
+
parseWsTicker(ticker, market = undefined) {
|
|
195
|
+
//
|
|
196
|
+
// {
|
|
197
|
+
// "quote_currency": "KRW",
|
|
198
|
+
// "target_currency": "BTC",
|
|
199
|
+
// "timestamp": 1705301117198,
|
|
200
|
+
// "quote_volume": "19521465345.504",
|
|
201
|
+
// "target_volume": "334.81445168",
|
|
202
|
+
// "high": "58710000",
|
|
203
|
+
// "low": "57276000",
|
|
204
|
+
// "first": "57293000",
|
|
205
|
+
// "last": "58532000",
|
|
206
|
+
// "volume_power": "100",
|
|
207
|
+
// "ask_best_price": "58537000",
|
|
208
|
+
// "ask_best_qty": "0.1961",
|
|
209
|
+
// "bid_best_price": "58532000",
|
|
210
|
+
// "bid_best_qty": "0.00009258",
|
|
211
|
+
// "id": "1705301117198001",
|
|
212
|
+
// "yesterday_high": "59140000",
|
|
213
|
+
// "yesterday_low": "57273000",
|
|
214
|
+
// "yesterday_first": "58897000",
|
|
215
|
+
// "yesterday_last": "57301000",
|
|
216
|
+
// "yesterday_quote_volume": "12967227517.4262",
|
|
217
|
+
// "yesterday_target_volume": "220.09232233"
|
|
218
|
+
// }
|
|
219
|
+
//
|
|
220
|
+
const timestamp = this.safeInteger(ticker, 'timestamp');
|
|
221
|
+
const last = this.safeString(ticker, 'last');
|
|
222
|
+
const baseId = this.safeString(ticker, 'target_currency');
|
|
223
|
+
const quoteId = this.safeString(ticker, 'quote_currency');
|
|
224
|
+
const base = this.safeCurrencyCode(baseId);
|
|
225
|
+
const quote = this.safeCurrencyCode(quoteId);
|
|
226
|
+
const symbol = this.symbol(base + '/' + quote);
|
|
227
|
+
return this.safeTicker({
|
|
228
|
+
'symbol': symbol,
|
|
229
|
+
'timestamp': timestamp,
|
|
230
|
+
'datetime': this.iso8601(timestamp),
|
|
231
|
+
'high': this.safeString(ticker, 'high'),
|
|
232
|
+
'low': this.safeString(ticker, 'low'),
|
|
233
|
+
'bid': this.safeNumber(ticker, 'bid_best_price'),
|
|
234
|
+
'bidVolume': this.safeNumber(ticker, 'bid_best_qty'),
|
|
235
|
+
'ask': this.safeNumber(ticker, 'ask_best_price'),
|
|
236
|
+
'askVolume': this.safeNumber(ticker, 'ask_best_qty'),
|
|
237
|
+
'vwap': undefined,
|
|
238
|
+
'open': this.safeString(ticker, 'first'),
|
|
239
|
+
'close': last,
|
|
240
|
+
'last': last,
|
|
241
|
+
'previousClose': undefined,
|
|
242
|
+
'change': undefined,
|
|
243
|
+
'percentage': undefined,
|
|
244
|
+
'average': undefined,
|
|
245
|
+
'baseVolume': this.safeString(ticker, 'target_volume'),
|
|
246
|
+
'quoteVolume': this.safeString(ticker, 'quote_volume'),
|
|
247
|
+
'info': ticker,
|
|
248
|
+
}, market);
|
|
249
|
+
}
|
|
250
|
+
async watchTrades(symbol, since = undefined, limit = undefined, params = {}) {
|
|
251
|
+
/**
|
|
252
|
+
* @method
|
|
253
|
+
* @name coinone#watchTrades
|
|
254
|
+
* @description watches information on multiple trades made in a market
|
|
255
|
+
* @see https://docs.coinone.co.kr/reference/public-websocket-trade
|
|
256
|
+
* @param {string} symbol unified market symbol of the market trades were made in
|
|
257
|
+
* @param {int} [since] the earliest time in ms to fetch trades for
|
|
258
|
+
* @param {int} [limit] the maximum number of trade structures to retrieve
|
|
259
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
260
|
+
* @returns {object[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=trade-structure
|
|
261
|
+
*/
|
|
262
|
+
await this.loadMarkets();
|
|
263
|
+
const market = this.market(symbol);
|
|
264
|
+
const messageHash = 'trade:' + market['symbol'];
|
|
265
|
+
const url = this.urls['api']['ws'];
|
|
266
|
+
const request = {
|
|
267
|
+
'request_type': 'SUBSCRIBE',
|
|
268
|
+
'channel': 'TRADE',
|
|
269
|
+
'topic': {
|
|
270
|
+
'quote_currency': market['quote'],
|
|
271
|
+
'target_currency': market['base'],
|
|
272
|
+
},
|
|
273
|
+
};
|
|
274
|
+
const message = this.extend(request, params);
|
|
275
|
+
const trades = await this.watch(url, messageHash, message, messageHash);
|
|
276
|
+
if (this.newUpdates) {
|
|
277
|
+
limit = trades.getLimit(market['symbol'], limit);
|
|
278
|
+
}
|
|
279
|
+
return this.filterBySinceLimit(trades, since, limit, 'timestamp', true);
|
|
280
|
+
}
|
|
281
|
+
handleTrades(client, message) {
|
|
282
|
+
//
|
|
283
|
+
// {
|
|
284
|
+
// "response_type": "DATA",
|
|
285
|
+
// "channel": "TRADE",
|
|
286
|
+
// "data": {
|
|
287
|
+
// "quote_currency": "KRW",
|
|
288
|
+
// "target_currency": "BTC",
|
|
289
|
+
// "id": "1705303667916001",
|
|
290
|
+
// "timestamp": 1705303667916,
|
|
291
|
+
// "price": "58490000",
|
|
292
|
+
// "qty": "0.0008",
|
|
293
|
+
// "is_seller_maker": false
|
|
294
|
+
// }
|
|
295
|
+
// }
|
|
296
|
+
//
|
|
297
|
+
const data = this.safeValue(message, 'data', {});
|
|
298
|
+
const trade = this.parseWsTrade(data);
|
|
299
|
+
const symbol = trade['symbol'];
|
|
300
|
+
let stored = this.safeValue(this.trades, symbol);
|
|
301
|
+
if (stored === undefined) {
|
|
302
|
+
const limit = this.safeInteger(this.options, 'tradesLimit', 1000);
|
|
303
|
+
stored = new ArrayCache(limit);
|
|
304
|
+
this.trades[symbol] = stored;
|
|
305
|
+
}
|
|
306
|
+
stored.append(trade);
|
|
307
|
+
const messageHash = 'trade:' + symbol;
|
|
308
|
+
client.resolve(stored, messageHash);
|
|
309
|
+
}
|
|
310
|
+
parseWsTrade(trade, market = undefined) {
|
|
311
|
+
//
|
|
312
|
+
// {
|
|
313
|
+
// "quote_currency": "KRW",
|
|
314
|
+
// "target_currency": "BTC",
|
|
315
|
+
// "id": "1705303667916001",
|
|
316
|
+
// "timestamp": 1705303667916,
|
|
317
|
+
// "price": "58490000",
|
|
318
|
+
// "qty": "0.0008",
|
|
319
|
+
// "is_seller_maker": false
|
|
320
|
+
// }
|
|
321
|
+
//
|
|
322
|
+
const baseId = this.safeStringUpper(trade, 'target_currency');
|
|
323
|
+
const quoteId = this.safeStringUpper(trade, 'quote_currency');
|
|
324
|
+
const base = this.safeCurrencyCode(baseId);
|
|
325
|
+
const quote = this.safeCurrencyCode(quoteId);
|
|
326
|
+
const symbol = base + '/' + quote;
|
|
327
|
+
const timestamp = this.safeInteger(trade, 'timestamp');
|
|
328
|
+
market = this.safeMarket(symbol, market);
|
|
329
|
+
const isSellerMaker = this.safeValue(trade, 'is_seller_maker');
|
|
330
|
+
let side = undefined;
|
|
331
|
+
if (isSellerMaker !== undefined) {
|
|
332
|
+
side = isSellerMaker ? 'sell' : 'buy';
|
|
333
|
+
}
|
|
334
|
+
const priceString = this.safeString(trade, 'price');
|
|
335
|
+
const amountString = this.safeString(trade, 'qty');
|
|
336
|
+
return this.safeTrade({
|
|
337
|
+
'id': this.safeString(trade, 'id'),
|
|
338
|
+
'info': trade,
|
|
339
|
+
'timestamp': timestamp,
|
|
340
|
+
'datetime': this.iso8601(timestamp),
|
|
341
|
+
'order': undefined,
|
|
342
|
+
'symbol': market['symbol'],
|
|
343
|
+
'type': undefined,
|
|
344
|
+
'side': side,
|
|
345
|
+
'takerOrMaker': undefined,
|
|
346
|
+
'price': priceString,
|
|
347
|
+
'amount': amountString,
|
|
348
|
+
'cost': undefined,
|
|
349
|
+
'fee': undefined,
|
|
350
|
+
}, market);
|
|
351
|
+
}
|
|
352
|
+
handleErrorMessage(client, message) {
|
|
353
|
+
//
|
|
354
|
+
// {
|
|
355
|
+
// "response_type": "ERROR",
|
|
356
|
+
// "error_code": 160012,
|
|
357
|
+
// "message": "Invalid Topic"
|
|
358
|
+
// }
|
|
359
|
+
//
|
|
360
|
+
const type = this.safeString(message, 'response_type', '');
|
|
361
|
+
if (type === 'ERROR') {
|
|
362
|
+
return true;
|
|
363
|
+
}
|
|
364
|
+
return false;
|
|
365
|
+
}
|
|
366
|
+
handleMessage(client, message) {
|
|
367
|
+
if (this.handleErrorMessage(client, message)) {
|
|
368
|
+
return;
|
|
369
|
+
}
|
|
370
|
+
const type = this.safeString(message, 'response_type');
|
|
371
|
+
if (type === 'PONG') {
|
|
372
|
+
this.handlePong(client, message);
|
|
373
|
+
return;
|
|
374
|
+
}
|
|
375
|
+
if (type === 'DATA') {
|
|
376
|
+
const topic = this.safeString(message, 'channel', '');
|
|
377
|
+
const methods = {
|
|
378
|
+
'ORDERBOOK': this.handleOrderBook,
|
|
379
|
+
'TICKER': this.handleTicker,
|
|
380
|
+
'TRADE': this.handleTrades,
|
|
381
|
+
};
|
|
382
|
+
const exacMethod = this.safeValue(methods, topic);
|
|
383
|
+
if (exacMethod !== undefined) {
|
|
384
|
+
exacMethod.call(this, client, message);
|
|
385
|
+
return;
|
|
386
|
+
}
|
|
387
|
+
const keys = Object.keys(methods);
|
|
388
|
+
for (let i = 0; i < keys.length; i++) {
|
|
389
|
+
const key = keys[i];
|
|
390
|
+
if (topic.indexOf(keys[i]) >= 0) {
|
|
391
|
+
const method = methods[key];
|
|
392
|
+
method.call(this, client, message);
|
|
393
|
+
return;
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
ping(client) {
|
|
399
|
+
return {
|
|
400
|
+
'request_type': 'PING',
|
|
401
|
+
};
|
|
402
|
+
}
|
|
403
|
+
handlePong(client, message) {
|
|
404
|
+
//
|
|
405
|
+
// {
|
|
406
|
+
// "response_type":"PONG"
|
|
407
|
+
// }
|
|
408
|
+
//
|
|
409
|
+
client.lastPong = this.milliseconds();
|
|
410
|
+
return message;
|
|
411
|
+
}
|
|
412
|
+
}
|
package/js/src/pro/htx.js
CHANGED
|
@@ -933,11 +933,16 @@ export default class htx extends htxRest {
|
|
|
933
933
|
// inject trade in existing order by faking an order object
|
|
934
934
|
const orderId = this.safeString(parsedTrade, 'order');
|
|
935
935
|
const trades = [parsedTrade];
|
|
936
|
+
const status = this.parseOrderStatus(this.safeString2(data, 'orderStatus', 'status', 'closed'));
|
|
937
|
+
const filled = this.safeString(data, 'execAmt');
|
|
938
|
+
const remaining = this.safeString(data, 'remainAmt');
|
|
936
939
|
const order = {
|
|
937
940
|
'id': orderId,
|
|
938
941
|
'trades': trades,
|
|
939
|
-
'status':
|
|
942
|
+
'status': status,
|
|
940
943
|
'symbol': market['symbol'],
|
|
944
|
+
'filled': this.parseNumber(filled),
|
|
945
|
+
'remaining': this.parseNumber(remaining),
|
|
941
946
|
};
|
|
942
947
|
parsedOrder = order;
|
|
943
948
|
}
|
|
@@ -181,7 +181,13 @@ export default class krakenfutures extends krakenfuturesRest {
|
|
|
181
181
|
const name = this.safeString2(params, 'method', 'watchTickerMethod', method);
|
|
182
182
|
params = this.omit(params, ['watchTickerMethod', 'method']);
|
|
183
183
|
symbols = this.marketSymbols(symbols, undefined, false);
|
|
184
|
-
|
|
184
|
+
const ticker = await this.subscribePublic(name, symbols, params);
|
|
185
|
+
if (this.newUpdates) {
|
|
186
|
+
const tickers = {};
|
|
187
|
+
tickers[ticker['symbol']] = ticker;
|
|
188
|
+
return tickers;
|
|
189
|
+
}
|
|
190
|
+
return this.filterByArray(this.tickers, 'symbol', symbols);
|
|
185
191
|
}
|
|
186
192
|
async watchTrades(symbol = undefined, since = undefined, limit = undefined, params = {}) {
|
|
187
193
|
/**
|
package/js/src/pro/woo.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import wooRest from '../woo.js';
|
|
2
|
-
import type { Int, Str, Strings, OrderBook, Order, Trade, Ticker, Tickers, OHLCV, Balances } from '../base/types.js';
|
|
2
|
+
import type { Int, Str, Strings, OrderBook, Order, Trade, Ticker, Tickers, OHLCV, Balances, Position } from '../base/types.js';
|
|
3
3
|
import Client from '../base/ws/Client.js';
|
|
4
4
|
export default class woo extends wooRest {
|
|
5
5
|
describe(): any;
|
|
@@ -24,6 +24,10 @@ export default class woo extends wooRest {
|
|
|
24
24
|
parseWsOrder(order: any, market?: any): Order;
|
|
25
25
|
handleOrderUpdate(client: Client, message: any): void;
|
|
26
26
|
handleOrder(client: Client, message: any): void;
|
|
27
|
+
watchPositions(symbols?: Strings, since?: Int, limit?: Int, params?: {}): Promise<Position[]>;
|
|
28
|
+
setPositionsCache(client: Client, type: any, symbols?: Strings): void;
|
|
29
|
+
loadPositionsSnapshot(client: any, messageHash: any): Promise<void>;
|
|
30
|
+
handlePositions(client: any, message: any): void;
|
|
27
31
|
watchBalance(params?: {}): Promise<Balances>;
|
|
28
32
|
handleBalance(client: any, message: any): void;
|
|
29
33
|
handleMessage(client: Client, message: any): any;
|
package/js/src/pro/woo.js
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
// ----------------------------------------------------------------------------
|
|
8
8
|
import wooRest from '../woo.js';
|
|
9
9
|
import { ExchangeError, AuthenticationError } from '../base/errors.js';
|
|
10
|
-
import { ArrayCacheByTimestamp, ArrayCacheBySymbolById, ArrayCache } from '../base/ws/Cache.js';
|
|
10
|
+
import { ArrayCacheByTimestamp, ArrayCacheBySymbolById, ArrayCache, ArrayCacheBySymbolBySide } from '../base/ws/Cache.js';
|
|
11
11
|
import { Precise } from '../base/Precise.js';
|
|
12
12
|
import { sha256 } from '../static_dependencies/noble-hashes/sha256.js';
|
|
13
13
|
// ----------------------------------------------------------------------------
|
|
@@ -24,6 +24,7 @@ export default class woo extends wooRest {
|
|
|
24
24
|
'watchTicker': true,
|
|
25
25
|
'watchTickers': true,
|
|
26
26
|
'watchTrades': true,
|
|
27
|
+
'watchPositions': true,
|
|
27
28
|
},
|
|
28
29
|
'urls': {
|
|
29
30
|
'api': {
|
|
@@ -48,6 +49,10 @@ export default class woo extends wooRest {
|
|
|
48
49
|
'tradesLimit': 1000,
|
|
49
50
|
'ordersLimit': 1000,
|
|
50
51
|
'requestId': {},
|
|
52
|
+
'watchPositions': {
|
|
53
|
+
'fetchPositionsSnapshot': true,
|
|
54
|
+
'awaitPositionsSnapshot': true, // whether to wait for the positions snapshot before providing updates
|
|
55
|
+
},
|
|
51
56
|
},
|
|
52
57
|
'streaming': {
|
|
53
58
|
'ping': this.ping,
|
|
@@ -606,6 +611,126 @@ export default class woo extends wooRest {
|
|
|
606
611
|
client.resolve(this.orders, messageHashSymbol);
|
|
607
612
|
}
|
|
608
613
|
}
|
|
614
|
+
async watchPositions(symbols = undefined, since = undefined, limit = undefined, params = {}) {
|
|
615
|
+
/**
|
|
616
|
+
* @method
|
|
617
|
+
* @name woo#watchPositions
|
|
618
|
+
* @see https://docs.woo.org/#position-push
|
|
619
|
+
* @description watch all open positions
|
|
620
|
+
* @param {string[]|undefined} symbols list of unified market symbols
|
|
621
|
+
* @param {object} params extra parameters specific to the exchange API endpoint
|
|
622
|
+
* @returns {object[]} a list of [position structure]{@link https://docs.ccxt.com/en/latest/manual.html#position-structure}
|
|
623
|
+
*/
|
|
624
|
+
await this.loadMarkets();
|
|
625
|
+
let messageHash = '';
|
|
626
|
+
symbols = this.marketSymbols(symbols);
|
|
627
|
+
if (!this.isEmpty(symbols)) {
|
|
628
|
+
messageHash = '::' + symbols.join(',');
|
|
629
|
+
}
|
|
630
|
+
messageHash = 'positions' + messageHash;
|
|
631
|
+
const url = this.urls['api']['ws']['private'] + '/' + this.uid;
|
|
632
|
+
const client = this.client(url);
|
|
633
|
+
this.setPositionsCache(client, symbols);
|
|
634
|
+
const fetchPositionsSnapshot = this.handleOption('watchPositions', 'fetchPositionsSnapshot', true);
|
|
635
|
+
const awaitPositionsSnapshot = this.safeValue('watchPositions', 'awaitPositionsSnapshot', true);
|
|
636
|
+
if (fetchPositionsSnapshot && awaitPositionsSnapshot && this.positions === undefined) {
|
|
637
|
+
const snapshot = await client.future('fetchPositionsSnapshot');
|
|
638
|
+
return this.filterBySymbolsSinceLimit(snapshot, symbols, since, limit, true);
|
|
639
|
+
}
|
|
640
|
+
const request = {
|
|
641
|
+
'event': 'subscribe',
|
|
642
|
+
'topic': 'position',
|
|
643
|
+
};
|
|
644
|
+
const newPositions = await this.watchPrivate(messageHash, request, params);
|
|
645
|
+
if (this.newUpdates) {
|
|
646
|
+
return newPositions;
|
|
647
|
+
}
|
|
648
|
+
return this.filterBySymbolsSinceLimit(this.positions, symbols, since, limit, true);
|
|
649
|
+
}
|
|
650
|
+
setPositionsCache(client, type, symbols = undefined) {
|
|
651
|
+
const fetchPositionsSnapshot = this.handleOption('watchPositions', 'fetchPositionsSnapshot', false);
|
|
652
|
+
if (fetchPositionsSnapshot) {
|
|
653
|
+
const messageHash = 'fetchPositionsSnapshot';
|
|
654
|
+
if (!(messageHash in client.futures)) {
|
|
655
|
+
client.future(messageHash);
|
|
656
|
+
this.spawn(this.loadPositionsSnapshot, client, messageHash);
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
else {
|
|
660
|
+
this.positions = new ArrayCacheBySymbolBySide();
|
|
661
|
+
}
|
|
662
|
+
}
|
|
663
|
+
async loadPositionsSnapshot(client, messageHash) {
|
|
664
|
+
const positions = await this.fetchPositions();
|
|
665
|
+
this.positions = new ArrayCacheBySymbolBySide();
|
|
666
|
+
const cache = this.positions;
|
|
667
|
+
for (let i = 0; i < positions.length; i++) {
|
|
668
|
+
const position = positions[i];
|
|
669
|
+
const contracts = this.safeNumber(position, 'contracts', 0);
|
|
670
|
+
if (contracts > 0) {
|
|
671
|
+
cache.append(position);
|
|
672
|
+
}
|
|
673
|
+
}
|
|
674
|
+
// don't remove the future from the .futures cache
|
|
675
|
+
const future = client.futures[messageHash];
|
|
676
|
+
future.resolve(cache);
|
|
677
|
+
client.resolve(cache, 'positions');
|
|
678
|
+
}
|
|
679
|
+
handlePositions(client, message) {
|
|
680
|
+
//
|
|
681
|
+
// {
|
|
682
|
+
// "topic":"position",
|
|
683
|
+
// "ts":1705292345255,
|
|
684
|
+
// "data":{
|
|
685
|
+
// "positions":{
|
|
686
|
+
// "PERP_LTC_USDT":{
|
|
687
|
+
// "holding":1,
|
|
688
|
+
// "pendingLongQty":0,
|
|
689
|
+
// "pendingShortQty":0,
|
|
690
|
+
// "averageOpenPrice":71.53,
|
|
691
|
+
// "pnl24H":0,
|
|
692
|
+
// "fee24H":0.07153,
|
|
693
|
+
// "settlePrice":71.53,
|
|
694
|
+
// "markPrice":71.32098452065145,
|
|
695
|
+
// "version":7886,
|
|
696
|
+
// "openingTime":1705292304267,
|
|
697
|
+
// "pnl24HPercentage":0,
|
|
698
|
+
// "adlQuantile":1,
|
|
699
|
+
// "positionSide":"BOTH"
|
|
700
|
+
// }
|
|
701
|
+
// }
|
|
702
|
+
// }
|
|
703
|
+
// }
|
|
704
|
+
//
|
|
705
|
+
const data = this.safeValue(message, 'data', {});
|
|
706
|
+
const rawPositions = this.safeValue(data, 'positions', {});
|
|
707
|
+
const postitionsIds = Object.keys(rawPositions);
|
|
708
|
+
if (this.positions === undefined) {
|
|
709
|
+
this.positions = new ArrayCacheBySymbolBySide();
|
|
710
|
+
}
|
|
711
|
+
const cache = this.positions;
|
|
712
|
+
const newPositions = [];
|
|
713
|
+
for (let i = 0; i < postitionsIds.length; i++) {
|
|
714
|
+
const marketId = postitionsIds[i];
|
|
715
|
+
const market = this.safeMarket(marketId);
|
|
716
|
+
const rawPosition = rawPositions[marketId];
|
|
717
|
+
const position = this.parsePosition(rawPosition, market);
|
|
718
|
+
newPositions.push(position);
|
|
719
|
+
cache.append(position);
|
|
720
|
+
}
|
|
721
|
+
const messageHashes = this.findMessageHashes(client, 'positions::');
|
|
722
|
+
for (let i = 0; i < messageHashes.length; i++) {
|
|
723
|
+
const messageHash = messageHashes[i];
|
|
724
|
+
const parts = messageHash.split('::');
|
|
725
|
+
const symbolsString = parts[1];
|
|
726
|
+
const symbols = symbolsString.split(',');
|
|
727
|
+
const positions = this.filterByArray(newPositions, 'symbol', symbols, false);
|
|
728
|
+
if (!this.isEmpty(positions)) {
|
|
729
|
+
client.resolve(positions, messageHash);
|
|
730
|
+
}
|
|
731
|
+
}
|
|
732
|
+
client.resolve(newPositions, 'positions');
|
|
733
|
+
}
|
|
609
734
|
async watchBalance(params = {}) {
|
|
610
735
|
/**
|
|
611
736
|
* @method
|
|
@@ -689,6 +814,7 @@ export default class woo extends wooRest {
|
|
|
689
814
|
'executionreport': this.handleOrderUpdate,
|
|
690
815
|
'trade': this.handleTrade,
|
|
691
816
|
'balance': this.handleBalance,
|
|
817
|
+
'position': this.handlePositions,
|
|
692
818
|
};
|
|
693
819
|
const event = this.safeString(message, 'event');
|
|
694
820
|
let method = this.safeValue(methods, event);
|
package/js/src/woo.js
CHANGED
|
@@ -45,16 +45,16 @@ export default class woo extends Exchange {
|
|
|
45
45
|
'createMarketOrderWithCost': false,
|
|
46
46
|
'createMarketSellOrderWithCost': false,
|
|
47
47
|
'createOrder': true,
|
|
48
|
+
'createOrderWithTakeProfitAndStopLoss': true,
|
|
48
49
|
'createReduceOnlyOrder': true,
|
|
49
50
|
'createStopLimitOrder': false,
|
|
51
|
+
'createStopLossOrder': true,
|
|
50
52
|
'createStopMarketOrder': false,
|
|
51
53
|
'createStopOrder': false,
|
|
54
|
+
'createTakeProfitOrder': true,
|
|
52
55
|
'createTrailingAmountOrder': true,
|
|
53
56
|
'createTrailingPercentOrder': true,
|
|
54
57
|
'createTriggerOrder': true,
|
|
55
|
-
'createTakeProfitOrder': true,
|
|
56
|
-
'createStopLossOrder': true,
|
|
57
|
-
'createOrderWithTakeProfitAndStopLoss': true,
|
|
58
58
|
'fetchAccounts': true,
|
|
59
59
|
'fetchBalance': true,
|
|
60
60
|
'fetchCanceledOrders': false,
|