ccxt 4.4.59 → 4.4.60
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.min.js +3 -3
- package/dist/cjs/ccxt.js +1 -1
- package/dist/cjs/src/alpaca.js +9 -3
- package/dist/cjs/src/base/Exchange.js +4 -0
- package/dist/cjs/src/binance.js +86 -1
- package/dist/cjs/src/bitget.js +2 -1
- package/dist/cjs/src/bybit.js +5 -2
- package/dist/cjs/src/hollaex.js +1 -1
- package/dist/cjs/src/oxfun.js +1 -1
- package/dist/cjs/src/pro/xt.js +117 -1
- package/dist/cjs/src/xt.js +15 -0
- package/js/ccxt.d.ts +1 -1
- package/js/ccxt.js +1 -1
- package/js/src/alpaca.d.ts +1 -0
- package/js/src/alpaca.js +9 -3
- package/js/src/base/Exchange.d.ts +1 -0
- package/js/src/base/Exchange.js +4 -0
- package/js/src/binance.d.ts +11 -0
- package/js/src/binance.js +86 -1
- package/js/src/bitget.js +2 -1
- package/js/src/bybit.js +5 -2
- package/js/src/hollaex.js +1 -1
- package/js/src/oxfun.js +1 -1
- package/js/src/pro/xt.d.ts +16 -1
- package/js/src/pro/xt.js +118 -2
- package/js/src/xt.d.ts +2 -0
- package/js/src/xt.js +15 -0
- package/package.json +1 -1
package/js/src/bybit.js
CHANGED
|
@@ -6923,10 +6923,13 @@ export default class bybit extends Exchange {
|
|
|
6923
6923
|
// }
|
|
6924
6924
|
//
|
|
6925
6925
|
const timestamp = this.safeInteger(interest, 'timestamp');
|
|
6926
|
-
const
|
|
6926
|
+
const openInterest = this.safeNumber2(interest, 'open_interest', 'openInterest');
|
|
6927
|
+
// the openInterest is in the base asset for linear and quote asset for inverse
|
|
6928
|
+
const amount = market['linear'] ? openInterest : undefined;
|
|
6929
|
+
const value = market['inverse'] ? openInterest : undefined;
|
|
6927
6930
|
return this.safeOpenInterest({
|
|
6928
6931
|
'symbol': market['symbol'],
|
|
6929
|
-
'openInterestAmount':
|
|
6932
|
+
'openInterestAmount': amount,
|
|
6930
6933
|
'openInterestValue': value,
|
|
6931
6934
|
'timestamp': timestamp,
|
|
6932
6935
|
'datetime': this.iso8601(timestamp),
|
package/js/src/hollaex.js
CHANGED
|
@@ -1917,7 +1917,7 @@ export default class hollaex extends Exchange {
|
|
|
1917
1917
|
// "network":"https://api.hollaex.network"
|
|
1918
1918
|
// }
|
|
1919
1919
|
//
|
|
1920
|
-
const coins = this.
|
|
1920
|
+
const coins = this.safeDict(response, 'coins', {});
|
|
1921
1921
|
return this.parseDepositWithdrawFees(coins, codes, 'symbol');
|
|
1922
1922
|
}
|
|
1923
1923
|
normalizeNumberIfNeeded(number) {
|
package/js/src/oxfun.js
CHANGED
|
@@ -2950,7 +2950,7 @@ export default class oxfun extends Exchange {
|
|
|
2950
2950
|
'AccessKey': this.apiKey,
|
|
2951
2951
|
'Timestamp': datetime,
|
|
2952
2952
|
'Signature': signature,
|
|
2953
|
-
'Nonce': nonce,
|
|
2953
|
+
'Nonce': nonce.toString(),
|
|
2954
2954
|
};
|
|
2955
2955
|
}
|
|
2956
2956
|
return { 'url': url, 'method': method, 'body': body, 'headers': headers };
|
package/js/src/pro/xt.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import xtRest from '../xt.js';
|
|
2
|
-
import { Balances, Dict, Int, Market, OHLCV, Order, OrderBook, Str, Strings, Ticker, Tickers, Trade } from '../base/types.js';
|
|
2
|
+
import { Balances, Dict, Int, Market, OHLCV, Order, OrderBook, Position, Str, Strings, Ticker, Tickers, Trade } from '../base/types.js';
|
|
3
3
|
import Client from '../base/ws/Client.js';
|
|
4
4
|
export default class xt extends xtRest {
|
|
5
5
|
describe(): any;
|
|
@@ -134,6 +134,21 @@ export default class xt extends xtRest {
|
|
|
134
134
|
* @returns {object[]} a list of [balance structures]{@link https://docs.ccxt.com/#/?id=balance-structure}
|
|
135
135
|
*/
|
|
136
136
|
watchBalance(params?: {}): Promise<Balances>;
|
|
137
|
+
/**
|
|
138
|
+
* @method
|
|
139
|
+
* @name xt#watchPositions
|
|
140
|
+
* @see https://doc.xt.com/#futures_user_websocket_v2position
|
|
141
|
+
* @description watch all open positions
|
|
142
|
+
* @param {string[]|undefined} symbols list of unified market symbols
|
|
143
|
+
* @param {number} [since] since timestamp
|
|
144
|
+
* @param {number} [limit] limit
|
|
145
|
+
* @param {object} params extra parameters specific to the exchange API endpoint
|
|
146
|
+
* @returns {object[]} a list of [position structure]{@link https://docs.ccxt.com/en/latest/manual.html#position-structure}
|
|
147
|
+
*/
|
|
148
|
+
watchPositions(symbols?: Strings, since?: Int, limit?: Int, params?: {}): Promise<Position[]>;
|
|
149
|
+
setPositionsCache(client: Client): void;
|
|
150
|
+
loadPositionsSnapshot(client: any, messageHash: any): Promise<void>;
|
|
151
|
+
handlePosition(client: any, message: any): void;
|
|
137
152
|
handleTicker(client: Client, message: Dict): Dict;
|
|
138
153
|
handleTickers(client: Client, message: Dict): Dict;
|
|
139
154
|
handleOHLCV(client: Client, message: Dict): Dict;
|
package/js/src/pro/xt.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
// ---------------------------------------------------------------------------
|
|
8
8
|
import xtRest from '../xt.js';
|
|
9
|
-
import { ArrayCache, ArrayCacheBySymbolById, ArrayCacheByTimestamp } from '../base/ws/Cache.js';
|
|
9
|
+
import { ArrayCache, ArrayCacheBySymbolById, ArrayCacheBySymbolBySide, ArrayCacheByTimestamp } from '../base/ws/Cache.js';
|
|
10
10
|
// ---------------------------------------------------------------------------
|
|
11
11
|
export default class xt extends xtRest {
|
|
12
12
|
describe() {
|
|
@@ -22,7 +22,7 @@ export default class xt extends xtRest {
|
|
|
22
22
|
'watchBalance': true,
|
|
23
23
|
'watchOrders': true,
|
|
24
24
|
'watchMyTrades': true,
|
|
25
|
-
'watchPositions':
|
|
25
|
+
'watchPositions': true,
|
|
26
26
|
},
|
|
27
27
|
'urls': {
|
|
28
28
|
'api': {
|
|
@@ -42,6 +42,11 @@ export default class xt extends xtRest {
|
|
|
42
42
|
'watchTickers': {
|
|
43
43
|
'method': 'tickers', // agg_tickers (contract only)
|
|
44
44
|
},
|
|
45
|
+
'watchPositions': {
|
|
46
|
+
'type': 'swap',
|
|
47
|
+
'fetchPositionsSnapshot': true,
|
|
48
|
+
'awaitPositionsSnapshot': true,
|
|
49
|
+
},
|
|
45
50
|
},
|
|
46
51
|
'streaming': {
|
|
47
52
|
'keepAlive': 20000,
|
|
@@ -371,6 +376,116 @@ export default class xt extends xtRest {
|
|
|
371
376
|
const name = 'balance';
|
|
372
377
|
return await this.subscribe(name, 'private', 'watchBalance', undefined, undefined, params);
|
|
373
378
|
}
|
|
379
|
+
/**
|
|
380
|
+
* @method
|
|
381
|
+
* @name xt#watchPositions
|
|
382
|
+
* @see https://doc.xt.com/#futures_user_websocket_v2position
|
|
383
|
+
* @description watch all open positions
|
|
384
|
+
* @param {string[]|undefined} symbols list of unified market symbols
|
|
385
|
+
* @param {number} [since] since timestamp
|
|
386
|
+
* @param {number} [limit] limit
|
|
387
|
+
* @param {object} params extra parameters specific to the exchange API endpoint
|
|
388
|
+
* @returns {object[]} a list of [position structure]{@link https://docs.ccxt.com/en/latest/manual.html#position-structure}
|
|
389
|
+
*/
|
|
390
|
+
async watchPositions(symbols = undefined, since = undefined, limit = undefined, params = {}) {
|
|
391
|
+
await this.loadMarkets();
|
|
392
|
+
const url = this.urls['api']['ws']['contract'] + '/' + 'user';
|
|
393
|
+
const client = this.client(url);
|
|
394
|
+
this.setPositionsCache(client);
|
|
395
|
+
const fetchPositionsSnapshot = this.handleOption('watchPositions', 'fetchPositionsSnapshot', true);
|
|
396
|
+
const awaitPositionsSnapshot = this.handleOption('watchPositions', 'awaitPositionsSnapshot', true);
|
|
397
|
+
const cache = this.positions;
|
|
398
|
+
if (fetchPositionsSnapshot && awaitPositionsSnapshot && this.isEmpty(cache)) {
|
|
399
|
+
const snapshot = await client.future('fetchPositionsSnapshot');
|
|
400
|
+
return this.filterBySymbolsSinceLimit(snapshot, symbols, since, limit, true);
|
|
401
|
+
}
|
|
402
|
+
const name = 'position';
|
|
403
|
+
const newPositions = await this.subscribe(name, 'private', 'watchPositions', undefined, undefined, params);
|
|
404
|
+
if (this.newUpdates) {
|
|
405
|
+
return newPositions;
|
|
406
|
+
}
|
|
407
|
+
return this.filterBySymbolsSinceLimit(cache, symbols, since, limit, true);
|
|
408
|
+
}
|
|
409
|
+
setPositionsCache(client) {
|
|
410
|
+
if (this.positions === undefined) {
|
|
411
|
+
this.positions = new ArrayCacheBySymbolBySide();
|
|
412
|
+
}
|
|
413
|
+
const fetchPositionsSnapshot = this.handleOption('watchPositions', 'fetchPositionsSnapshot');
|
|
414
|
+
if (fetchPositionsSnapshot) {
|
|
415
|
+
const messageHash = 'fetchPositionsSnapshot';
|
|
416
|
+
if (!(messageHash in client.futures)) {
|
|
417
|
+
client.future(messageHash);
|
|
418
|
+
this.spawn(this.loadPositionsSnapshot, client, messageHash);
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
async loadPositionsSnapshot(client, messageHash) {
|
|
423
|
+
const positions = await this.fetchPositions(undefined);
|
|
424
|
+
this.positions = new ArrayCacheBySymbolBySide();
|
|
425
|
+
const cache = this.positions;
|
|
426
|
+
for (let i = 0; i < positions.length; i++) {
|
|
427
|
+
const position = positions[i];
|
|
428
|
+
const contracts = this.safeNumber(position, 'contracts', 0);
|
|
429
|
+
if (contracts > 0) {
|
|
430
|
+
cache.append(position);
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
// don't remove the future from the .futures cache
|
|
434
|
+
const future = client.futures[messageHash];
|
|
435
|
+
future.resolve(cache);
|
|
436
|
+
client.resolve(cache, 'position::contract');
|
|
437
|
+
}
|
|
438
|
+
handlePosition(client, message) {
|
|
439
|
+
//
|
|
440
|
+
// {
|
|
441
|
+
// topic: 'position',
|
|
442
|
+
// event: 'position',
|
|
443
|
+
// data: {
|
|
444
|
+
// accountId: 245296,
|
|
445
|
+
// accountType: 0,
|
|
446
|
+
// symbol: 'eth_usdt',
|
|
447
|
+
// contractType: 'PERPETUAL',
|
|
448
|
+
// positionType: 'CROSSED',
|
|
449
|
+
// positionSide: 'LONG',
|
|
450
|
+
// positionSize: '1',
|
|
451
|
+
// closeOrderSize: '0',
|
|
452
|
+
// availableCloseSize: '1',
|
|
453
|
+
// realizedProfit: '-0.0121',
|
|
454
|
+
// entryPrice: '2637.87',
|
|
455
|
+
// openOrderSize: '1',
|
|
456
|
+
// isolatedMargin: '2.63787',
|
|
457
|
+
// openOrderMarginFrozen: '2.78832014',
|
|
458
|
+
// underlyingType: 'U_BASED',
|
|
459
|
+
// leverage: 10,
|
|
460
|
+
// welfareAccount: false,
|
|
461
|
+
// profitFixedLatest: {},
|
|
462
|
+
// closeProfit: '0.0000',
|
|
463
|
+
// totalFee: '-0.0158',
|
|
464
|
+
// totalFundFee: '0.0037',
|
|
465
|
+
// markPrice: '2690.96'
|
|
466
|
+
// }
|
|
467
|
+
// }
|
|
468
|
+
//
|
|
469
|
+
if (this.positions === undefined) {
|
|
470
|
+
this.positions = new ArrayCacheBySymbolBySide();
|
|
471
|
+
}
|
|
472
|
+
const cache = this.positions;
|
|
473
|
+
const data = this.safeDict(message, 'data', {});
|
|
474
|
+
const position = this.parsePosition(data);
|
|
475
|
+
cache.append(position);
|
|
476
|
+
const messageHashes = this.findMessageHashes(client, 'position::contract');
|
|
477
|
+
for (let i = 0; i < messageHashes.length; i++) {
|
|
478
|
+
const messageHash = messageHashes[i];
|
|
479
|
+
const parts = messageHash.split('::');
|
|
480
|
+
const symbolsString = parts[1];
|
|
481
|
+
const symbols = symbolsString.split(',');
|
|
482
|
+
const positions = this.filterByArray([position], 'symbol', symbols, false);
|
|
483
|
+
if (!this.isEmpty(positions)) {
|
|
484
|
+
client.resolve(positions, messageHash);
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
client.resolve([position], 'position::contract');
|
|
488
|
+
}
|
|
374
489
|
handleTicker(client, message) {
|
|
375
490
|
//
|
|
376
491
|
// spot
|
|
@@ -1075,6 +1190,7 @@ export default class xt extends xtRest {
|
|
|
1075
1190
|
'agg_tickers': this.handleTickers,
|
|
1076
1191
|
'balance': this.handleBalance,
|
|
1077
1192
|
'order': this.handleOrder,
|
|
1193
|
+
'position': this.handlePosition,
|
|
1078
1194
|
};
|
|
1079
1195
|
let method = this.safeValue(methods, topic);
|
|
1080
1196
|
if (topic === 'trade') {
|
package/js/src/xt.d.ts
CHANGED
|
@@ -50,6 +50,8 @@ export default class xt extends Exchange {
|
|
|
50
50
|
* @param {int} [since] timestamp in ms of the earliest candle to fetch
|
|
51
51
|
* @param {int} [limit] the maximum amount of candles to fetch
|
|
52
52
|
* @param {object} params extra parameters specific to the xt api endpoint
|
|
53
|
+
* @param {int} [params.until] timestamp in ms of the latest candle to fetch
|
|
54
|
+
* @param {boolean} [params.paginate] default false, when true will automatically paginate by calling this endpoint multiple times. See in the docs all the [available parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
|
|
53
55
|
* @returns {int[][]} A list of candles ordered as timestamp, open, high, low, close, volume
|
|
54
56
|
*/
|
|
55
57
|
fetchOHLCV(symbol: string, timeframe?: string, since?: Int, limit?: Int, params?: {}): Promise<OHLCV[]>;
|
package/js/src/xt.js
CHANGED
|
@@ -1400,10 +1400,17 @@ export default class xt extends Exchange {
|
|
|
1400
1400
|
* @param {int} [since] timestamp in ms of the earliest candle to fetch
|
|
1401
1401
|
* @param {int} [limit] the maximum amount of candles to fetch
|
|
1402
1402
|
* @param {object} params extra parameters specific to the xt api endpoint
|
|
1403
|
+
* @param {int} [params.until] timestamp in ms of the latest candle to fetch
|
|
1404
|
+
* @param {boolean} [params.paginate] default false, when true will automatically paginate by calling this endpoint multiple times. See in the docs all the [available parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
|
|
1403
1405
|
* @returns {int[][]} A list of candles ordered as timestamp, open, high, low, close, volume
|
|
1404
1406
|
*/
|
|
1405
1407
|
async fetchOHLCV(symbol, timeframe = '1m', since = undefined, limit = undefined, params = {}) {
|
|
1406
1408
|
await this.loadMarkets();
|
|
1409
|
+
let paginate = false;
|
|
1410
|
+
[paginate, params] = this.handleOptionAndParams(params, 'fetchOHLCV', 'paginate', false);
|
|
1411
|
+
if (paginate) {
|
|
1412
|
+
return await this.fetchPaginatedCallDeterministic('fetchOHLCV', symbol, since, limit, timeframe, params, 1000);
|
|
1413
|
+
}
|
|
1407
1414
|
const market = this.market(symbol);
|
|
1408
1415
|
const request = {
|
|
1409
1416
|
'symbol': market['id'],
|
|
@@ -1415,6 +1422,14 @@ export default class xt extends Exchange {
|
|
|
1415
1422
|
if (limit !== undefined) {
|
|
1416
1423
|
request['limit'] = limit;
|
|
1417
1424
|
}
|
|
1425
|
+
else {
|
|
1426
|
+
request['limit'] = 1000;
|
|
1427
|
+
}
|
|
1428
|
+
const until = this.safeInteger(params, 'until');
|
|
1429
|
+
params = this.omit(params, ['until']);
|
|
1430
|
+
if (until !== undefined) {
|
|
1431
|
+
request['endTime'] = until;
|
|
1432
|
+
}
|
|
1418
1433
|
let response = undefined;
|
|
1419
1434
|
if (market['linear']) {
|
|
1420
1435
|
response = await this.publicLinearGetFutureMarketV1PublicQKline(this.extend(request, params));
|
package/package.json
CHANGED