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