ccxt 4.1.49 → 4.1.50
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 +1009 -140
- package/dist/ccxt.browser.min.js +6 -6
- package/dist/cjs/ccxt.js +1 -1
- package/dist/cjs/src/base/Exchange.js +6 -0
- package/dist/cjs/src/binance.js +76 -0
- package/dist/cjs/src/bybit.js +121 -0
- package/dist/cjs/src/cryptocom.js +1 -0
- package/dist/cjs/src/delta.js +149 -0
- package/dist/cjs/src/deribit.js +132 -0
- package/dist/cjs/src/gate.js +102 -4
- package/dist/cjs/src/htx.js +313 -135
- package/dist/cjs/src/okx.js +108 -0
- package/js/ccxt.d.ts +3 -3
- package/js/ccxt.js +1 -1
- package/js/src/abstract/htx.d.ts +1 -1
- package/js/src/abstract/huobi.d.ts +1 -1
- package/js/src/abstract/huobipro.d.ts +1 -1
- package/js/src/base/Exchange.d.ts +4 -2
- package/js/src/base/Exchange.js +6 -0
- package/js/src/base/types.d.ts +21 -0
- package/js/src/binance.d.ts +23 -1
- package/js/src/binance.js +76 -0
- package/js/src/bybit.d.ts +23 -1
- package/js/src/bybit.js +121 -0
- package/js/src/cryptocom.js +1 -0
- package/js/src/delta.d.ts +23 -1
- package/js/src/delta.js +149 -0
- package/js/src/deribit.d.ts +23 -1
- package/js/src/deribit.js +132 -0
- package/js/src/gate.d.ts +23 -1
- package/js/src/gate.js +102 -4
- package/js/src/htx.d.ts +4 -3
- package/js/src/htx.js +313 -135
- package/js/src/okx.d.ts +23 -1
- package/js/src/okx.js +108 -0
- package/package.json +1 -1
- package/skip-tests.json +2 -0
package/dist/cjs/src/htx.js
CHANGED
|
@@ -38,6 +38,7 @@ class htx extends htx$1 {
|
|
|
38
38
|
'cancelOrders': true,
|
|
39
39
|
'createDepositAddress': undefined,
|
|
40
40
|
'createOrder': true,
|
|
41
|
+
'createOrders': true,
|
|
41
42
|
'createReduceOnlyOrder': false,
|
|
42
43
|
'createStopLimitOrder': true,
|
|
43
44
|
'createStopMarketOrder': true,
|
|
@@ -632,7 +633,7 @@ class htx extends htx$1 {
|
|
|
632
633
|
// Future Trade Interface
|
|
633
634
|
'api/v1/contract-cancel-after': 1,
|
|
634
635
|
'api/v1/contract_order': 1,
|
|
635
|
-
'v1/contract_batchorder': 1,
|
|
636
|
+
'api/v1/contract_batchorder': 1,
|
|
636
637
|
'api/v1/contract_cancel': 1,
|
|
637
638
|
'api/v1/contract_cancelall': 1,
|
|
638
639
|
'api/v1/contract_switch_lever_rate': 1,
|
|
@@ -4705,7 +4706,41 @@ class htx extends htx$1 {
|
|
|
4705
4706
|
// "trade_partition": "USDT"
|
|
4706
4707
|
// }
|
|
4707
4708
|
//
|
|
4708
|
-
|
|
4709
|
+
// spot: createOrders
|
|
4710
|
+
//
|
|
4711
|
+
// [
|
|
4712
|
+
// {
|
|
4713
|
+
// "order-id": 936847569789079,
|
|
4714
|
+
// "client-order-id": "AA03022abc3a55e82c-0087-4fc2-beac-112fdebb1ee9"
|
|
4715
|
+
// },
|
|
4716
|
+
// {
|
|
4717
|
+
// "client-order-id": "AA03022abcdb3baefb-3cfa-4891-8009-082b3d46ca82",
|
|
4718
|
+
// "err-code": "account-frozen-balance-insufficient-error",
|
|
4719
|
+
// "err-msg": "trade account balance is not enough, left: `89`"
|
|
4720
|
+
// }
|
|
4721
|
+
// ]
|
|
4722
|
+
//
|
|
4723
|
+
// swap and future: createOrders
|
|
4724
|
+
//
|
|
4725
|
+
// [
|
|
4726
|
+
// {
|
|
4727
|
+
// "index": 2,
|
|
4728
|
+
// "err_code": 1047,
|
|
4729
|
+
// "err_msg": "Insufficient margin available."
|
|
4730
|
+
// },
|
|
4731
|
+
// {
|
|
4732
|
+
// "order_id": 1172923090632953857,
|
|
4733
|
+
// "index": 1,
|
|
4734
|
+
// "order_id_str": "1172923090632953857"
|
|
4735
|
+
// }
|
|
4736
|
+
// ]
|
|
4737
|
+
//
|
|
4738
|
+
const rejectedCreateOrders = this.safeString2(order, 'err_code', 'err-code');
|
|
4739
|
+
let status = this.parseOrderStatus(this.safeString2(order, 'state', 'status'));
|
|
4740
|
+
if (rejectedCreateOrders !== undefined) {
|
|
4741
|
+
status = 'rejected';
|
|
4742
|
+
}
|
|
4743
|
+
const id = this.safeStringN(order, ['id', 'order_id_str', 'order-id']);
|
|
4709
4744
|
let side = this.safeString(order, 'direction');
|
|
4710
4745
|
let type = this.safeString(order, 'order_price_type');
|
|
4711
4746
|
if ('type' in order) {
|
|
@@ -4713,7 +4748,6 @@ class htx extends htx$1 {
|
|
|
4713
4748
|
side = orderType[0];
|
|
4714
4749
|
type = orderType[1];
|
|
4715
4750
|
}
|
|
4716
|
-
const status = this.parseOrderStatus(this.safeString2(order, 'state', 'status'));
|
|
4717
4751
|
const marketId = this.safeString2(order, 'contract_code', 'symbol');
|
|
4718
4752
|
market = this.safeMarket(marketId, market);
|
|
4719
4753
|
const timestamp = this.safeIntegerN(order, ['created_at', 'created-at', 'create_date']);
|
|
@@ -4756,7 +4790,10 @@ class htx extends htx$1 {
|
|
|
4756
4790
|
const average = this.safeString(order, 'trade_avg_price');
|
|
4757
4791
|
const trades = this.safeValue(order, 'trades');
|
|
4758
4792
|
const reduceOnlyInteger = this.safeInteger(order, 'reduce_only');
|
|
4759
|
-
|
|
4793
|
+
let reduceOnly = undefined;
|
|
4794
|
+
if (reduceOnlyInteger !== undefined) {
|
|
4795
|
+
reduceOnly = (reduceOnlyInteger === 0) ? false : true;
|
|
4796
|
+
}
|
|
4760
4797
|
return this.safeOrder({
|
|
4761
4798
|
'info': order,
|
|
4762
4799
|
'id': id,
|
|
@@ -4783,61 +4820,20 @@ class htx extends htx$1 {
|
|
|
4783
4820
|
'trades': trades,
|
|
4784
4821
|
}, market);
|
|
4785
4822
|
}
|
|
4786
|
-
async
|
|
4823
|
+
async createSpotOrderRequest(symbol, type, side, amount, price = undefined, params = {}) {
|
|
4787
4824
|
/**
|
|
4788
4825
|
* @method
|
|
4789
|
-
* @name huobi#createOrder
|
|
4790
|
-
* @description create a trade order
|
|
4791
|
-
* @see https://huobiapi.github.io/docs/spot/v1/en/#place-a-new-order // spot, margin
|
|
4792
|
-
* @see https://huobiapi.github.io/docs/coin_margined_swap/v1/en/#place-an-order // coin-m swap
|
|
4793
|
-
* @see https://huobiapi.github.io/docs/coin_margined_swap/v1/en/#place-trigger-order // coin-m swap trigger
|
|
4794
|
-
* @see https://huobiapi.github.io/docs/usdt_swap/v1/en/#cross-place-an-order // usdt-m swap cross
|
|
4795
|
-
* @see https://huobiapi.github.io/docs/usdt_swap/v1/en/#cross-place-trigger-order // usdt-m swap cross trigger
|
|
4796
|
-
* @see https://huobiapi.github.io/docs/usdt_swap/v1/en/#isolated-place-an-order // usdt-m swap isolated
|
|
4797
|
-
* @see https://huobiapi.github.io/docs/usdt_swap/v1/en/#isolated-place-trigger-order // usdt-m swap isolated trigger
|
|
4798
|
-
* @see https://huobiapi.github.io/docs/dm/v1/en/#place-an-order // coin-m futures
|
|
4799
|
-
* @see https://huobiapi.github.io/docs/dm/v1/en/#place-trigger-order // coin-m futures contract trigger
|
|
4800
|
-
* @param {string} symbol unified symbol of the market to create an order in
|
|
4801
|
-
* @param {string} type 'market' or 'limit'
|
|
4802
|
-
* @param {string} side 'buy' or 'sell'
|
|
4803
|
-
* @param {float} amount how much of currency you want to trade in units of base currency
|
|
4804
|
-
* @param {float} [price] the price at which the order is to be fullfilled, in units of the quote currency, ignored in market orders
|
|
4805
|
-
* @param {object} [params] extra parameters specific to the huobi api endpoint
|
|
4806
|
-
* @param {float} [params.stopPrice] the price a trigger order is triggered at
|
|
4807
|
-
* @param {string} [params.triggerType] *contract trigger orders only* ge: greater than or equal to, le: less than or equal to
|
|
4808
|
-
* @param {float} [params.stopLossPrice] *contract only* the price a stop-loss order is triggered at
|
|
4809
|
-
* @param {float} [params.takeProfitPrice] *contract only* the price a take-profit order is triggered at
|
|
4810
|
-
* @param {string} [params.operator] *spot and margin only* gte or lte, trigger price condition
|
|
4811
|
-
* @param {string} [params.offset] *contract only* 'open', 'close', or 'both', required in hedge mode
|
|
4812
|
-
* @param {bool} [params.postOnly] *contract only* true or false
|
|
4813
|
-
* @param {int} [params.leverRate] *contract only* required for all contract orders except tpsl, leverage greater than 20x requires prior approval of high-leverage agreement
|
|
4814
|
-
* @param {string} [params.timeInForce] supports 'IOC' and 'FOK'
|
|
4815
|
-
* @returns {object} an [order structure]{@link https://github.com/ccxt/ccxt/wiki/Manual#order-structure}
|
|
4816
|
-
*/
|
|
4817
|
-
await this.loadMarkets();
|
|
4818
|
-
const market = this.market(symbol);
|
|
4819
|
-
const [marketType, query] = this.handleMarketTypeAndParams('createOrder', market, params);
|
|
4820
|
-
if (marketType === 'spot') {
|
|
4821
|
-
return await this.createSpotOrder(symbol, type, side, amount, price, query);
|
|
4822
|
-
}
|
|
4823
|
-
else {
|
|
4824
|
-
return await this.createContractOrder(symbol, type, side, amount, price, query);
|
|
4825
|
-
}
|
|
4826
|
-
}
|
|
4827
|
-
async createSpotOrder(symbol, type, side, amount, price = undefined, params = {}) {
|
|
4828
|
-
/**
|
|
4829
4826
|
* @ignore
|
|
4830
|
-
* @
|
|
4831
|
-
* @
|
|
4832
|
-
* @description create a spot trade order
|
|
4833
|
-
* @see https://huobiapi.github.io/docs/spot/v1/en/#place-a-new-order
|
|
4827
|
+
* @name htx#createSpotOrderRequest
|
|
4828
|
+
* @description helper function to build request
|
|
4834
4829
|
* @param {string} symbol unified symbol of the market to create an order in
|
|
4835
4830
|
* @param {string} type 'market' or 'limit'
|
|
4836
4831
|
* @param {string} side 'buy' or 'sell'
|
|
4837
|
-
* @param {float} amount how much
|
|
4832
|
+
* @param {float} amount how much you want to trade in units of the base currency
|
|
4838
4833
|
* @param {float} [price] the price at which the order is to be fullfilled, in units of the quote currency, ignored in market orders
|
|
4839
|
-
* @param {object} params extra parameters specific to the
|
|
4840
|
-
* @
|
|
4834
|
+
* @param {object} [params] extra parameters specific to the htx api endpoint
|
|
4835
|
+
* @param {string} [params.timeInForce] supports 'IOC' and 'FOK'
|
|
4836
|
+
* @returns {object} request to be sent to the exchange
|
|
4841
4837
|
*/
|
|
4842
4838
|
await this.loadMarkets();
|
|
4843
4839
|
await this.loadAccounts();
|
|
@@ -4939,52 +4935,22 @@ class htx extends htx$1 {
|
|
|
4939
4935
|
request['price'] = this.priceToPrecision(symbol, price);
|
|
4940
4936
|
}
|
|
4941
4937
|
params = this.omit(params, ['stopPrice', 'stop-price', 'clientOrderId', 'client-order-id', 'operator', 'timeInForce']);
|
|
4942
|
-
|
|
4943
|
-
//
|
|
4944
|
-
// spot
|
|
4945
|
-
//
|
|
4946
|
-
// {"status":"ok","data":"438398393065481"}
|
|
4947
|
-
//
|
|
4948
|
-
const id = this.safeString(response, 'data');
|
|
4949
|
-
return this.safeOrder({
|
|
4950
|
-
'info': response,
|
|
4951
|
-
'id': id,
|
|
4952
|
-
'timestamp': undefined,
|
|
4953
|
-
'datetime': undefined,
|
|
4954
|
-
'lastTradeTimestamp': undefined,
|
|
4955
|
-
'status': undefined,
|
|
4956
|
-
'symbol': undefined,
|
|
4957
|
-
'type': type,
|
|
4958
|
-
'side': side,
|
|
4959
|
-
'price': price,
|
|
4960
|
-
'amount': amount,
|
|
4961
|
-
'filled': undefined,
|
|
4962
|
-
'remaining': undefined,
|
|
4963
|
-
'cost': undefined,
|
|
4964
|
-
'trades': undefined,
|
|
4965
|
-
'fee': undefined,
|
|
4966
|
-
'clientOrderId': undefined,
|
|
4967
|
-
'average': undefined,
|
|
4968
|
-
}, market);
|
|
4938
|
+
return this.extend(request, params);
|
|
4969
4939
|
}
|
|
4970
|
-
|
|
4940
|
+
createContractOrderRequest(symbol, type, side, amount, price = undefined, params = {}) {
|
|
4971
4941
|
/**
|
|
4972
|
-
* @ignore
|
|
4973
4942
|
* @method
|
|
4974
|
-
* @
|
|
4975
|
-
* @
|
|
4976
|
-
* @
|
|
4977
|
-
* @see https://huobiapi.github.io/docs/coin_margined_swap/v1/en/#place-an-order
|
|
4978
|
-
* @see https://huobiapi.github.io/docs/usdt_swap/v1/en/#isolated-place-an-order
|
|
4979
|
-
* @see https://huobiapi.github.io/docs/usdt_swap/v1/en/#cross-place-an-order
|
|
4943
|
+
* @ignore
|
|
4944
|
+
* @name htx#createContractOrderRequest
|
|
4945
|
+
* @description helper function to build request
|
|
4980
4946
|
* @param {string} symbol unified symbol of the market to create an order in
|
|
4981
4947
|
* @param {string} type 'market' or 'limit'
|
|
4982
4948
|
* @param {string} side 'buy' or 'sell'
|
|
4983
|
-
* @param {float} amount how much
|
|
4949
|
+
* @param {float} amount how much you want to trade in units of the base currency
|
|
4984
4950
|
* @param {float} [price] the price at which the order is to be fullfilled, in units of the quote currency, ignored in market orders
|
|
4985
|
-
* @param {object} params extra parameters specific to the
|
|
4951
|
+
* @param {object} [params] extra parameters specific to the htx api endpoint
|
|
4986
4952
|
* @param {string} [params.timeInForce] supports 'IOC' and 'FOK'
|
|
4987
|
-
* @returns {object}
|
|
4953
|
+
* @returns {object} request to be sent to the exchange
|
|
4988
4954
|
*/
|
|
4989
4955
|
const market = this.market(symbol);
|
|
4990
4956
|
const request = {
|
|
@@ -5056,63 +5022,117 @@ class htx extends htx$1 {
|
|
|
5056
5022
|
request['lever_rate'] = leverRate;
|
|
5057
5023
|
request['order_price_type'] = type;
|
|
5058
5024
|
}
|
|
5059
|
-
params = this.omit(params, ['reduceOnly', 'stopPrice', 'stopLossPrice', 'takeProfitPrice', 'triggerType', 'leverRate', 'timeInForce']);
|
|
5060
5025
|
const broker = this.safeValue(this.options, 'broker', {});
|
|
5061
5026
|
const brokerId = this.safeString(broker, 'id');
|
|
5062
5027
|
request['channel_code'] = brokerId;
|
|
5028
|
+
params = this.omit(params, ['reduceOnly', 'stopPrice', 'stopLossPrice', 'takeProfitPrice', 'triggerType', 'leverRate', 'timeInForce']);
|
|
5029
|
+
return this.extend(request, params);
|
|
5030
|
+
}
|
|
5031
|
+
async createOrder(symbol, type, side, amount, price = undefined, params = {}) {
|
|
5032
|
+
/**
|
|
5033
|
+
* @method
|
|
5034
|
+
* @name huobi#createOrder
|
|
5035
|
+
* @description create a trade order
|
|
5036
|
+
* @see https://huobiapi.github.io/docs/spot/v1/en/#place-a-new-order // spot, margin
|
|
5037
|
+
* @see https://huobiapi.github.io/docs/coin_margined_swap/v1/en/#place-an-order // coin-m swap
|
|
5038
|
+
* @see https://huobiapi.github.io/docs/coin_margined_swap/v1/en/#place-trigger-order // coin-m swap trigger
|
|
5039
|
+
* @see https://huobiapi.github.io/docs/usdt_swap/v1/en/#cross-place-an-order // usdt-m swap cross
|
|
5040
|
+
* @see https://huobiapi.github.io/docs/usdt_swap/v1/en/#cross-place-trigger-order // usdt-m swap cross trigger
|
|
5041
|
+
* @see https://huobiapi.github.io/docs/usdt_swap/v1/en/#isolated-place-an-order // usdt-m swap isolated
|
|
5042
|
+
* @see https://huobiapi.github.io/docs/usdt_swap/v1/en/#isolated-place-trigger-order // usdt-m swap isolated trigger
|
|
5043
|
+
* @see https://huobiapi.github.io/docs/dm/v1/en/#place-an-order // coin-m futures
|
|
5044
|
+
* @see https://huobiapi.github.io/docs/dm/v1/en/#place-trigger-order // coin-m futures contract trigger
|
|
5045
|
+
* @param {string} symbol unified symbol of the market to create an order in
|
|
5046
|
+
* @param {string} type 'market' or 'limit'
|
|
5047
|
+
* @param {string} side 'buy' or 'sell'
|
|
5048
|
+
* @param {float} amount how much you want to trade in units of the base currency
|
|
5049
|
+
* @param {float} [price] the price at which the order is to be fullfilled, in units of the quote currency, ignored in market orders
|
|
5050
|
+
* @param {object} [params] extra parameters specific to the huobi api endpoint
|
|
5051
|
+
* @param {float} [params.stopPrice] the price a trigger order is triggered at
|
|
5052
|
+
* @param {string} [params.triggerType] *contract trigger orders only* ge: greater than or equal to, le: less than or equal to
|
|
5053
|
+
* @param {float} [params.stopLossPrice] *contract only* the price a stop-loss order is triggered at
|
|
5054
|
+
* @param {float} [params.takeProfitPrice] *contract only* the price a take-profit order is triggered at
|
|
5055
|
+
* @param {string} [params.operator] *spot and margin only* gte or lte, trigger price condition
|
|
5056
|
+
* @param {string} [params.offset] *contract only* 'open', 'close', or 'both', required in hedge mode
|
|
5057
|
+
* @param {bool} [params.postOnly] *contract only* true or false
|
|
5058
|
+
* @param {int} [params.leverRate] *contract only* required for all contract orders except tpsl, leverage greater than 20x requires prior approval of high-leverage agreement
|
|
5059
|
+
* @param {string} [params.timeInForce] supports 'IOC' and 'FOK'
|
|
5060
|
+
* @returns {object} an [order structure]{@link https://github.com/ccxt/ccxt/wiki/Manual#order-structure}
|
|
5061
|
+
*/
|
|
5062
|
+
await this.loadMarkets();
|
|
5063
|
+
const market = this.market(symbol);
|
|
5064
|
+
const triggerPrice = this.safeNumber2(params, 'stopPrice', 'trigger_price');
|
|
5065
|
+
const stopLossTriggerPrice = this.safeNumber2(params, 'stopLossPrice', 'sl_trigger_price');
|
|
5066
|
+
const takeProfitTriggerPrice = this.safeNumber2(params, 'takeProfitPrice', 'tp_trigger_price');
|
|
5067
|
+
const isStop = triggerPrice !== undefined;
|
|
5068
|
+
const isStopLossTriggerOrder = stopLossTriggerPrice !== undefined;
|
|
5069
|
+
const isTakeProfitTriggerOrder = takeProfitTriggerPrice !== undefined;
|
|
5063
5070
|
let response = undefined;
|
|
5064
|
-
if (market['
|
|
5065
|
-
|
|
5066
|
-
|
|
5067
|
-
marginMode = (marginMode === undefined) ? 'cross' : marginMode;
|
|
5068
|
-
if (marginMode === 'isolated') {
|
|
5069
|
-
if (isStop) {
|
|
5070
|
-
response = await this.contractPrivatePostLinearSwapApiV1SwapTriggerOrder(this.extend(request, params));
|
|
5071
|
-
}
|
|
5072
|
-
else if (isStopLossTriggerOrder || isTakeProfitTriggerOrder) {
|
|
5073
|
-
response = await this.contractPrivatePostLinearSwapApiV1SwapTpslOrder(this.extend(request, params));
|
|
5074
|
-
}
|
|
5075
|
-
else {
|
|
5076
|
-
response = await this.contractPrivatePostLinearSwapApiV1SwapOrder(this.extend(request, params));
|
|
5077
|
-
}
|
|
5078
|
-
}
|
|
5079
|
-
else if (marginMode === 'cross') {
|
|
5080
|
-
if (isStop) {
|
|
5081
|
-
response = await this.contractPrivatePostLinearSwapApiV1SwapCrossTriggerOrder(this.extend(request, params));
|
|
5082
|
-
}
|
|
5083
|
-
else if (isStopLossTriggerOrder || isTakeProfitTriggerOrder) {
|
|
5084
|
-
response = await this.contractPrivatePostLinearSwapApiV1SwapCrossTpslOrder(this.extend(request, params));
|
|
5085
|
-
}
|
|
5086
|
-
else {
|
|
5087
|
-
response = await this.contractPrivatePostLinearSwapApiV1SwapCrossOrder(this.extend(request, params));
|
|
5088
|
-
}
|
|
5089
|
-
}
|
|
5071
|
+
if (market['spot']) {
|
|
5072
|
+
const spotRequest = await this.createSpotOrderRequest(symbol, type, side, amount, price, params);
|
|
5073
|
+
response = await this.spotPrivatePostV1OrderOrdersPlace(spotRequest);
|
|
5090
5074
|
}
|
|
5091
|
-
else
|
|
5092
|
-
|
|
5093
|
-
|
|
5094
|
-
|
|
5095
|
-
|
|
5096
|
-
|
|
5097
|
-
|
|
5075
|
+
else {
|
|
5076
|
+
const contractRequest = this.createContractOrderRequest(symbol, type, side, amount, price, params);
|
|
5077
|
+
if (market['linear']) {
|
|
5078
|
+
let marginMode = undefined;
|
|
5079
|
+
[marginMode, params] = this.handleMarginModeAndParams('createOrder', params);
|
|
5080
|
+
marginMode = (marginMode === undefined) ? 'cross' : marginMode;
|
|
5081
|
+
if (marginMode === 'isolated') {
|
|
5082
|
+
if (isStop) {
|
|
5083
|
+
response = await this.contractPrivatePostLinearSwapApiV1SwapTriggerOrder(contractRequest);
|
|
5084
|
+
}
|
|
5085
|
+
else if (isStopLossTriggerOrder || isTakeProfitTriggerOrder) {
|
|
5086
|
+
response = await this.contractPrivatePostLinearSwapApiV1SwapTpslOrder(contractRequest);
|
|
5087
|
+
}
|
|
5088
|
+
else {
|
|
5089
|
+
response = await this.contractPrivatePostLinearSwapApiV1SwapOrder(contractRequest);
|
|
5090
|
+
}
|
|
5098
5091
|
}
|
|
5099
|
-
else {
|
|
5100
|
-
|
|
5092
|
+
else if (marginMode === 'cross') {
|
|
5093
|
+
if (isStop) {
|
|
5094
|
+
response = await this.contractPrivatePostLinearSwapApiV1SwapCrossTriggerOrder(contractRequest);
|
|
5095
|
+
}
|
|
5096
|
+
else if (isStopLossTriggerOrder || isTakeProfitTriggerOrder) {
|
|
5097
|
+
response = await this.contractPrivatePostLinearSwapApiV1SwapCrossTpslOrder(contractRequest);
|
|
5098
|
+
}
|
|
5099
|
+
else {
|
|
5100
|
+
response = await this.contractPrivatePostLinearSwapApiV1SwapCrossOrder(contractRequest);
|
|
5101
|
+
}
|
|
5101
5102
|
}
|
|
5102
5103
|
}
|
|
5103
|
-
else if (market['
|
|
5104
|
-
if (
|
|
5105
|
-
|
|
5106
|
-
|
|
5107
|
-
|
|
5108
|
-
|
|
5104
|
+
else if (market['inverse']) {
|
|
5105
|
+
if (market['swap']) {
|
|
5106
|
+
if (isStop) {
|
|
5107
|
+
response = await this.contractPrivatePostSwapApiV1SwapTriggerOrder(contractRequest);
|
|
5108
|
+
}
|
|
5109
|
+
else if (isStopLossTriggerOrder || isTakeProfitTriggerOrder) {
|
|
5110
|
+
response = await this.contractPrivatePostSwapApiV1SwapTpslOrder(contractRequest);
|
|
5111
|
+
}
|
|
5112
|
+
else {
|
|
5113
|
+
response = await this.contractPrivatePostSwapApiV1SwapOrder(contractRequest);
|
|
5114
|
+
}
|
|
5109
5115
|
}
|
|
5110
|
-
else {
|
|
5111
|
-
|
|
5116
|
+
else if (market['future']) {
|
|
5117
|
+
if (isStop) {
|
|
5118
|
+
response = await this.contractPrivatePostApiV1ContractTriggerOrder(contractRequest);
|
|
5119
|
+
}
|
|
5120
|
+
else if (isStopLossTriggerOrder || isTakeProfitTriggerOrder) {
|
|
5121
|
+
response = await this.contractPrivatePostApiV1ContractTpslOrder(contractRequest);
|
|
5122
|
+
}
|
|
5123
|
+
else {
|
|
5124
|
+
response = await this.contractPrivatePostApiV1ContractOrder(contractRequest);
|
|
5125
|
+
}
|
|
5112
5126
|
}
|
|
5113
5127
|
}
|
|
5114
5128
|
}
|
|
5115
5129
|
//
|
|
5130
|
+
// spot
|
|
5131
|
+
//
|
|
5132
|
+
// {"status":"ok","data":"438398393065481"}
|
|
5133
|
+
//
|
|
5134
|
+
// swap and future
|
|
5135
|
+
//
|
|
5116
5136
|
// {
|
|
5117
5137
|
// "status": "ok",
|
|
5118
5138
|
// "data": {
|
|
@@ -5138,7 +5158,29 @@ class htx extends htx$1 {
|
|
|
5138
5158
|
//
|
|
5139
5159
|
let data = undefined;
|
|
5140
5160
|
let result = undefined;
|
|
5141
|
-
if (
|
|
5161
|
+
if (market['spot']) {
|
|
5162
|
+
return this.safeOrder({
|
|
5163
|
+
'info': response,
|
|
5164
|
+
'id': this.safeString(response, 'data'),
|
|
5165
|
+
'timestamp': undefined,
|
|
5166
|
+
'datetime': undefined,
|
|
5167
|
+
'lastTradeTimestamp': undefined,
|
|
5168
|
+
'status': undefined,
|
|
5169
|
+
'symbol': undefined,
|
|
5170
|
+
'type': type,
|
|
5171
|
+
'side': side,
|
|
5172
|
+
'price': price,
|
|
5173
|
+
'amount': amount,
|
|
5174
|
+
'filled': undefined,
|
|
5175
|
+
'remaining': undefined,
|
|
5176
|
+
'cost': undefined,
|
|
5177
|
+
'trades': undefined,
|
|
5178
|
+
'fee': undefined,
|
|
5179
|
+
'clientOrderId': undefined,
|
|
5180
|
+
'average': undefined,
|
|
5181
|
+
}, market);
|
|
5182
|
+
}
|
|
5183
|
+
else if (isStopLossTriggerOrder) {
|
|
5142
5184
|
data = this.safeValue(response, 'data', {});
|
|
5143
5185
|
result = this.safeValue(data, 'sl_order', {});
|
|
5144
5186
|
}
|
|
@@ -5151,6 +5193,142 @@ class htx extends htx$1 {
|
|
|
5151
5193
|
}
|
|
5152
5194
|
return this.parseOrder(result, market);
|
|
5153
5195
|
}
|
|
5196
|
+
async createOrders(orders, params = {}) {
|
|
5197
|
+
/**
|
|
5198
|
+
* @method
|
|
5199
|
+
* @name htx#createOrders
|
|
5200
|
+
* @description create a list of trade orders
|
|
5201
|
+
* @see https://huobiapi.github.io/docs/spot/v1/en/#place-a-batch-of-orders
|
|
5202
|
+
* @see https://huobiapi.github.io/docs/dm/v1/en/#place-a-batch-of-orders
|
|
5203
|
+
* @see https://huobiapi.github.io/docs/coin_margined_swap/v1/en/#place-a-batch-of-orders
|
|
5204
|
+
* @see https://huobiapi.github.io/docs/usdt_swap/v1/en/#isolated-place-a-batch-of-orders
|
|
5205
|
+
* @see https://huobiapi.github.io/docs/usdt_swap/v1/en/#cross-place-a-batch-of-orders
|
|
5206
|
+
* @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
|
|
5207
|
+
* @param {object} [params] extra parameters specific to the htx api endpoint
|
|
5208
|
+
* @returns {object} an [order structure]{@link https://github.com/ccxt/ccxt/wiki/Manual#order-structure}
|
|
5209
|
+
*/
|
|
5210
|
+
await this.loadMarkets();
|
|
5211
|
+
const ordersRequests = [];
|
|
5212
|
+
let symbol = undefined;
|
|
5213
|
+
let market = undefined;
|
|
5214
|
+
let marginMode = undefined;
|
|
5215
|
+
for (let i = 0; i < orders.length; i++) {
|
|
5216
|
+
const rawOrder = orders[i];
|
|
5217
|
+
const marketId = this.safeString(rawOrder, 'symbol');
|
|
5218
|
+
if (symbol === undefined) {
|
|
5219
|
+
symbol = marketId;
|
|
5220
|
+
}
|
|
5221
|
+
else {
|
|
5222
|
+
if (symbol !== marketId) {
|
|
5223
|
+
throw new errors.BadRequest(this.id + ' createOrders() requires all orders to have the same symbol');
|
|
5224
|
+
}
|
|
5225
|
+
}
|
|
5226
|
+
const type = this.safeString(rawOrder, 'type');
|
|
5227
|
+
const side = this.safeString(rawOrder, 'side');
|
|
5228
|
+
const amount = this.safeValue(rawOrder, 'amount');
|
|
5229
|
+
const price = this.safeValue(rawOrder, 'price');
|
|
5230
|
+
const orderParams = this.safeValue(rawOrder, 'params', {});
|
|
5231
|
+
const marginResult = this.handleMarginModeAndParams('createOrders', orderParams);
|
|
5232
|
+
const currentMarginMode = marginResult[0];
|
|
5233
|
+
if (currentMarginMode !== undefined) {
|
|
5234
|
+
if (marginMode === undefined) {
|
|
5235
|
+
marginMode = currentMarginMode;
|
|
5236
|
+
}
|
|
5237
|
+
else {
|
|
5238
|
+
if (marginMode !== currentMarginMode) {
|
|
5239
|
+
throw new errors.BadRequest(this.id + ' createOrders() requires all orders to have the same margin mode (isolated or cross)');
|
|
5240
|
+
}
|
|
5241
|
+
}
|
|
5242
|
+
}
|
|
5243
|
+
market = this.market(symbol);
|
|
5244
|
+
let orderRequest = undefined;
|
|
5245
|
+
if (market['spot']) {
|
|
5246
|
+
orderRequest = await this.createSpotOrderRequest(marketId, type, side, amount, price, orderParams);
|
|
5247
|
+
}
|
|
5248
|
+
else {
|
|
5249
|
+
orderRequest = this.createContractOrderRequest(marketId, type, side, amount, price, orderParams);
|
|
5250
|
+
}
|
|
5251
|
+
orderRequest = this.omit(orderRequest, 'marginMode');
|
|
5252
|
+
ordersRequests.push(orderRequest);
|
|
5253
|
+
}
|
|
5254
|
+
const request = {};
|
|
5255
|
+
let response = undefined;
|
|
5256
|
+
if (market['spot']) {
|
|
5257
|
+
response = await this.privatePostOrderBatchOrders(ordersRequests);
|
|
5258
|
+
}
|
|
5259
|
+
else {
|
|
5260
|
+
request['orders_data'] = ordersRequests;
|
|
5261
|
+
if (market['linear']) {
|
|
5262
|
+
marginMode = (marginMode === undefined) ? 'cross' : marginMode;
|
|
5263
|
+
if (marginMode === 'isolated') {
|
|
5264
|
+
response = await this.contractPrivatePostLinearSwapApiV1SwapBatchorder(request);
|
|
5265
|
+
}
|
|
5266
|
+
else if (marginMode === 'cross') {
|
|
5267
|
+
response = await this.contractPrivatePostLinearSwapApiV1SwapCrossBatchorder(request);
|
|
5268
|
+
}
|
|
5269
|
+
}
|
|
5270
|
+
else if (market['inverse']) {
|
|
5271
|
+
if (market['swap']) {
|
|
5272
|
+
response = await this.contractPrivatePostSwapApiV1SwapBatchorder(request);
|
|
5273
|
+
}
|
|
5274
|
+
else if (market['future']) {
|
|
5275
|
+
response = await this.contractPrivatePostApiV1ContractBatchorder(request);
|
|
5276
|
+
}
|
|
5277
|
+
}
|
|
5278
|
+
}
|
|
5279
|
+
//
|
|
5280
|
+
// spot
|
|
5281
|
+
//
|
|
5282
|
+
// {
|
|
5283
|
+
// "status": "ok",
|
|
5284
|
+
// "data": [
|
|
5285
|
+
// {
|
|
5286
|
+
// "order-id": 936847569789079,
|
|
5287
|
+
// "client-order-id": "AA03022abc3a55e82c-0087-4fc2-beac-112fdebb1ee9"
|
|
5288
|
+
// },
|
|
5289
|
+
// {
|
|
5290
|
+
// "client-order-id": "AA03022abcdb3baefb-3cfa-4891-8009-082b3d46ca82",
|
|
5291
|
+
// "err-code": "account-frozen-balance-insufficient-error",
|
|
5292
|
+
// "err-msg": "trade account balance is not enough, left: `89`"
|
|
5293
|
+
// }
|
|
5294
|
+
// ]
|
|
5295
|
+
// }
|
|
5296
|
+
//
|
|
5297
|
+
// swap and future
|
|
5298
|
+
//
|
|
5299
|
+
// {
|
|
5300
|
+
// "status": "ok",
|
|
5301
|
+
// "data": {
|
|
5302
|
+
// "errors": [
|
|
5303
|
+
// {
|
|
5304
|
+
// "index": 2,
|
|
5305
|
+
// "err_code": 1047,
|
|
5306
|
+
// "err_msg": "Insufficient margin available."
|
|
5307
|
+
// }
|
|
5308
|
+
// ],
|
|
5309
|
+
// "success": [
|
|
5310
|
+
// {
|
|
5311
|
+
// "order_id": 1172923090632953857,
|
|
5312
|
+
// "index": 1,
|
|
5313
|
+
// "order_id_str": "1172923090632953857"
|
|
5314
|
+
// }
|
|
5315
|
+
// ]
|
|
5316
|
+
// },
|
|
5317
|
+
// "ts": 1699688256671
|
|
5318
|
+
// }
|
|
5319
|
+
//
|
|
5320
|
+
let result = undefined;
|
|
5321
|
+
if (market['spot']) {
|
|
5322
|
+
result = this.safeValue(response, 'data', []);
|
|
5323
|
+
}
|
|
5324
|
+
else {
|
|
5325
|
+
const data = this.safeValue(response, 'data', {});
|
|
5326
|
+
const success = this.safeValue(data, 'success', []);
|
|
5327
|
+
const errors = this.safeValue(data, 'errors', []);
|
|
5328
|
+
result = this.arrayConcat(success, errors);
|
|
5329
|
+
}
|
|
5330
|
+
return this.parseOrders(result, market);
|
|
5331
|
+
}
|
|
5154
5332
|
async cancelOrder(id, symbol = undefined, params = {}) {
|
|
5155
5333
|
/**
|
|
5156
5334
|
* @method
|