ccxt 4.2.13 → 4.2.15
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 +781 -133
- package/dist/ccxt.browser.min.js +7 -7
- package/dist/cjs/ccxt.js +1 -1
- package/dist/cjs/js/ccxt.js +1 -1
- package/dist/cjs/js/src/base/Exchange.js +148 -1
- package/dist/cjs/js/src/bigone.js +36 -32
- package/dist/cjs/js/src/binance.js +108 -0
- package/dist/cjs/js/src/binanceus.js +8 -0
- package/dist/cjs/js/src/bingx.js +5 -0
- package/dist/cjs/js/src/bitget.js +4 -0
- package/dist/cjs/js/src/bybit.js +4 -0
- package/dist/cjs/js/src/coinex.js +3 -0
- package/dist/cjs/js/src/delta.js +7 -1
- package/dist/cjs/js/src/gate.js +5 -0
- package/dist/cjs/js/src/htx.js +126 -1
- package/dist/cjs/js/src/kraken.js +43 -9
- package/dist/cjs/js/src/kucoin.js +5 -0
- package/dist/cjs/js/src/kucoinfutures.js +131 -77
- package/dist/cjs/js/src/okx.js +9 -8
- package/dist/cjs/js/src/pro/htx.js +6 -1
- package/dist/cjs/js/src/pro/woo.js +126 -0
- package/dist/cjs/js/src/woo.js +6 -2
- package/js/ccxt.d.ts +1 -1
- package/js/ccxt.js +1 -1
- package/js/src/abstract/bigone.d.ts +1 -0
- package/js/src/abstract/kucoin.d.ts +4 -0
- package/js/src/abstract/kucoinfutures.d.ts +4 -0
- package/js/src/base/Exchange.d.ts +8 -0
- package/js/src/base/Exchange.js +148 -1
- package/js/src/bigone.js +36 -32
- package/js/src/binance.d.ts +9 -0
- package/js/src/binance.js +108 -0
- package/js/src/binanceus.js +8 -0
- package/js/src/bingx.js +5 -0
- package/js/src/bitget.js +4 -0
- package/js/src/bybit.js +4 -0
- package/js/src/coinex.js +3 -0
- package/js/src/delta.js +7 -1
- package/js/src/gate.js +5 -0
- package/js/src/htx.d.ts +9 -0
- package/js/src/htx.js +126 -1
- package/js/src/kraken.d.ts +1 -0
- package/js/src/kraken.js +43 -9
- package/js/src/kucoin.js +5 -0
- package/js/src/kucoinfutures.d.ts +4 -2
- package/js/src/kucoinfutures.js +131 -77
- package/js/src/okx.js +9 -8
- package/js/src/pro/htx.js +6 -1
- package/js/src/pro/woo.d.ts +5 -1
- package/js/src/pro/woo.js +127 -1
- package/js/src/woo.js +6 -2
- package/package.json +1 -1
package/js/src/kucoinfutures.js
CHANGED
|
@@ -36,10 +36,14 @@ export default class kucoinfutures extends kucoin {
|
|
|
36
36
|
'closePositions': false,
|
|
37
37
|
'createDepositAddress': true,
|
|
38
38
|
'createOrder': true,
|
|
39
|
+
'createOrders': true,
|
|
39
40
|
'createReduceOnlyOrder': true,
|
|
40
41
|
'createStopLimitOrder': true,
|
|
42
|
+
'createStopLossOrder': true,
|
|
41
43
|
'createStopMarketOrder': true,
|
|
42
44
|
'createStopOrder': true,
|
|
45
|
+
'createTakeProfitOrder': true,
|
|
46
|
+
'createTriggerOrder': true,
|
|
43
47
|
'fetchAccounts': true,
|
|
44
48
|
'fetchBalance': true,
|
|
45
49
|
'fetchBorrowRateHistories': false,
|
|
@@ -54,7 +58,7 @@ export default class kucoinfutures extends kucoin {
|
|
|
54
58
|
'fetchDepositWithdrawFees': false,
|
|
55
59
|
'fetchFundingHistory': true,
|
|
56
60
|
'fetchFundingRate': true,
|
|
57
|
-
'fetchFundingRateHistory':
|
|
61
|
+
'fetchFundingRateHistory': true,
|
|
58
62
|
'fetchIndexOHLCV': false,
|
|
59
63
|
'fetchIsolatedBorrowRate': false,
|
|
60
64
|
'fetchIsolatedBorrowRates': false,
|
|
@@ -1115,6 +1119,78 @@ export default class kucoinfutures extends kucoin {
|
|
|
1115
1119
|
* @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
|
|
1116
1120
|
*/
|
|
1117
1121
|
await this.loadMarkets();
|
|
1122
|
+
const market = this.market(symbol);
|
|
1123
|
+
const testOrder = this.safeValue(params, 'test', false);
|
|
1124
|
+
params = this.omit(params, 'test');
|
|
1125
|
+
const orderRequest = this.createContractOrderRequest(symbol, type, side, amount, price, params);
|
|
1126
|
+
let response = undefined;
|
|
1127
|
+
if (testOrder) {
|
|
1128
|
+
response = await this.futuresPrivatePostOrdersTest(orderRequest);
|
|
1129
|
+
}
|
|
1130
|
+
else {
|
|
1131
|
+
response = await this.futuresPrivatePostOrders(orderRequest);
|
|
1132
|
+
}
|
|
1133
|
+
//
|
|
1134
|
+
// {
|
|
1135
|
+
// "code": "200000",
|
|
1136
|
+
// "data": {
|
|
1137
|
+
// "orderId": "619717484f1d010001510cde",
|
|
1138
|
+
// },
|
|
1139
|
+
// }
|
|
1140
|
+
//
|
|
1141
|
+
const data = this.safeValue(response, 'data', {});
|
|
1142
|
+
return this.parseOrder(data, market);
|
|
1143
|
+
}
|
|
1144
|
+
async createOrders(orders, params = {}) {
|
|
1145
|
+
/**
|
|
1146
|
+
* @method
|
|
1147
|
+
* @name kucoinfutures#createOrders
|
|
1148
|
+
* @description create a list of trade orders
|
|
1149
|
+
* @see https://www.kucoin.com/docs/rest/futures-trading/orders/place-multiple-orders
|
|
1150
|
+
* @param {Array} orders list of orders to create, each object should contain the parameters required by createOrder, namely symbol, type, side, amount, price and params
|
|
1151
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
1152
|
+
* @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
|
|
1153
|
+
*/
|
|
1154
|
+
await this.loadMarkets();
|
|
1155
|
+
const ordersRequests = [];
|
|
1156
|
+
for (let i = 0; i < orders.length; i++) {
|
|
1157
|
+
const rawOrder = orders[i];
|
|
1158
|
+
const symbol = this.safeString(rawOrder, 'symbol');
|
|
1159
|
+
const market = this.market(symbol);
|
|
1160
|
+
const type = this.safeString(rawOrder, 'type');
|
|
1161
|
+
const side = this.safeString(rawOrder, 'side');
|
|
1162
|
+
const amount = this.safeValue(rawOrder, 'amount');
|
|
1163
|
+
const price = this.safeValue(rawOrder, 'price');
|
|
1164
|
+
const orderParams = this.safeValue(rawOrder, 'params', {});
|
|
1165
|
+
const orderRequest = this.createContractOrderRequest(market['id'], type, side, amount, price, orderParams);
|
|
1166
|
+
ordersRequests.push(orderRequest);
|
|
1167
|
+
}
|
|
1168
|
+
const response = await this.futuresPrivatePostOrdersMulti(ordersRequests);
|
|
1169
|
+
//
|
|
1170
|
+
// {
|
|
1171
|
+
// "code": "200000",
|
|
1172
|
+
// "data": [
|
|
1173
|
+
// {
|
|
1174
|
+
// "orderId": "135241412609331200",
|
|
1175
|
+
// "clientOid": "3d8fcc13-0b13-447f-ad30-4b3441e05213",
|
|
1176
|
+
// "symbol": "LTCUSDTM",
|
|
1177
|
+
// "code": "200000",
|
|
1178
|
+
// "msg": "success"
|
|
1179
|
+
// },
|
|
1180
|
+
// {
|
|
1181
|
+
// "orderId": "135241412747743234",
|
|
1182
|
+
// "clientOid": "b878c7ee-ae3e-4d63-a20b-038acbb7306f",
|
|
1183
|
+
// "symbol": "LTCUSDTM",
|
|
1184
|
+
// "code": "200000",
|
|
1185
|
+
// "msg": "success"
|
|
1186
|
+
// }
|
|
1187
|
+
// ]
|
|
1188
|
+
// }
|
|
1189
|
+
//
|
|
1190
|
+
const data = this.safeValue(response, 'data', []);
|
|
1191
|
+
return this.parseOrders(data);
|
|
1192
|
+
}
|
|
1193
|
+
createContractOrderRequest(symbol, type, side, amount, price = undefined, params = {}) {
|
|
1118
1194
|
const market = this.market(symbol);
|
|
1119
1195
|
// required param, cannot be used twice
|
|
1120
1196
|
const clientOrderId = this.safeString2(params, 'clientOid', 'clientOrderId', this.uuid());
|
|
@@ -1187,48 +1263,7 @@ export default class kucoinfutures extends kucoin {
|
|
|
1187
1263
|
}
|
|
1188
1264
|
}
|
|
1189
1265
|
params = this.omit(params, ['timeInForce', 'stopPrice', 'triggerPrice', 'stopLossPrice', 'takeProfitPrice']); // Time in force only valid for limit orders, exchange error when gtc for market orders
|
|
1190
|
-
|
|
1191
|
-
const testOrder = this.safeValue(params, 'test', false);
|
|
1192
|
-
params = this.omit(params, 'test');
|
|
1193
|
-
if (testOrder) {
|
|
1194
|
-
response = await this.futuresPrivatePostOrdersTest(this.extend(request, params));
|
|
1195
|
-
}
|
|
1196
|
-
else {
|
|
1197
|
-
response = await this.futuresPrivatePostOrders(this.extend(request, params));
|
|
1198
|
-
}
|
|
1199
|
-
//
|
|
1200
|
-
// {
|
|
1201
|
-
// "code": "200000",
|
|
1202
|
-
// "data": {
|
|
1203
|
-
// "orderId": "619717484f1d010001510cde",
|
|
1204
|
-
// },
|
|
1205
|
-
// }
|
|
1206
|
-
//
|
|
1207
|
-
const data = this.safeValue(response, 'data', {});
|
|
1208
|
-
return this.safeOrder({
|
|
1209
|
-
'id': this.safeString(data, 'orderId'),
|
|
1210
|
-
'clientOrderId': undefined,
|
|
1211
|
-
'timestamp': undefined,
|
|
1212
|
-
'datetime': undefined,
|
|
1213
|
-
'lastTradeTimestamp': undefined,
|
|
1214
|
-
'symbol': undefined,
|
|
1215
|
-
'type': undefined,
|
|
1216
|
-
'side': undefined,
|
|
1217
|
-
'price': undefined,
|
|
1218
|
-
'amount': undefined,
|
|
1219
|
-
'cost': undefined,
|
|
1220
|
-
'average': undefined,
|
|
1221
|
-
'filled': undefined,
|
|
1222
|
-
'remaining': undefined,
|
|
1223
|
-
'status': undefined,
|
|
1224
|
-
'fee': undefined,
|
|
1225
|
-
'trades': undefined,
|
|
1226
|
-
'timeInForce': undefined,
|
|
1227
|
-
'postOnly': undefined,
|
|
1228
|
-
'stopPrice': undefined,
|
|
1229
|
-
'triggerPrice': undefined,
|
|
1230
|
-
'info': response,
|
|
1231
|
-
}, market);
|
|
1266
|
+
return this.extend(request, params);
|
|
1232
1267
|
}
|
|
1233
1268
|
async cancelOrder(id, symbol = undefined, params = {}) {
|
|
1234
1269
|
/**
|
|
@@ -1701,10 +1736,26 @@ export default class kucoinfutures extends kucoin {
|
|
|
1701
1736
|
// "reduceOnly": false
|
|
1702
1737
|
// }
|
|
1703
1738
|
//
|
|
1739
|
+
// createOrder
|
|
1740
|
+
//
|
|
1741
|
+
// {
|
|
1742
|
+
// "orderId": "619717484f1d010001510cde"
|
|
1743
|
+
// }
|
|
1744
|
+
//
|
|
1745
|
+
// createOrders
|
|
1746
|
+
//
|
|
1747
|
+
// {
|
|
1748
|
+
// "orderId": "80465574458560512",
|
|
1749
|
+
// "clientOid": "5c52e11203aa677f33e491",
|
|
1750
|
+
// "symbol": "ETHUSDTM",
|
|
1751
|
+
// "code": "200000",
|
|
1752
|
+
// "msg": "success"
|
|
1753
|
+
// }
|
|
1754
|
+
//
|
|
1704
1755
|
const marketId = this.safeString(order, 'symbol');
|
|
1705
1756
|
market = this.safeMarket(marketId, market);
|
|
1706
1757
|
const symbol = market['symbol'];
|
|
1707
|
-
const orderId = this.
|
|
1758
|
+
const orderId = this.safeString2(order, 'id', 'orderId');
|
|
1708
1759
|
const type = this.safeString(order, 'type');
|
|
1709
1760
|
const timestamp = this.safeInteger(order, 'createdAt');
|
|
1710
1761
|
const datetime = this.iso8601(timestamp);
|
|
@@ -1731,9 +1782,12 @@ export default class kucoinfutures extends kucoin {
|
|
|
1731
1782
|
// precision reported by their api is 8 d.p.
|
|
1732
1783
|
// const average = Precise.stringDiv (cost, Precise.stringMul (filled, market['contractSize']));
|
|
1733
1784
|
// bool
|
|
1734
|
-
const isActive = this.safeValue(order, 'isActive'
|
|
1785
|
+
const isActive = this.safeValue(order, 'isActive');
|
|
1735
1786
|
const cancelExist = this.safeValue(order, 'cancelExist', false);
|
|
1736
|
-
let status =
|
|
1787
|
+
let status = undefined;
|
|
1788
|
+
if (isActive !== undefined) {
|
|
1789
|
+
status = isActive ? 'open' : 'closed';
|
|
1790
|
+
}
|
|
1737
1791
|
status = cancelExist ? 'canceled' : status;
|
|
1738
1792
|
let fee = undefined;
|
|
1739
1793
|
if (feeCost !== undefined) {
|
|
@@ -2378,62 +2432,62 @@ export default class kucoinfutures extends kucoin {
|
|
|
2378
2432
|
/**
|
|
2379
2433
|
* @method
|
|
2380
2434
|
* @name kucoinfutures#fetchFundingRateHistory
|
|
2435
|
+
* @see https://www.kucoin.com/docs/rest/futures-trading/funding-fees/get-public-funding-history#request-url
|
|
2381
2436
|
* @description fetches historical funding rate prices
|
|
2382
2437
|
* @param {string} symbol unified symbol of the market to fetch the funding rate history for
|
|
2383
2438
|
* @param {int} [since] not used by kucuoinfutures
|
|
2384
2439
|
* @param {int} [limit] the maximum amount of [funding rate structures]{@link https://docs.ccxt.com/#/?id=funding-rate-history-structure} to fetch
|
|
2385
2440
|
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
2386
|
-
* @param {
|
|
2441
|
+
* @param {int} [params.until] end time in ms
|
|
2387
2442
|
* @returns {object[]} a list of [funding rate structures]{@link https://docs.ccxt.com/#/?id=funding-rate-history-structure}
|
|
2388
2443
|
*/
|
|
2389
2444
|
if (symbol === undefined) {
|
|
2390
2445
|
throw new ArgumentsRequired(this.id + ' fetchFundingRateHistory() requires a symbol argument');
|
|
2391
2446
|
}
|
|
2392
2447
|
await this.loadMarkets();
|
|
2393
|
-
let paginate = false;
|
|
2394
|
-
[paginate, params] = this.handleOptionAndParams(params, 'fetchFundingRateHistory', 'paginate');
|
|
2395
|
-
if (paginate) {
|
|
2396
|
-
return await this.fetchPaginatedCallDeterministic('fetchFundingRateHistory', symbol, since, limit, '8h', params);
|
|
2397
|
-
}
|
|
2398
2448
|
const market = this.market(symbol);
|
|
2399
2449
|
const request = {
|
|
2400
2450
|
'symbol': market['id'],
|
|
2451
|
+
'from': 0,
|
|
2452
|
+
'to': this.milliseconds(),
|
|
2401
2453
|
};
|
|
2402
|
-
|
|
2403
|
-
|
|
2454
|
+
const until = this.safeInteger2(params, 'until', 'till');
|
|
2455
|
+
params = this.omit(params, ['until', 'till']);
|
|
2456
|
+
if (since !== undefined) {
|
|
2457
|
+
request['from'] = since;
|
|
2458
|
+
if (until === undefined) {
|
|
2459
|
+
request['to'] = since + 1000 * 8 * 60 * 60 * 100;
|
|
2460
|
+
}
|
|
2461
|
+
}
|
|
2462
|
+
if (until !== undefined) {
|
|
2463
|
+
request['to'] = until;
|
|
2464
|
+
if (since === undefined) {
|
|
2465
|
+
request['to'] = until - 1000 * 8 * 60 * 60 * 100;
|
|
2466
|
+
}
|
|
2404
2467
|
}
|
|
2405
|
-
const response = await this.
|
|
2468
|
+
const response = await this.futuresPublicGetContractFundingRates(this.extend(request, params));
|
|
2406
2469
|
//
|
|
2407
|
-
//
|
|
2408
|
-
//
|
|
2409
|
-
//
|
|
2410
|
-
//
|
|
2411
|
-
//
|
|
2412
|
-
//
|
|
2413
|
-
//
|
|
2414
|
-
//
|
|
2415
|
-
//
|
|
2416
|
-
//
|
|
2417
|
-
// "timePoint": 1675108800000,
|
|
2418
|
-
// "value": 0.0001
|
|
2419
|
-
// },
|
|
2420
|
-
// ...
|
|
2421
|
-
// ],
|
|
2422
|
-
// "hasMore": true
|
|
2423
|
-
// }
|
|
2424
|
-
// }
|
|
2470
|
+
// {
|
|
2471
|
+
// "code": "200000",
|
|
2472
|
+
// "data": [
|
|
2473
|
+
// {
|
|
2474
|
+
// "symbol": "IDUSDTM",
|
|
2475
|
+
// "fundingRate": 2.26E-4,
|
|
2476
|
+
// "timepoint": 1702296000000
|
|
2477
|
+
// }
|
|
2478
|
+
// ]
|
|
2479
|
+
// }
|
|
2425
2480
|
//
|
|
2426
2481
|
const data = this.safeValue(response, 'data');
|
|
2427
|
-
|
|
2428
|
-
return this.parseFundingRateHistories(dataList, market, since, limit);
|
|
2482
|
+
return this.parseFundingRateHistories(data, market, since, limit);
|
|
2429
2483
|
}
|
|
2430
2484
|
parseFundingRateHistory(info, market = undefined) {
|
|
2431
|
-
const timestamp = this.safeInteger(info, '
|
|
2485
|
+
const timestamp = this.safeInteger(info, 'timepoint');
|
|
2432
2486
|
const marketId = this.safeString(info, 'symbol');
|
|
2433
2487
|
return {
|
|
2434
2488
|
'info': info,
|
|
2435
2489
|
'symbol': this.safeSymbol(marketId, market),
|
|
2436
|
-
'fundingRate': this.safeNumber(info, '
|
|
2490
|
+
'fundingRate': this.safeNumber(info, 'fundingRate'),
|
|
2437
2491
|
'timestamp': timestamp,
|
|
2438
2492
|
'datetime': this.iso8601(timestamp),
|
|
2439
2493
|
};
|
package/js/src/okx.js
CHANGED
|
@@ -43,12 +43,16 @@ export default class okx extends Exchange {
|
|
|
43
43
|
'createMarketSellOrderWithCost': true,
|
|
44
44
|
'createOrder': true,
|
|
45
45
|
'createOrders': true,
|
|
46
|
+
'createOrderWithTakeProfitAndStopLoss': true,
|
|
46
47
|
'createPostOnlyOrder': true,
|
|
47
48
|
'createReduceOnlyOrder': true,
|
|
48
49
|
'createStopLimitOrder': true,
|
|
50
|
+
'createStopLossOrder': true,
|
|
49
51
|
'createStopMarketOrder': true,
|
|
50
52
|
'createStopOrder': true,
|
|
53
|
+
'createTakeProfitOrder': true,
|
|
51
54
|
'createTrailingPercentOrder': true,
|
|
55
|
+
'createTriggerOrder': true,
|
|
52
56
|
'editOrder': true,
|
|
53
57
|
'fetchAccounts': true,
|
|
54
58
|
'fetchBalance': true,
|
|
@@ -2136,17 +2140,14 @@ export default class okx extends Exchange {
|
|
|
2136
2140
|
let defaultType = 'Candles';
|
|
2137
2141
|
if (since !== undefined) {
|
|
2138
2142
|
const now = this.milliseconds();
|
|
2139
|
-
const difference = now - since;
|
|
2140
2143
|
const durationInMilliseconds = duration * 1000;
|
|
2141
|
-
//
|
|
2142
|
-
|
|
2143
|
-
|
|
2144
|
-
if (difference > calc) {
|
|
2144
|
+
// switch to history candles if since is past the cutoff for current candles
|
|
2145
|
+
const historyBorder = now - ((1440 - 1) * durationInMilliseconds);
|
|
2146
|
+
if (since < historyBorder) {
|
|
2145
2147
|
defaultType = 'HistoryCandles';
|
|
2146
2148
|
}
|
|
2147
|
-
|
|
2148
|
-
request['
|
|
2149
|
-
request['after'] = this.sum(startTime, durationInMilliseconds * limit);
|
|
2149
|
+
request['before'] = since;
|
|
2150
|
+
request['after'] = this.sum(since, durationInMilliseconds * limit);
|
|
2150
2151
|
}
|
|
2151
2152
|
const until = this.safeInteger(params, 'until');
|
|
2152
2153
|
if (until !== undefined) {
|
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
|
}
|
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,12 +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,
|
|
57
|
+
'createTriggerOrder': true,
|
|
54
58
|
'fetchAccounts': true,
|
|
55
59
|
'fetchBalance': true,
|
|
56
60
|
'fetchCanceledOrders': false,
|
|
@@ -769,7 +773,7 @@ export default class woo extends Exchange {
|
|
|
769
773
|
async createTrailingAmountOrder(symbol, type, side, amount, price = undefined, trailingAmount = undefined, trailingTriggerPrice = undefined, params = {}) {
|
|
770
774
|
/**
|
|
771
775
|
* @method
|
|
772
|
-
* @name createTrailingAmountOrder
|
|
776
|
+
* @name woo#createTrailingAmountOrder
|
|
773
777
|
* @description create a trailing order by providing the symbol, type, side, amount, price and trailingAmount
|
|
774
778
|
* @param {string} symbol unified symbol of the market to create an order in
|
|
775
779
|
* @param {string} type 'market' or 'limit'
|
|
@@ -794,7 +798,7 @@ export default class woo extends Exchange {
|
|
|
794
798
|
async createTrailingPercentOrder(symbol, type, side, amount, price = undefined, trailingPercent = undefined, trailingTriggerPrice = undefined, params = {}) {
|
|
795
799
|
/**
|
|
796
800
|
* @method
|
|
797
|
-
* @name createTrailingPercentOrder
|
|
801
|
+
* @name woo#createTrailingPercentOrder
|
|
798
802
|
* @description create a trailing order by providing the symbol, type, side, amount, price and trailingPercent
|
|
799
803
|
* @param {string} symbol unified symbol of the market to create an order in
|
|
800
804
|
* @param {string} type 'market' or 'limit'
|
package/package.json
CHANGED