ccxt 4.3.22 → 4.3.24
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 +5 -5
- package/dist/cjs/ccxt.js +9 -6
- package/dist/cjs/src/base/Exchange.js +4 -3
- package/dist/cjs/src/binance.js +1 -1
- package/dist/cjs/src/bitrue.js +6 -1
- package/dist/cjs/src/coinbase.js +5 -0
- package/dist/cjs/src/coinbaseadvanced.js +17 -0
- package/dist/cjs/src/{coinbasepro.js → coinbaseexchange.js} +40 -40
- package/dist/cjs/src/coinex.js +198 -257
- package/dist/cjs/src/kucoin.js +1 -0
- package/dist/cjs/src/phemex.js +26 -9
- package/dist/cjs/src/pro/bitget.js +12 -3
- package/dist/cjs/src/pro/{coinbasepro.js → coinbaseexchange.js} +13 -13
- package/dist/cjs/src/pro/poloniexfutures.js +22 -17
- package/dist/cjs/src/probit.js +1 -20
- package/dist/cjs/src/whitebit.js +9 -0
- package/js/ccxt.d.ts +11 -8
- package/js/ccxt.js +8 -6
- package/js/src/abstract/coinbaseadvanced.d.ts +97 -0
- package/js/src/abstract/coinbaseadvanced.js +11 -0
- package/js/src/abstract/whitebit.d.ts +9 -0
- package/js/src/base/Exchange.js +4 -3
- package/js/src/binance.js +1 -1
- package/js/src/bitrue.js +6 -1
- package/js/src/coinbase.js +5 -0
- package/js/src/coinbaseadvanced.d.ts +4 -0
- package/js/src/coinbaseadvanced.js +18 -0
- package/js/src/{coinbasepro.d.ts → coinbaseexchange.d.ts} +3 -3
- package/js/src/{coinbasepro.js → coinbaseexchange.js} +39 -39
- package/js/src/coinex.d.ts +13 -13
- package/js/src/coinex.js +199 -258
- package/js/src/kucoin.js +1 -0
- package/js/src/phemex.d.ts +1 -0
- package/js/src/phemex.js +26 -9
- package/js/src/pro/bitget.js +12 -3
- package/js/src/pro/{coinbasepro.d.ts → coinbaseexchange.d.ts} +2 -2
- package/js/src/pro/{coinbasepro.js → coinbaseexchange.js} +12 -12
- package/js/src/pro/poloniexfutures.js +22 -17
- package/js/src/probit.js +1 -20
- package/js/src/whitebit.js +9 -0
- package/package.json +1 -1
- /package/dist/cjs/src/abstract/{coinbasepro.js → coinbaseexchange.js} +0 -0
- /package/js/src/abstract/{coinbasepro.d.ts → coinbaseexchange.d.ts} +0 -0
- /package/js/src/abstract/{coinbasepro.js → coinbaseexchange.js} +0 -0
package/dist/cjs/src/coinex.js
CHANGED
|
@@ -445,7 +445,9 @@ class coinex extends coinex$1 {
|
|
|
445
445
|
'fillResponseFromRequest': true,
|
|
446
446
|
},
|
|
447
447
|
'accountsById': {
|
|
448
|
-
'spot': '
|
|
448
|
+
'spot': 'SPOT',
|
|
449
|
+
'margin': 'MARGIN',
|
|
450
|
+
'swap': 'FUTURES',
|
|
449
451
|
},
|
|
450
452
|
'networks': {
|
|
451
453
|
'BEP20': 'BSC',
|
|
@@ -468,10 +470,53 @@ class coinex extends coinex$1 {
|
|
|
468
470
|
'36': errors.RequestTimeout,
|
|
469
471
|
'213': errors.RateLimitExceeded,
|
|
470
472
|
'107': errors.InsufficientFunds,
|
|
473
|
+
'158': errors.PermissionDenied,
|
|
471
474
|
'600': errors.OrderNotFound,
|
|
472
475
|
'601': errors.InvalidOrder,
|
|
473
476
|
'602': errors.InvalidOrder,
|
|
474
477
|
'606': errors.InvalidOrder,
|
|
478
|
+
'3008': errors.RequestTimeout,
|
|
479
|
+
'3109': errors.InsufficientFunds,
|
|
480
|
+
'3127': errors.InvalidOrder,
|
|
481
|
+
'3606': errors.InvalidOrder,
|
|
482
|
+
'3610': errors.ExchangeError,
|
|
483
|
+
'3612': errors.InvalidOrder,
|
|
484
|
+
'3613': errors.InvalidOrder,
|
|
485
|
+
'3614': errors.InvalidOrder,
|
|
486
|
+
'3615': errors.InvalidOrder,
|
|
487
|
+
'3616': errors.InvalidOrder,
|
|
488
|
+
'3617': errors.InvalidOrder,
|
|
489
|
+
'3618': errors.InvalidOrder,
|
|
490
|
+
'3619': errors.InvalidOrder,
|
|
491
|
+
'3620': errors.InvalidOrder,
|
|
492
|
+
'3621': errors.InvalidOrder,
|
|
493
|
+
'3622': errors.InvalidOrder,
|
|
494
|
+
'3627': errors.InvalidOrder,
|
|
495
|
+
'3628': errors.InvalidOrder,
|
|
496
|
+
'3629': errors.InvalidOrder,
|
|
497
|
+
'3632': errors.InvalidOrder,
|
|
498
|
+
'3633': errors.InvalidOrder,
|
|
499
|
+
'3634': errors.InvalidOrder,
|
|
500
|
+
'3635': errors.InvalidOrder,
|
|
501
|
+
'4001': errors.ExchangeNotAvailable,
|
|
502
|
+
'4002': errors.RequestTimeout,
|
|
503
|
+
'4003': errors.ExchangeError,
|
|
504
|
+
'4004': errors.BadRequest,
|
|
505
|
+
'4005': errors.AuthenticationError,
|
|
506
|
+
'4006': errors.AuthenticationError,
|
|
507
|
+
'4007': errors.PermissionDenied,
|
|
508
|
+
'4008': errors.AuthenticationError,
|
|
509
|
+
'4009': errors.ExchangeError,
|
|
510
|
+
'4010': errors.ExchangeError,
|
|
511
|
+
'4011': errors.PermissionDenied,
|
|
512
|
+
'4017': errors.ExchangeError,
|
|
513
|
+
'4115': errors.AccountSuspended,
|
|
514
|
+
'4117': errors.BadSymbol,
|
|
515
|
+
'4123': errors.RateLimitExceeded,
|
|
516
|
+
'4130': errors.ExchangeError,
|
|
517
|
+
'4158': errors.ExchangeError,
|
|
518
|
+
'4213': errors.RateLimitExceeded,
|
|
519
|
+
'4512': errors.PermissionDenied, // Insufficient sub-account permissions, please check.
|
|
475
520
|
},
|
|
476
521
|
'broad': {
|
|
477
522
|
'ip not allow visit': errors.PermissionDenied,
|
|
@@ -3608,7 +3653,11 @@ class coinex extends coinex$1 {
|
|
|
3608
3653
|
* @param {string} [params.marginMode] 'cross' or 'isolated' for fetching spot margin orders
|
|
3609
3654
|
* @returns {Order[]} a list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
|
|
3610
3655
|
*/
|
|
3611
|
-
|
|
3656
|
+
const openOrders = await this.fetchOrdersByStatus('pending', symbol, since, limit, params);
|
|
3657
|
+
for (let i = 0; i < openOrders.length; i++) {
|
|
3658
|
+
openOrders[i]['status'] = 'open';
|
|
3659
|
+
}
|
|
3660
|
+
return openOrders;
|
|
3612
3661
|
}
|
|
3613
3662
|
async fetchClosedOrders(symbol = undefined, since = undefined, limit = undefined, params = {}) {
|
|
3614
3663
|
/**
|
|
@@ -4394,8 +4443,8 @@ class coinex extends coinex$1 {
|
|
|
4394
4443
|
/**
|
|
4395
4444
|
* @method
|
|
4396
4445
|
* @name coinex#fetchFundingHistory
|
|
4397
|
-
* @description fetch the history of funding payments paid and received on this account
|
|
4398
|
-
* @see https://
|
|
4446
|
+
* @description fetch the history of funding fee payments paid and received on this account
|
|
4447
|
+
* @see https://docs.coinex.com/api/v2/futures/position/http/list-position-funding-history
|
|
4399
4448
|
* @param {string} symbol unified market symbol
|
|
4400
4449
|
* @param {int} [since] the earliest time in ms to fetch funding history for
|
|
4401
4450
|
* @param {int} [limit] the maximum number of funding history structures to retrieve
|
|
@@ -4405,54 +4454,47 @@ class coinex extends coinex$1 {
|
|
|
4405
4454
|
if (symbol === undefined) {
|
|
4406
4455
|
throw new errors.ArgumentsRequired(this.id + ' fetchFundingHistory() requires a symbol argument');
|
|
4407
4456
|
}
|
|
4408
|
-
limit = (limit === undefined) ? 100 : limit;
|
|
4409
4457
|
await this.loadMarkets();
|
|
4410
4458
|
const market = this.market(symbol);
|
|
4411
|
-
|
|
4459
|
+
let request = {
|
|
4412
4460
|
'market': market['id'],
|
|
4413
|
-
'
|
|
4414
|
-
// 'offset': 0,
|
|
4415
|
-
// 'end_time': 1638990636000,
|
|
4416
|
-
// 'windowtime': 1638990636000,
|
|
4461
|
+
'market_type': 'FUTURES',
|
|
4417
4462
|
};
|
|
4463
|
+
[request, params] = this.handleUntilOption('end_time', request, params);
|
|
4418
4464
|
if (since !== undefined) {
|
|
4419
4465
|
request['start_time'] = since;
|
|
4420
4466
|
}
|
|
4421
|
-
|
|
4467
|
+
if (limit !== undefined) {
|
|
4468
|
+
request['limit'] = limit;
|
|
4469
|
+
}
|
|
4470
|
+
const response = await this.v2PrivateGetFuturesPositionFundingHistory(this.extend(request, params));
|
|
4422
4471
|
//
|
|
4423
4472
|
// {
|
|
4424
4473
|
// "code": 0,
|
|
4425
|
-
// "data":
|
|
4426
|
-
//
|
|
4427
|
-
//
|
|
4428
|
-
//
|
|
4429
|
-
//
|
|
4430
|
-
//
|
|
4431
|
-
//
|
|
4432
|
-
//
|
|
4433
|
-
//
|
|
4434
|
-
//
|
|
4435
|
-
//
|
|
4436
|
-
//
|
|
4437
|
-
//
|
|
4438
|
-
//
|
|
4439
|
-
//
|
|
4440
|
-
//
|
|
4441
|
-
// "user_id": 3620173,
|
|
4442
|
-
// "value": "47.76294"
|
|
4443
|
-
// },
|
|
4444
|
-
// ]
|
|
4445
|
-
// },
|
|
4446
|
-
// "message": "OK"
|
|
4474
|
+
// "data": [
|
|
4475
|
+
// {
|
|
4476
|
+
// "ccy": "USDT",
|
|
4477
|
+
// "created_at": 1715673620183,
|
|
4478
|
+
// "funding_rate": "0",
|
|
4479
|
+
// "funding_value": "0",
|
|
4480
|
+
// "market": "BTCUSDT",
|
|
4481
|
+
// "market_type": "FUTURES",
|
|
4482
|
+
// "position_id": 306458800,
|
|
4483
|
+
// "side": "long"
|
|
4484
|
+
// },
|
|
4485
|
+
// ],
|
|
4486
|
+
// "message": "OK",
|
|
4487
|
+
// "pagination": {
|
|
4488
|
+
// "has_next": true
|
|
4489
|
+
// }
|
|
4447
4490
|
// }
|
|
4448
4491
|
//
|
|
4449
|
-
const data = this.
|
|
4450
|
-
const resultList = this.safeValue(data, 'records', []);
|
|
4492
|
+
const data = this.safeList(response, 'data', []);
|
|
4451
4493
|
const result = [];
|
|
4452
|
-
for (let i = 0; i <
|
|
4453
|
-
const entry =
|
|
4454
|
-
const timestamp = this.
|
|
4455
|
-
const currencyId = this.safeString(entry, '
|
|
4494
|
+
for (let i = 0; i < data.length; i++) {
|
|
4495
|
+
const entry = data[i];
|
|
4496
|
+
const timestamp = this.safeInteger(entry, 'created_at');
|
|
4497
|
+
const currencyId = this.safeString(entry, 'ccy');
|
|
4456
4498
|
const code = this.safeCurrencyCode(currencyId);
|
|
4457
4499
|
result.push({
|
|
4458
4500
|
'info': entry,
|
|
@@ -4461,7 +4503,7 @@ class coinex extends coinex$1 {
|
|
|
4461
4503
|
'timestamp': timestamp,
|
|
4462
4504
|
'datetime': this.iso8601(timestamp),
|
|
4463
4505
|
'id': this.safeNumber(entry, 'position_id'),
|
|
4464
|
-
'amount': this.safeNumber(entry, '
|
|
4506
|
+
'amount': this.safeNumber(entry, 'funding_value'),
|
|
4465
4507
|
});
|
|
4466
4508
|
}
|
|
4467
4509
|
return result;
|
|
@@ -4471,7 +4513,7 @@ class coinex extends coinex$1 {
|
|
|
4471
4513
|
* @method
|
|
4472
4514
|
* @name coinex#fetchFundingRate
|
|
4473
4515
|
* @description fetch the current funding rate
|
|
4474
|
-
* @see https://
|
|
4516
|
+
* @see https://docs.coinex.com/api/v2/futures/market/http/list-market-funding-rate
|
|
4475
4517
|
* @param {string} symbol unified market symbol
|
|
4476
4518
|
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
4477
4519
|
* @returns {object} a [funding rate structure]{@link https://docs.ccxt.com/#/?id=funding-rate-structure}
|
|
@@ -4484,93 +4526,63 @@ class coinex extends coinex$1 {
|
|
|
4484
4526
|
const request = {
|
|
4485
4527
|
'market': market['id'],
|
|
4486
4528
|
};
|
|
4487
|
-
const response = await this.
|
|
4529
|
+
const response = await this.v2PublicGetFuturesFundingRate(this.extend(request, params));
|
|
4488
4530
|
//
|
|
4489
4531
|
// {
|
|
4490
|
-
//
|
|
4491
|
-
// "data":
|
|
4492
|
-
//
|
|
4493
|
-
//
|
|
4494
|
-
//
|
|
4495
|
-
// "
|
|
4496
|
-
// "
|
|
4497
|
-
// "
|
|
4498
|
-
// "
|
|
4499
|
-
// "
|
|
4500
|
-
// "
|
|
4501
|
-
// "period": 86400,
|
|
4502
|
-
// "funding_time": 372,
|
|
4503
|
-
// "position_amount": "270.1956",
|
|
4504
|
-
// "funding_rate_last": "0.00022913",
|
|
4505
|
-
// "funding_rate_next": "0.00013158",
|
|
4506
|
-
// "funding_rate_predict": "0.00016552",
|
|
4507
|
-
// "insurance": "16045554.83969682659674035672",
|
|
4508
|
-
// "sign_price": "39652.48",
|
|
4509
|
-
// "index_price": "39648.44250000",
|
|
4510
|
-
// "sell_total": "22.3913",
|
|
4511
|
-
// "buy_total": "19.4498",
|
|
4512
|
-
// "buy_amount": "12.8942",
|
|
4513
|
-
// "sell": "39663.80",
|
|
4514
|
-
// "sell_amount": "0.9388"
|
|
4532
|
+
// "code": 0,
|
|
4533
|
+
// "data": [
|
|
4534
|
+
// {
|
|
4535
|
+
// "latest_funding_rate": "0",
|
|
4536
|
+
// "latest_funding_time": 1715731200000,
|
|
4537
|
+
// "mark_price": "61602.22",
|
|
4538
|
+
// "market": "BTCUSDT",
|
|
4539
|
+
// "max_funding_rate": "0.00375",
|
|
4540
|
+
// "min_funding_rate": "-0.00375",
|
|
4541
|
+
// "next_funding_rate": "0.00021074",
|
|
4542
|
+
// "next_funding_time": 1715760000000
|
|
4515
4543
|
// }
|
|
4516
|
-
//
|
|
4544
|
+
// ],
|
|
4517
4545
|
// "message": "OK"
|
|
4518
4546
|
// }
|
|
4519
4547
|
//
|
|
4520
|
-
const data = this.
|
|
4521
|
-
const
|
|
4522
|
-
|
|
4523
|
-
ticker['timestamp'] = timestamp; // avoid changing parseFundingRate signature
|
|
4524
|
-
return this.parseFundingRate(ticker, market);
|
|
4548
|
+
const data = this.safeList(response, 'data', []);
|
|
4549
|
+
const first = this.safeDict(data, 0, {});
|
|
4550
|
+
return this.parseFundingRate(first, market);
|
|
4525
4551
|
}
|
|
4526
4552
|
parseFundingRate(contract, market = undefined) {
|
|
4527
4553
|
//
|
|
4528
|
-
// fetchFundingRate
|
|
4554
|
+
// fetchFundingRate, fetchFundingRates
|
|
4529
4555
|
//
|
|
4530
4556
|
// {
|
|
4531
|
-
// "
|
|
4532
|
-
// "
|
|
4533
|
-
// "
|
|
4534
|
-
// "
|
|
4535
|
-
// "
|
|
4536
|
-
// "
|
|
4537
|
-
// "
|
|
4538
|
-
// "
|
|
4539
|
-
// "position_amount": "270.1956",
|
|
4540
|
-
// "funding_rate_last": "0.00022913",
|
|
4541
|
-
// "funding_rate_next": "0.00013158",
|
|
4542
|
-
// "funding_rate_predict": "0.00016552",
|
|
4543
|
-
// "insurance": "16045554.83969682659674035672",
|
|
4544
|
-
// "sign_price": "39652.48",
|
|
4545
|
-
// "index_price": "39648.44250000",
|
|
4546
|
-
// "sell_total": "22.3913",
|
|
4547
|
-
// "buy_total": "19.4498",
|
|
4548
|
-
// "buy_amount": "12.8942",
|
|
4549
|
-
// "sell": "39663.80",
|
|
4550
|
-
// "sell_amount": "0.9388"
|
|
4557
|
+
// "latest_funding_rate": "0",
|
|
4558
|
+
// "latest_funding_time": 1715731200000,
|
|
4559
|
+
// "mark_price": "61602.22",
|
|
4560
|
+
// "market": "BTCUSDT",
|
|
4561
|
+
// "max_funding_rate": "0.00375",
|
|
4562
|
+
// "min_funding_rate": "-0.00375",
|
|
4563
|
+
// "next_funding_rate": "0.00021074",
|
|
4564
|
+
// "next_funding_time": 1715760000000
|
|
4551
4565
|
// }
|
|
4552
4566
|
//
|
|
4553
|
-
const
|
|
4554
|
-
|
|
4555
|
-
const
|
|
4556
|
-
const fundingHour = (timestamp + fundingDelta) / 3600000;
|
|
4557
|
-
const fundingTimestamp = Math.round(fundingHour) * 3600000;
|
|
4567
|
+
const currentFundingTimestamp = this.safeInteger(contract, 'latest_funding_time');
|
|
4568
|
+
const futureFundingTimestamp = this.safeInteger(contract, 'next_funding_time');
|
|
4569
|
+
const marketId = this.safeString(contract, 'market');
|
|
4558
4570
|
return {
|
|
4559
4571
|
'info': contract,
|
|
4560
|
-
'symbol': this.safeSymbol(undefined,
|
|
4561
|
-
'markPrice': this.safeNumber(contract, '
|
|
4562
|
-
'indexPrice':
|
|
4572
|
+
'symbol': this.safeSymbol(marketId, market, undefined, 'swap'),
|
|
4573
|
+
'markPrice': this.safeNumber(contract, 'mark_price'),
|
|
4574
|
+
'indexPrice': undefined,
|
|
4563
4575
|
'interestRate': undefined,
|
|
4564
4576
|
'estimatedSettlePrice': undefined,
|
|
4565
|
-
'timestamp':
|
|
4566
|
-
'datetime':
|
|
4567
|
-
'fundingRate': this.safeNumber(contract, '
|
|
4568
|
-
'fundingTimestamp':
|
|
4569
|
-
'fundingDatetime': this.iso8601(
|
|
4570
|
-
'nextFundingRate': this.safeNumber(contract, '
|
|
4571
|
-
'nextFundingTimestamp':
|
|
4572
|
-
'nextFundingDatetime':
|
|
4573
|
-
'previousFundingRate':
|
|
4577
|
+
'timestamp': undefined,
|
|
4578
|
+
'datetime': undefined,
|
|
4579
|
+
'fundingRate': this.safeNumber(contract, 'latest_funding_rate'),
|
|
4580
|
+
'fundingTimestamp': currentFundingTimestamp,
|
|
4581
|
+
'fundingDatetime': this.iso8601(currentFundingTimestamp),
|
|
4582
|
+
'nextFundingRate': this.safeNumber(contract, 'next_funding_rate'),
|
|
4583
|
+
'nextFundingTimestamp': futureFundingTimestamp,
|
|
4584
|
+
'nextFundingDatetime': this.iso8601(futureFundingTimestamp),
|
|
4585
|
+
'previousFundingRate': undefined,
|
|
4574
4586
|
'previousFundingTimestamp': undefined,
|
|
4575
4587
|
'previousFundingDatetime': undefined,
|
|
4576
4588
|
};
|
|
@@ -4580,13 +4592,14 @@ class coinex extends coinex$1 {
|
|
|
4580
4592
|
* @method
|
|
4581
4593
|
* @name coinex#fetchFundingRates
|
|
4582
4594
|
* @description fetch the current funding rates
|
|
4583
|
-
* @see https://
|
|
4595
|
+
* @see https://docs.coinex.com/api/v2/futures/market/http/list-market-funding-rate
|
|
4584
4596
|
* @param {string[]} symbols unified market symbols
|
|
4585
4597
|
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
4586
4598
|
* @returns {object[]} an array of [funding rate structures]{@link https://docs.ccxt.com/#/?id=funding-rate-structure}
|
|
4587
4599
|
*/
|
|
4588
4600
|
await this.loadMarkets();
|
|
4589
4601
|
symbols = this.marketSymbols(symbols);
|
|
4602
|
+
const request = {};
|
|
4590
4603
|
let market = undefined;
|
|
4591
4604
|
if (symbols !== undefined) {
|
|
4592
4605
|
const symbol = this.safeValue(symbols, 0);
|
|
@@ -4594,55 +4607,30 @@ class coinex extends coinex$1 {
|
|
|
4594
4607
|
if (!market['swap']) {
|
|
4595
4608
|
throw new errors.BadSymbol(this.id + ' fetchFundingRates() supports swap contracts only');
|
|
4596
4609
|
}
|
|
4610
|
+
const marketIds = this.marketIds(symbols);
|
|
4611
|
+
request['market'] = marketIds.join(',');
|
|
4597
4612
|
}
|
|
4598
|
-
const response = await this.
|
|
4613
|
+
const response = await this.v2PublicGetFuturesFundingRate(this.extend(request, params));
|
|
4599
4614
|
//
|
|
4600
4615
|
// {
|
|
4601
4616
|
// "code": 0,
|
|
4602
|
-
// "data":
|
|
4603
|
-
//
|
|
4604
|
-
//
|
|
4605
|
-
//
|
|
4606
|
-
// "
|
|
4607
|
-
//
|
|
4608
|
-
//
|
|
4609
|
-
//
|
|
4610
|
-
//
|
|
4611
|
-
//
|
|
4612
|
-
// "buy": "39663.79",
|
|
4613
|
-
// "period": 86400,
|
|
4614
|
-
// "funding_time": 372,
|
|
4615
|
-
// "position_amount": "270.1956",
|
|
4616
|
-
// "funding_rate_last": "0.00022913",
|
|
4617
|
-
// "funding_rate_next": "0.00013158",
|
|
4618
|
-
// "funding_rate_predict": "0.00016552",
|
|
4619
|
-
// "insurance": "16045554.83969682659674035672",
|
|
4620
|
-
// "sign_price": "39652.48",
|
|
4621
|
-
// "index_price": "39648.44250000",
|
|
4622
|
-
// "sell_total": "22.3913",
|
|
4623
|
-
// "buy_total": "19.4498",
|
|
4624
|
-
// "buy_amount": "12.8942",
|
|
4625
|
-
// "sell": "39663.80",
|
|
4626
|
-
// "sell_amount": "0.9388"
|
|
4627
|
-
// }
|
|
4617
|
+
// "data": [
|
|
4618
|
+
// {
|
|
4619
|
+
// "latest_funding_rate": "0",
|
|
4620
|
+
// "latest_funding_time": 1715731200000,
|
|
4621
|
+
// "mark_price": "61602.22",
|
|
4622
|
+
// "market": "BTCUSDT",
|
|
4623
|
+
// "max_funding_rate": "0.00375",
|
|
4624
|
+
// "min_funding_rate": "-0.00375",
|
|
4625
|
+
// "next_funding_rate": "0.00021074",
|
|
4626
|
+
// "next_funding_time": 1715760000000
|
|
4628
4627
|
// }
|
|
4629
|
-
//
|
|
4628
|
+
// ],
|
|
4630
4629
|
// "message": "OK"
|
|
4631
4630
|
// }
|
|
4632
|
-
|
|
4633
|
-
const
|
|
4634
|
-
const
|
|
4635
|
-
const result = [];
|
|
4636
|
-
const marketIds = Object.keys(tickers);
|
|
4637
|
-
for (let i = 0; i < marketIds.length; i++) {
|
|
4638
|
-
const marketId = marketIds[i];
|
|
4639
|
-
if (marketId.indexOf('_') === -1) { // skip _signprice and _indexprice
|
|
4640
|
-
const marketInner = this.safeMarket(marketId, undefined, undefined, 'swap');
|
|
4641
|
-
const ticker = tickers[marketId];
|
|
4642
|
-
ticker['timestamp'] = timestamp;
|
|
4643
|
-
result.push(this.parseFundingRate(ticker, marketInner));
|
|
4644
|
-
}
|
|
4645
|
-
}
|
|
4631
|
+
//
|
|
4632
|
+
const data = this.safeList(response, 'data', []);
|
|
4633
|
+
const result = this.parseFundingRates(data, market);
|
|
4646
4634
|
return this.filterByArray(result, 'symbol', symbols);
|
|
4647
4635
|
}
|
|
4648
4636
|
async withdraw(code, amount, address, tag = undefined, params = {}) {
|
|
@@ -4716,13 +4704,13 @@ class coinex extends coinex$1 {
|
|
|
4716
4704
|
/**
|
|
4717
4705
|
* @method
|
|
4718
4706
|
* @name coinex#fetchFundingRateHistory
|
|
4719
|
-
* @see https://viabtc.github.io/coinex_api_en_doc/futures/#docsfutures001_http038_funding_history
|
|
4720
4707
|
* @description fetches historical funding rate prices
|
|
4708
|
+
* @see https://docs.coinex.com/api/v2/futures/market/http/list-market-funding-rate-history
|
|
4721
4709
|
* @param {string} symbol unified symbol of the market to fetch the funding rate history for
|
|
4722
4710
|
* @param {int} [since] timestamp in ms of the earliest funding rate to fetch
|
|
4723
4711
|
* @param {int} [limit] the maximum amount of [funding rate structures]{@link https://docs.ccxt.com/#/?id=funding-rate-history-structure} to fetch
|
|
4724
4712
|
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
4725
|
-
* @param {boolean} [params.paginate] default false, when true will automatically paginate by calling this endpoint multiple times. See in the docs all the [
|
|
4713
|
+
* @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)
|
|
4726
4714
|
* @param {int} [params.until] timestamp in ms of the latest funding rate
|
|
4727
4715
|
* @returns {object[]} a list of [funding rate structures]{@link https://docs.ccxt.com/#/?id=funding-rate-history-structure}
|
|
4728
4716
|
*/
|
|
@@ -4735,52 +4723,46 @@ class coinex extends coinex$1 {
|
|
|
4735
4723
|
if (paginate) {
|
|
4736
4724
|
return await this.fetchPaginatedCallDeterministic('fetchFundingRateHistory', symbol, since, limit, '8h', params, 1000);
|
|
4737
4725
|
}
|
|
4738
|
-
if (limit === undefined) {
|
|
4739
|
-
limit = 100;
|
|
4740
|
-
}
|
|
4741
4726
|
const market = this.market(symbol);
|
|
4742
4727
|
let request = {
|
|
4743
4728
|
'market': market['id'],
|
|
4744
|
-
'limit': limit,
|
|
4745
|
-
'offset': 0,
|
|
4746
|
-
// 'end_time': 1638990636,
|
|
4747
4729
|
};
|
|
4748
4730
|
if (since !== undefined) {
|
|
4749
4731
|
request['start_time'] = since;
|
|
4750
4732
|
}
|
|
4733
|
+
if (limit !== undefined) {
|
|
4734
|
+
request['limit'] = limit;
|
|
4735
|
+
}
|
|
4751
4736
|
[request, params] = this.handleUntilOption('end_time', request, params);
|
|
4752
|
-
const response = await this.
|
|
4737
|
+
const response = await this.v2PublicGetFuturesFundingRateHistory(this.extend(request, params));
|
|
4753
4738
|
//
|
|
4754
4739
|
// {
|
|
4755
4740
|
// "code": 0,
|
|
4756
|
-
// "data":
|
|
4757
|
-
//
|
|
4758
|
-
//
|
|
4759
|
-
//
|
|
4760
|
-
//
|
|
4761
|
-
//
|
|
4762
|
-
//
|
|
4763
|
-
//
|
|
4764
|
-
//
|
|
4765
|
-
//
|
|
4766
|
-
//
|
|
4767
|
-
//
|
|
4768
|
-
// },
|
|
4769
|
-
// "message": "OK"
|
|
4741
|
+
// "data": [
|
|
4742
|
+
// {
|
|
4743
|
+
// "actual_funding_rate": "0",
|
|
4744
|
+
// "funding_time": 1715731221761,
|
|
4745
|
+
// "market": "BTCUSDT",
|
|
4746
|
+
// "theoretical_funding_rate": "0"
|
|
4747
|
+
// },
|
|
4748
|
+
// ],
|
|
4749
|
+
// "message": "OK",
|
|
4750
|
+
// "pagination": {
|
|
4751
|
+
// "has_next": true
|
|
4752
|
+
// }
|
|
4770
4753
|
// }
|
|
4771
4754
|
//
|
|
4772
|
-
const data = this.
|
|
4773
|
-
const result = this.safeValue(data, 'records', []);
|
|
4755
|
+
const data = this.safeList(response, 'data', []);
|
|
4774
4756
|
const rates = [];
|
|
4775
|
-
for (let i = 0; i <
|
|
4776
|
-
const entry =
|
|
4757
|
+
for (let i = 0; i < data.length; i++) {
|
|
4758
|
+
const entry = data[i];
|
|
4777
4759
|
const marketId = this.safeString(entry, 'market');
|
|
4778
4760
|
const symbolInner = this.safeSymbol(marketId, market, undefined, 'swap');
|
|
4779
|
-
const timestamp = this.
|
|
4761
|
+
const timestamp = this.safeInteger(entry, 'funding_time');
|
|
4780
4762
|
rates.push({
|
|
4781
4763
|
'info': entry,
|
|
4782
4764
|
'symbol': symbolInner,
|
|
4783
|
-
'fundingRate': this.safeNumber(entry, '
|
|
4765
|
+
'fundingRate': this.safeNumber(entry, 'actual_funding_rate'),
|
|
4784
4766
|
'timestamp': timestamp,
|
|
4785
4767
|
'datetime': this.iso8601(timestamp),
|
|
4786
4768
|
});
|
|
@@ -4907,43 +4889,45 @@ class coinex extends coinex$1 {
|
|
|
4907
4889
|
* @method
|
|
4908
4890
|
* @name coinex#transfer
|
|
4909
4891
|
* @description transfer currency internally between wallets on the same account
|
|
4910
|
-
* @see https://
|
|
4911
|
-
* @see https://viabtc.github.io/coinex_api_en_doc/spot/#docsspot002_account013_margin_transfer
|
|
4892
|
+
* @see https://docs.coinex.com/api/v2/assets/transfer/http/transfer
|
|
4912
4893
|
* @param {string} code unified currency code
|
|
4913
4894
|
* @param {float} amount amount to transfer
|
|
4914
4895
|
* @param {string} fromAccount account to transfer from
|
|
4915
4896
|
* @param {string} toAccount account to transfer to
|
|
4916
4897
|
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
4898
|
+
* @param {string} [params.symbol] unified ccxt symbol, required when either the fromAccount or toAccount is margin
|
|
4917
4899
|
* @returns {object} a [transfer structure]{@link https://docs.ccxt.com/#/?id=transfer-structure}
|
|
4918
4900
|
*/
|
|
4919
4901
|
await this.loadMarkets();
|
|
4920
4902
|
const currency = this.currency(code);
|
|
4921
4903
|
const amountToPrecision = this.currencyToPrecision(code, amount);
|
|
4904
|
+
const accountsById = this.safeDict(this.options, 'accountsById', {});
|
|
4905
|
+
const fromId = this.safeString(accountsById, fromAccount, fromAccount);
|
|
4906
|
+
const toId = this.safeString(accountsById, toAccount, toAccount);
|
|
4922
4907
|
const request = {
|
|
4908
|
+
'ccy': currency['id'],
|
|
4923
4909
|
'amount': amountToPrecision,
|
|
4924
|
-
'
|
|
4910
|
+
'from_account_type': fromId,
|
|
4911
|
+
'to_account_type': toId,
|
|
4925
4912
|
};
|
|
4926
|
-
|
|
4927
|
-
|
|
4928
|
-
|
|
4929
|
-
|
|
4930
|
-
|
|
4931
|
-
|
|
4932
|
-
request['
|
|
4933
|
-
response = await this.v1PrivatePostContractBalanceTransfer(this.extend(request, params));
|
|
4913
|
+
if ((fromAccount === 'margin') || (toAccount === 'margin')) {
|
|
4914
|
+
const symbol = this.safeString(params, 'symbol');
|
|
4915
|
+
if (symbol === undefined) {
|
|
4916
|
+
throw new errors.ArgumentsRequired(this.id + ' transfer() the symbol parameter must be defined for a margin account');
|
|
4917
|
+
}
|
|
4918
|
+
params = this.omit(params, 'symbol');
|
|
4919
|
+
request['market'] = this.marketId(symbol);
|
|
4934
4920
|
}
|
|
4935
|
-
|
|
4936
|
-
|
|
4937
|
-
const fromId = this.safeString(accountsById, fromAccount, fromAccount);
|
|
4938
|
-
const toId = this.safeString(accountsById, toAccount, toAccount);
|
|
4939
|
-
// fromAccount and toAccount must be integers for margin transfers
|
|
4940
|
-
// spot is 0, use fetchBalance() to find the margin account id
|
|
4941
|
-
request['from_account'] = parseInt(fromId);
|
|
4942
|
-
request['to_account'] = parseInt(toId);
|
|
4943
|
-
response = await this.v1PrivatePostMarginTransfer(this.extend(request, params));
|
|
4921
|
+
if ((fromAccount !== 'spot') && (toAccount !== 'spot')) {
|
|
4922
|
+
throw new errors.BadRequest(this.id + ' transfer() can only be between spot and swap, or spot and margin, either the fromAccount or toAccount must be spot');
|
|
4944
4923
|
}
|
|
4924
|
+
const response = await this.v2PrivatePostAssetsTransfer(this.extend(request, params));
|
|
4945
4925
|
//
|
|
4946
|
-
// {
|
|
4926
|
+
// {
|
|
4927
|
+
// "code": 0,
|
|
4928
|
+
// "data": {},
|
|
4929
|
+
// "message": "OK"
|
|
4930
|
+
// }
|
|
4947
4931
|
//
|
|
4948
4932
|
return this.extend(this.parseTransfer(response, currency), {
|
|
4949
4933
|
'amount': this.parseNumber(amountToPrecision),
|
|
@@ -4955,67 +4939,24 @@ class coinex extends coinex$1 {
|
|
|
4955
4939
|
const statuses = {
|
|
4956
4940
|
'0': 'ok',
|
|
4957
4941
|
'SUCCESS': 'ok',
|
|
4942
|
+
'OK': 'ok',
|
|
4958
4943
|
};
|
|
4959
4944
|
return this.safeString(statuses, status, status);
|
|
4960
4945
|
}
|
|
4961
4946
|
parseTransfer(transfer, currency = undefined) {
|
|
4962
|
-
|
|
4963
|
-
|
|
4964
|
-
|
|
4965
|
-
|
|
4966
|
-
|
|
4967
|
-
// "asset": "USDT",
|
|
4968
|
-
// "transfer_type": "transfer_out", // from swap to spot
|
|
4969
|
-
// "created_at": 1651633422
|
|
4970
|
-
// },
|
|
4971
|
-
//
|
|
4972
|
-
// fetchTransfers Margin
|
|
4973
|
-
//
|
|
4974
|
-
// {
|
|
4975
|
-
// "id": 7580062,
|
|
4976
|
-
// "updated_at": 1653684379,
|
|
4977
|
-
// "user_id": 3620173,
|
|
4978
|
-
// "from_account_id": 0,
|
|
4979
|
-
// "to_account_id": 1,
|
|
4980
|
-
// "asset": "BTC",
|
|
4981
|
-
// "amount": "0.00160829",
|
|
4982
|
-
// "balance": "0.00160829",
|
|
4983
|
-
// "transfer_type": "IN",
|
|
4984
|
-
// "status": "SUCCESS",
|
|
4985
|
-
// "created_at": 1653684379
|
|
4986
|
-
// },
|
|
4987
|
-
//
|
|
4988
|
-
const timestamp = this.safeTimestamp(transfer, 'created_at');
|
|
4989
|
-
const transferType = this.safeString(transfer, 'transfer_type');
|
|
4990
|
-
let fromAccount = undefined;
|
|
4991
|
-
let toAccount = undefined;
|
|
4992
|
-
if (transferType === 'transfer_out') {
|
|
4993
|
-
fromAccount = 'swap';
|
|
4994
|
-
toAccount = 'spot';
|
|
4995
|
-
}
|
|
4996
|
-
else if (transferType === 'transfer_in') {
|
|
4997
|
-
fromAccount = 'spot';
|
|
4998
|
-
toAccount = 'swap';
|
|
4999
|
-
}
|
|
5000
|
-
else if (transferType === 'IN') {
|
|
5001
|
-
fromAccount = 'spot';
|
|
5002
|
-
toAccount = 'margin';
|
|
5003
|
-
}
|
|
5004
|
-
else if (transferType === 'OUT') {
|
|
5005
|
-
fromAccount = 'margin';
|
|
5006
|
-
toAccount = 'spot';
|
|
5007
|
-
}
|
|
5008
|
-
const currencyId = this.safeString(transfer, 'asset');
|
|
5009
|
-
const currencyCode = this.safeCurrencyCode(currencyId, currency);
|
|
4947
|
+
const timestamp = this.safeInteger(transfer, 'created_at');
|
|
4948
|
+
const currencyId = this.safeString(transfer, 'ccy');
|
|
4949
|
+
const fromId = this.safeString(transfer, 'from_account_type');
|
|
4950
|
+
const toId = this.safeString(transfer, 'to_account_type');
|
|
4951
|
+
const accountsById = this.safeValue(this.options, 'accountsById', {});
|
|
5010
4952
|
return {
|
|
5011
|
-
'
|
|
5012
|
-
'id': this.safeString(transfer, 'id'),
|
|
4953
|
+
'id': undefined,
|
|
5013
4954
|
'timestamp': timestamp,
|
|
5014
4955
|
'datetime': this.iso8601(timestamp),
|
|
5015
|
-
'currency':
|
|
4956
|
+
'currency': this.safeCurrencyCode(currencyId, currency),
|
|
5016
4957
|
'amount': this.safeNumber(transfer, 'amount'),
|
|
5017
|
-
'fromAccount':
|
|
5018
|
-
'toAccount':
|
|
4958
|
+
'fromAccount': this.safeString(accountsById, fromId, fromId),
|
|
4959
|
+
'toAccount': this.safeString(accountsById, toId, toId),
|
|
5019
4960
|
'status': this.parseTransferStatus(this.safeString2(transfer, 'code', 'status')),
|
|
5020
4961
|
};
|
|
5021
4962
|
}
|