ccxt 4.1.69 → 4.1.71
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 +702 -207
- package/dist/ccxt.browser.min.js +2 -2
- package/dist/cjs/ccxt.js +1 -1
- package/dist/cjs/src/binance.js +1 -0
- package/dist/cjs/src/coinbase.js +3 -0
- package/dist/cjs/src/coinex.js +388 -63
- package/dist/cjs/src/gate.js +297 -134
- package/dist/cjs/src/pro/binance.js +13 -10
- package/js/ccxt.d.ts +1 -1
- package/js/ccxt.js +1 -1
- package/js/src/abstract/binance.d.ts +1 -0
- package/js/src/abstract/binancecoinm.d.ts +1 -0
- package/js/src/abstract/binanceus.d.ts +1 -0
- package/js/src/abstract/binanceusdm.d.ts +1 -0
- package/js/src/abstract/coinbase.d.ts +3 -0
- package/js/src/binance.js +1 -0
- package/js/src/coinbase.js +3 -0
- package/js/src/coinex.d.ts +4 -1
- package/js/src/coinex.js +388 -63
- package/js/src/gate.js +297 -134
- package/js/src/pro/binance.js +13 -10
- package/package.json +1 -1
- package/skip-tests.json +3 -1
package/js/src/coinex.js
CHANGED
|
@@ -45,8 +45,10 @@ export default class coinex extends Exchange {
|
|
|
45
45
|
'borrowIsolatedMargin': true,
|
|
46
46
|
'cancelAllOrders': true,
|
|
47
47
|
'cancelOrder': true,
|
|
48
|
+
'cancelOrders': true,
|
|
48
49
|
'createDepositAddress': true,
|
|
49
50
|
'createOrder': true,
|
|
51
|
+
'createOrders': true,
|
|
50
52
|
'createReduceOnlyOrder': true,
|
|
51
53
|
'editOrder': true,
|
|
52
54
|
'fetchBalance': true,
|
|
@@ -1537,6 +1539,8 @@ export default class coinex extends Exchange {
|
|
|
1537
1539
|
}
|
|
1538
1540
|
parseOrderStatus(status) {
|
|
1539
1541
|
const statuses = {
|
|
1542
|
+
'rejected': 'rejected',
|
|
1543
|
+
'open': 'open',
|
|
1540
1544
|
'not_deal': 'open',
|
|
1541
1545
|
'part_deal': 'open',
|
|
1542
1546
|
'done': 'closed',
|
|
@@ -1570,7 +1574,7 @@ export default class coinex extends Exchange {
|
|
|
1570
1574
|
// "client_id": "",
|
|
1571
1575
|
// }
|
|
1572
1576
|
//
|
|
1573
|
-
// Spot and Margin createOrder, cancelOrder, fetchOrder
|
|
1577
|
+
// Spot and Margin createOrder, createOrders, cancelOrder, cancelOrders, fetchOrder
|
|
1574
1578
|
//
|
|
1575
1579
|
// {
|
|
1576
1580
|
// "amount":"1.5",
|
|
@@ -1769,13 +1773,50 @@ export default class coinex extends Exchange {
|
|
|
1769
1773
|
// "user_id": 3620173
|
|
1770
1774
|
// }
|
|
1771
1775
|
//
|
|
1776
|
+
// swap: cancelOrders
|
|
1777
|
+
//
|
|
1778
|
+
// {
|
|
1779
|
+
// "amount": "0.0005",
|
|
1780
|
+
// "client_id": "x-167673045-b0cee0c584718b65",
|
|
1781
|
+
// "create_time": 1701233683.294231,
|
|
1782
|
+
// "deal_asset_fee": "0.00000000000000000000",
|
|
1783
|
+
// "deal_fee": "0.00000000000000000000",
|
|
1784
|
+
// "deal_profit": "0.00000000000000000000",
|
|
1785
|
+
// "deal_stock": "0.00000000000000000000",
|
|
1786
|
+
// "effect_type": 1,
|
|
1787
|
+
// "fee_asset": "",
|
|
1788
|
+
// "fee_discount": "0.00000000000000000000",
|
|
1789
|
+
// "last_deal_amount": "0.00000000000000000000",
|
|
1790
|
+
// "last_deal_id": 0,
|
|
1791
|
+
// "last_deal_price": "0.00000000000000000000",
|
|
1792
|
+
// "last_deal_role": 0,
|
|
1793
|
+
// "last_deal_time": 0,
|
|
1794
|
+
// "last_deal_type": 0,
|
|
1795
|
+
// "left": "0.0005",
|
|
1796
|
+
// "leverage": "3",
|
|
1797
|
+
// "maker_fee": "0.00030",
|
|
1798
|
+
// "market": "BTCUSDT",
|
|
1799
|
+
// "option": 0,
|
|
1800
|
+
// "order_id": 115940476323,
|
|
1801
|
+
// "position_id": 0,
|
|
1802
|
+
// "position_type": 2,
|
|
1803
|
+
// "price": "25000.00",
|
|
1804
|
+
// "side": 2,
|
|
1805
|
+
// "source": "api.v1",
|
|
1806
|
+
// "stop_id": 0,
|
|
1807
|
+
// "stop_loss_price": "0.00000000000000000000",
|
|
1808
|
+
// "stop_loss_type": 0,
|
|
1809
|
+
// "take_profit_price": "0.00000000000000000000",
|
|
1810
|
+
// "take_profit_type": 0,
|
|
1811
|
+
// "taker_fee": "0.00050",
|
|
1812
|
+
// "target": 0,
|
|
1813
|
+
// "type": 1,
|
|
1814
|
+
// "update_time": 1701233721.718884,
|
|
1815
|
+
// "user_id": 3620173
|
|
1816
|
+
// }
|
|
1817
|
+
//
|
|
1818
|
+
const rawStatus = this.safeString(order, 'status');
|
|
1772
1819
|
const timestamp = this.safeTimestamp(order, 'create_time');
|
|
1773
|
-
const priceString = this.safeString(order, 'price');
|
|
1774
|
-
const costString = this.safeString(order, 'deal_money');
|
|
1775
|
-
const amountString = this.safeString(order, 'amount');
|
|
1776
|
-
const filledString = this.safeString(order, 'deal_amount');
|
|
1777
|
-
const averageString = this.safeString(order, 'avg_price');
|
|
1778
|
-
const remainingString = this.safeString(order, 'left');
|
|
1779
1820
|
const marketId = this.safeString(order, 'market');
|
|
1780
1821
|
const defaultType = this.safeString(this.options, 'defaultType');
|
|
1781
1822
|
const orderType = ('source' in order) ? 'swap' : defaultType;
|
|
@@ -1785,7 +1826,6 @@ export default class coinex extends Exchange {
|
|
|
1785
1826
|
if (feeCurrency === undefined) {
|
|
1786
1827
|
feeCurrency = market['quote'];
|
|
1787
1828
|
}
|
|
1788
|
-
const status = this.parseOrderStatus(this.safeString(order, 'status'));
|
|
1789
1829
|
const rawSide = this.safeInteger(order, 'side');
|
|
1790
1830
|
let side = undefined;
|
|
1791
1831
|
if (rawSide === 1) {
|
|
@@ -1821,21 +1861,23 @@ export default class coinex extends Exchange {
|
|
|
1821
1861
|
'datetime': this.iso8601(timestamp),
|
|
1822
1862
|
'timestamp': timestamp,
|
|
1823
1863
|
'lastTradeTimestamp': this.safeTimestamp(order, 'update_time'),
|
|
1824
|
-
'status':
|
|
1864
|
+
'status': this.parseOrderStatus(rawStatus),
|
|
1825
1865
|
'symbol': market['symbol'],
|
|
1826
1866
|
'type': type,
|
|
1827
1867
|
'timeInForce': undefined,
|
|
1828
1868
|
'postOnly': undefined,
|
|
1829
1869
|
'reduceOnly': undefined,
|
|
1830
1870
|
'side': side,
|
|
1831
|
-
'price':
|
|
1871
|
+
'price': this.safeString(order, 'price'),
|
|
1832
1872
|
'stopPrice': this.safeString(order, 'stop_price'),
|
|
1833
1873
|
'triggerPrice': this.safeString(order, 'stop_price'),
|
|
1834
|
-
'
|
|
1835
|
-
'
|
|
1836
|
-
'
|
|
1837
|
-
'
|
|
1838
|
-
'
|
|
1874
|
+
'takeProfitPrice': this.safeNumber(order, 'take_profit_price'),
|
|
1875
|
+
'stopLossPrice': this.safeNumber(order, 'stop_loss_price'),
|
|
1876
|
+
'cost': this.safeString(order, 'deal_money'),
|
|
1877
|
+
'average': this.safeString(order, 'avg_price'),
|
|
1878
|
+
'amount': this.safeString(order, 'amount'),
|
|
1879
|
+
'filled': this.safeString(order, 'deal_amount'),
|
|
1880
|
+
'remaining': this.safeString(order, 'left'),
|
|
1839
1881
|
'trades': undefined,
|
|
1840
1882
|
'fee': {
|
|
1841
1883
|
'currency': feeCurrency,
|
|
@@ -1844,34 +1886,7 @@ export default class coinex extends Exchange {
|
|
|
1844
1886
|
'info': order,
|
|
1845
1887
|
}, market);
|
|
1846
1888
|
}
|
|
1847
|
-
|
|
1848
|
-
/**
|
|
1849
|
-
* @method
|
|
1850
|
-
* @name coinex#createOrder
|
|
1851
|
-
* @description create a trade order
|
|
1852
|
-
* @see https://viabtc.github.io/coinex_api_en_doc/futures/#docsfutures001_http017_put_limit
|
|
1853
|
-
* @see https://viabtc.github.io/coinex_api_en_doc/futures/#docsfutures001_http018_put_market
|
|
1854
|
-
* @see https://viabtc.github.io/coinex_api_en_doc/futures/#docsfutures001_http019_put_limit_stop
|
|
1855
|
-
* @see https://viabtc.github.io/coinex_api_en_doc/futures/#docsfutures001_http020_put_market_stop
|
|
1856
|
-
* @see https://viabtc.github.io/coinex_api_en_doc/futures/#docsfutures001_http031_market_close
|
|
1857
|
-
* @see https://viabtc.github.io/coinex_api_en_doc/futures/#docsfutures001_http030_limit_close
|
|
1858
|
-
* @param {string} symbol unified symbol of the market to create an order in
|
|
1859
|
-
* @param {string} type 'market' or 'limit'
|
|
1860
|
-
* @param {string} side 'buy' or 'sell'
|
|
1861
|
-
* @param {float} amount how much of currency you want to trade in units of base currency
|
|
1862
|
-
* @param {float} [price] the price at which the order is to be fullfilled, in units of the quote currency, ignored in market orders
|
|
1863
|
-
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
1864
|
-
* @param {float} triggerPrice price at which to triger stop orders
|
|
1865
|
-
* @param {float} stopPrice price at which to triger stop orders
|
|
1866
|
-
* @param {float} stopLossPrice price at which to trigger stop-loss orders
|
|
1867
|
-
* @param {float} takeProfitPrice price at which to trigger take-profit orders
|
|
1868
|
-
* @param {string} [params.timeInForce] "GTC", "IOC", "FOK", "PO"
|
|
1869
|
-
* @param {bool} params.postOnly
|
|
1870
|
-
* @param {bool} params.reduceOnly
|
|
1871
|
-
* @param {bool} [params.position_id] *required for reduce only orders* the position id to reduce
|
|
1872
|
-
* @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
|
|
1873
|
-
*/
|
|
1874
|
-
await this.loadMarkets();
|
|
1889
|
+
createOrderRequest(symbol, type, side, amount, price = undefined, params = {}) {
|
|
1875
1890
|
const market = this.market(symbol);
|
|
1876
1891
|
const swap = market['swap'];
|
|
1877
1892
|
const clientOrderId = this.safeString2(params, 'client_id', 'clientOrderId');
|
|
@@ -1885,14 +1900,13 @@ export default class coinex extends Exchange {
|
|
|
1885
1900
|
const timeInForceRaw = this.safeString(params, 'timeInForce'); // Spot: IOC, FOK, PO, GTC, ... NORMAL (default), MAKER_ONLY
|
|
1886
1901
|
const reduceOnly = this.safeValue(params, 'reduceOnly');
|
|
1887
1902
|
if (reduceOnly) {
|
|
1888
|
-
if (market['
|
|
1903
|
+
if (!market['swap']) {
|
|
1889
1904
|
throw new InvalidOrder(this.id + ' createOrder() does not support reduceOnly for ' + market['type'] + ' orders, reduceOnly orders are supported for swap markets only');
|
|
1890
1905
|
}
|
|
1891
1906
|
if (positionId === undefined) {
|
|
1892
1907
|
throw new ArgumentsRequired(this.id + ' createOrder() requires a position_id/positionId parameter for reduceOnly orders');
|
|
1893
1908
|
}
|
|
1894
1909
|
}
|
|
1895
|
-
let method = undefined;
|
|
1896
1910
|
const request = {
|
|
1897
1911
|
'market': market['id'],
|
|
1898
1912
|
};
|
|
@@ -1912,16 +1926,13 @@ export default class coinex extends Exchange {
|
|
|
1912
1926
|
}
|
|
1913
1927
|
request['position_id'] = positionId;
|
|
1914
1928
|
if (stopLossPrice) {
|
|
1915
|
-
method = 'perpetualPrivatePostPositionStopLoss';
|
|
1916
1929
|
request['stop_loss_price'] = this.priceToPrecision(symbol, stopLossPrice);
|
|
1917
1930
|
}
|
|
1918
1931
|
else if (takeProfitPrice) {
|
|
1919
|
-
method = 'perpetualPrivatePostPositionTakeProfit';
|
|
1920
1932
|
request['take_profit_price'] = this.priceToPrecision(symbol, takeProfitPrice);
|
|
1921
1933
|
}
|
|
1922
1934
|
}
|
|
1923
1935
|
else {
|
|
1924
|
-
method = 'perpetualPrivatePostOrderPut' + this.capitalize(type);
|
|
1925
1936
|
const requestSide = (side === 'buy') ? 2 : 1;
|
|
1926
1937
|
if (stopPrice !== undefined) {
|
|
1927
1938
|
request['stop_price'] = this.priceToPrecision(symbol, stopPrice);
|
|
@@ -1929,12 +1940,8 @@ export default class coinex extends Exchange {
|
|
|
1929
1940
|
request['amount'] = this.amountToPrecision(symbol, amount);
|
|
1930
1941
|
request['side'] = requestSide;
|
|
1931
1942
|
if (type === 'limit') {
|
|
1932
|
-
method = 'perpetualPrivatePostOrderPutStopLimit';
|
|
1933
1943
|
request['price'] = this.priceToPrecision(symbol, price);
|
|
1934
1944
|
}
|
|
1935
|
-
else if (type === 'market') {
|
|
1936
|
-
method = 'perpetualPrivatePostOrderPutStopMarket';
|
|
1937
|
-
}
|
|
1938
1945
|
request['amount'] = this.amountToPrecision(symbol, amount);
|
|
1939
1946
|
}
|
|
1940
1947
|
let timeInForce = undefined;
|
|
@@ -1957,7 +1964,6 @@ export default class coinex extends Exchange {
|
|
|
1957
1964
|
}
|
|
1958
1965
|
if (type === 'limit' && stopPrice === undefined) {
|
|
1959
1966
|
if (reduceOnly) {
|
|
1960
|
-
method = 'perpetualPrivatePostOrderCloseLimit';
|
|
1961
1967
|
request['position_id'] = positionId;
|
|
1962
1968
|
}
|
|
1963
1969
|
else {
|
|
@@ -1968,7 +1974,6 @@ export default class coinex extends Exchange {
|
|
|
1968
1974
|
}
|
|
1969
1975
|
else if (type === 'market' && stopPrice === undefined) {
|
|
1970
1976
|
if (reduceOnly) {
|
|
1971
|
-
method = 'perpetualPrivatePostOrderCloseMarket';
|
|
1972
1977
|
request['position_id'] = positionId;
|
|
1973
1978
|
}
|
|
1974
1979
|
else {
|
|
@@ -1979,7 +1984,6 @@ export default class coinex extends Exchange {
|
|
|
1979
1984
|
}
|
|
1980
1985
|
}
|
|
1981
1986
|
else {
|
|
1982
|
-
method = 'privatePostOrder' + this.capitalize(type);
|
|
1983
1987
|
request['type'] = side;
|
|
1984
1988
|
if ((type === 'market') && (side === 'buy')) {
|
|
1985
1989
|
if (this.options['createMarketBuyOrderRequiresPrice']) {
|
|
@@ -2006,12 +2010,6 @@ export default class coinex extends Exchange {
|
|
|
2006
2010
|
}
|
|
2007
2011
|
if (stopPrice !== undefined) {
|
|
2008
2012
|
request['stop_price'] = this.priceToPrecision(symbol, stopPrice);
|
|
2009
|
-
if (type === 'limit') {
|
|
2010
|
-
method = 'privatePostOrderStopLimit';
|
|
2011
|
-
}
|
|
2012
|
-
else if (type === 'market') {
|
|
2013
|
-
method = 'privatePostOrderStopMarket';
|
|
2014
|
-
}
|
|
2015
2013
|
}
|
|
2016
2014
|
if ((type !== 'market') || (stopPrice !== undefined)) {
|
|
2017
2015
|
// following options cannot be applied to vanilla market orders (but can be applied to stop-market orders)
|
|
@@ -2039,7 +2037,100 @@ export default class coinex extends Exchange {
|
|
|
2039
2037
|
request['account_id'] = accountId;
|
|
2040
2038
|
}
|
|
2041
2039
|
params = this.omit(params, ['reduceOnly', 'positionId', 'timeInForce', 'postOnly', 'stopPrice', 'triggerPrice', 'stopLossPrice', 'takeProfitPrice']);
|
|
2042
|
-
|
|
2040
|
+
return this.extend(request, params);
|
|
2041
|
+
}
|
|
2042
|
+
async createOrder(symbol, type, side, amount, price = undefined, params = {}) {
|
|
2043
|
+
/**
|
|
2044
|
+
* @method
|
|
2045
|
+
* @name coinex#createOrder
|
|
2046
|
+
* @description create a trade order
|
|
2047
|
+
* @see https://viabtc.github.io/coinex_api_en_doc/futures/#docsfutures001_http017_put_limit
|
|
2048
|
+
* @see https://viabtc.github.io/coinex_api_en_doc/futures/#docsfutures001_http018_put_market
|
|
2049
|
+
* @see https://viabtc.github.io/coinex_api_en_doc/futures/#docsfutures001_http019_put_limit_stop
|
|
2050
|
+
* @see https://viabtc.github.io/coinex_api_en_doc/futures/#docsfutures001_http020_put_market_stop
|
|
2051
|
+
* @see https://viabtc.github.io/coinex_api_en_doc/futures/#docsfutures001_http031_market_close
|
|
2052
|
+
* @see https://viabtc.github.io/coinex_api_en_doc/futures/#docsfutures001_http030_limit_close
|
|
2053
|
+
* @param {string} symbol unified symbol of the market to create an order in
|
|
2054
|
+
* @param {string} type 'market' or 'limit'
|
|
2055
|
+
* @param {string} side 'buy' or 'sell'
|
|
2056
|
+
* @param {float} amount how much you want to trade in units of the base currency
|
|
2057
|
+
* @param {float} [price] the price at which the order is to be fullfilled, in units of the quote currency, ignored in market orders
|
|
2058
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
2059
|
+
* @param {float} [params.triggerPrice] price to trigger stop orders
|
|
2060
|
+
* @param {float} [params.stopLossPrice] price to trigger stop loss orders
|
|
2061
|
+
* @param {float} [params.takeProfitPrice] price to trigger take profit orders
|
|
2062
|
+
* @param {string} [params.timeInForce] 'GTC', 'IOC', 'FOK', 'PO'
|
|
2063
|
+
* @param {boolean} [params.postOnly] set to true if you wish to make a post only order
|
|
2064
|
+
* @param {boolean} [params.reduceOnly] *contract only* indicates if this order is to reduce the size of a position
|
|
2065
|
+
* @param {int} [params.position_id] *required for reduce only orders* the position id to reduce
|
|
2066
|
+
* @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
|
|
2067
|
+
*/
|
|
2068
|
+
await this.loadMarkets();
|
|
2069
|
+
const market = this.market(symbol);
|
|
2070
|
+
const reduceOnly = this.safeValue(params, 'reduceOnly');
|
|
2071
|
+
const triggerPrice = this.safeNumber2(params, 'stopPrice', 'triggerPrice');
|
|
2072
|
+
const stopLossTriggerPrice = this.safeNumber(params, 'stopLossPrice');
|
|
2073
|
+
const takeProfitTriggerPrice = this.safeNumber(params, 'takeProfitPrice');
|
|
2074
|
+
const isTriggerOrder = triggerPrice !== undefined;
|
|
2075
|
+
const isStopLossTriggerOrder = stopLossTriggerPrice !== undefined;
|
|
2076
|
+
const isTakeProfitTriggerOrder = takeProfitTriggerPrice !== undefined;
|
|
2077
|
+
const isStopLossOrTakeProfitTrigger = isStopLossTriggerOrder || isTakeProfitTriggerOrder;
|
|
2078
|
+
const request = this.createOrderRequest(symbol, type, side, amount, price, params);
|
|
2079
|
+
let response = undefined;
|
|
2080
|
+
if (market['spot']) {
|
|
2081
|
+
if (isTriggerOrder) {
|
|
2082
|
+
if (type === 'limit') {
|
|
2083
|
+
response = await this.privatePostOrderStopLimit(request);
|
|
2084
|
+
}
|
|
2085
|
+
else {
|
|
2086
|
+
response = await this.privatePostOrderStopMarket(request);
|
|
2087
|
+
}
|
|
2088
|
+
}
|
|
2089
|
+
else {
|
|
2090
|
+
if (type === 'limit') {
|
|
2091
|
+
response = await this.privatePostOrderLimit(request);
|
|
2092
|
+
}
|
|
2093
|
+
else {
|
|
2094
|
+
response = await this.privatePostOrderMarket(request);
|
|
2095
|
+
}
|
|
2096
|
+
}
|
|
2097
|
+
}
|
|
2098
|
+
else {
|
|
2099
|
+
if (isTriggerOrder) {
|
|
2100
|
+
if (type === 'limit') {
|
|
2101
|
+
response = await this.perpetualPrivatePostOrderPutStopLimit(request);
|
|
2102
|
+
}
|
|
2103
|
+
else {
|
|
2104
|
+
response = await this.perpetualPrivatePostOrderPutStopMarket(request);
|
|
2105
|
+
}
|
|
2106
|
+
}
|
|
2107
|
+
else if (isStopLossOrTakeProfitTrigger) {
|
|
2108
|
+
if (isStopLossTriggerOrder) {
|
|
2109
|
+
response = await this.perpetualPrivatePostPositionStopLoss(request);
|
|
2110
|
+
}
|
|
2111
|
+
else if (isTakeProfitTriggerOrder) {
|
|
2112
|
+
response = await this.perpetualPrivatePostPositionTakeProfit(request);
|
|
2113
|
+
}
|
|
2114
|
+
}
|
|
2115
|
+
else {
|
|
2116
|
+
if (reduceOnly) {
|
|
2117
|
+
if (type === 'limit') {
|
|
2118
|
+
response = await this.perpetualPrivatePostOrderCloseLimit(request);
|
|
2119
|
+
}
|
|
2120
|
+
else {
|
|
2121
|
+
response = await this.perpetualPrivatePostOrderCloseMarket(request);
|
|
2122
|
+
}
|
|
2123
|
+
}
|
|
2124
|
+
else {
|
|
2125
|
+
if (type === 'limit') {
|
|
2126
|
+
response = await this.perpetualPrivatePostOrderPutLimit(request);
|
|
2127
|
+
}
|
|
2128
|
+
else {
|
|
2129
|
+
response = await this.perpetualPrivatePostOrderPutMarket(request);
|
|
2130
|
+
}
|
|
2131
|
+
}
|
|
2132
|
+
}
|
|
2133
|
+
}
|
|
2043
2134
|
//
|
|
2044
2135
|
// Spot and Margin
|
|
2045
2136
|
//
|
|
@@ -2117,9 +2208,243 @@ export default class coinex extends Exchange {
|
|
|
2117
2208
|
//
|
|
2118
2209
|
// {"code":0,"data":{"status":"success"},"message":"OK"}
|
|
2119
2210
|
//
|
|
2120
|
-
const data = this.safeValue(response, 'data');
|
|
2211
|
+
const data = this.safeValue(response, 'data', {});
|
|
2121
2212
|
return this.parseOrder(data, market);
|
|
2122
2213
|
}
|
|
2214
|
+
async createOrders(orders, params = {}) {
|
|
2215
|
+
/**
|
|
2216
|
+
* @method
|
|
2217
|
+
* @name coinex#createOrders
|
|
2218
|
+
* @description create a list of trade orders (all orders should be of the same symbol)
|
|
2219
|
+
* @see https://viabtc.github.io/coinex_api_en_doc/spot/#docsspot003_trade002_batch_limit_orders
|
|
2220
|
+
* @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
|
|
2221
|
+
* @param {object} [params] extra parameters specific to the api endpoint
|
|
2222
|
+
* @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
|
|
2223
|
+
*/
|
|
2224
|
+
await this.loadMarkets();
|
|
2225
|
+
const ordersRequests = [];
|
|
2226
|
+
let symbol = undefined;
|
|
2227
|
+
for (let i = 0; i < orders.length; i++) {
|
|
2228
|
+
const rawOrder = orders[i];
|
|
2229
|
+
const marketId = this.safeString(rawOrder, 'symbol');
|
|
2230
|
+
if (symbol === undefined) {
|
|
2231
|
+
symbol = marketId;
|
|
2232
|
+
}
|
|
2233
|
+
else {
|
|
2234
|
+
if (symbol !== marketId) {
|
|
2235
|
+
throw new BadRequest(this.id + ' createOrders() requires all orders to have the same symbol');
|
|
2236
|
+
}
|
|
2237
|
+
}
|
|
2238
|
+
const type = this.safeString(rawOrder, 'type');
|
|
2239
|
+
const side = this.safeString(rawOrder, 'side');
|
|
2240
|
+
const amount = this.safeValue(rawOrder, 'amount');
|
|
2241
|
+
const price = this.safeValue(rawOrder, 'price');
|
|
2242
|
+
const orderParams = this.safeValue(rawOrder, 'params', {});
|
|
2243
|
+
if (type !== 'limit') {
|
|
2244
|
+
throw new NotSupported(this.id + ' createOrders() does not support ' + type + ' orders, only limit orders are accepted');
|
|
2245
|
+
}
|
|
2246
|
+
const orderRequest = this.createOrderRequest(marketId, type, side, amount, price, orderParams);
|
|
2247
|
+
ordersRequests.push(orderRequest);
|
|
2248
|
+
}
|
|
2249
|
+
const market = this.market(symbol);
|
|
2250
|
+
if (!market['spot']) {
|
|
2251
|
+
throw new NotSupported(this.id + ' createOrders() does not support ' + market['type'] + ' orders, only spot orders are accepted');
|
|
2252
|
+
}
|
|
2253
|
+
const request = {
|
|
2254
|
+
'market': market['id'],
|
|
2255
|
+
'batch_orders': this.json(ordersRequests),
|
|
2256
|
+
};
|
|
2257
|
+
const response = await this.privatePostOrderLimitBatch(request);
|
|
2258
|
+
//
|
|
2259
|
+
// {
|
|
2260
|
+
// "code": 0,
|
|
2261
|
+
// "data": [
|
|
2262
|
+
// {
|
|
2263
|
+
// "code": 0,
|
|
2264
|
+
// "data": {
|
|
2265
|
+
// "amount": "0.0005",
|
|
2266
|
+
// "asset_fee": "0",
|
|
2267
|
+
// "avg_price": "0.00",
|
|
2268
|
+
// "client_id": "x-167673045-d34bfb41242d8fd1",
|
|
2269
|
+
// "create_time": 1701229157,
|
|
2270
|
+
// "deal_amount": "0",
|
|
2271
|
+
// "deal_fee": "0",
|
|
2272
|
+
// "deal_money": "0",
|
|
2273
|
+
// "fee_asset": null,
|
|
2274
|
+
// "fee_discount": "1",
|
|
2275
|
+
// "finished_time": null,
|
|
2276
|
+
// "id": 107745856676,
|
|
2277
|
+
// "left": "0.0005",
|
|
2278
|
+
// "maker_fee_rate": "0.002",
|
|
2279
|
+
// "market": "BTCUSDT",
|
|
2280
|
+
// "money_fee": "0",
|
|
2281
|
+
// "order_type": "limit",
|
|
2282
|
+
// "price": "23000",
|
|
2283
|
+
// "source_id": "",
|
|
2284
|
+
// "status": "not_deal",
|
|
2285
|
+
// "stock_fee": "0",
|
|
2286
|
+
// "taker_fee_rate": "0.002",
|
|
2287
|
+
// "type": "buy"
|
|
2288
|
+
// },
|
|
2289
|
+
// "message": "OK"
|
|
2290
|
+
// },
|
|
2291
|
+
// ],
|
|
2292
|
+
// "message": "Success"
|
|
2293
|
+
// }
|
|
2294
|
+
//
|
|
2295
|
+
const data = this.safeValue(response, 'data', []);
|
|
2296
|
+
const results = [];
|
|
2297
|
+
for (let i = 0; i < data.length; i++) {
|
|
2298
|
+
const entry = data[i];
|
|
2299
|
+
let status = undefined;
|
|
2300
|
+
const code = this.safeInteger(entry, 'code');
|
|
2301
|
+
if (code !== undefined) {
|
|
2302
|
+
if (code !== 0) {
|
|
2303
|
+
status = 'rejected';
|
|
2304
|
+
}
|
|
2305
|
+
else {
|
|
2306
|
+
status = 'open';
|
|
2307
|
+
}
|
|
2308
|
+
}
|
|
2309
|
+
const item = this.safeValue(entry, 'data', {});
|
|
2310
|
+
item['status'] = status;
|
|
2311
|
+
const order = this.parseOrder(item, market);
|
|
2312
|
+
results.push(order);
|
|
2313
|
+
}
|
|
2314
|
+
return results;
|
|
2315
|
+
}
|
|
2316
|
+
async cancelOrders(ids, symbol = undefined, params = {}) {
|
|
2317
|
+
/**
|
|
2318
|
+
* @method
|
|
2319
|
+
* @name coinex#cancelOrders
|
|
2320
|
+
* @description cancel multiple orders
|
|
2321
|
+
* @see https://viabtc.github.io/coinex_api_en_doc/spot/#docsspot003_trade016_batch_cancel_order
|
|
2322
|
+
* @see https://viabtc.github.io/coinex_api_en_doc/futures/#docsfutures001_http021-0_cancel_order_batch
|
|
2323
|
+
* @param {string[]} ids order ids
|
|
2324
|
+
* @param {string} symbol unified market symbol
|
|
2325
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
2326
|
+
* @returns {object} a list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
|
|
2327
|
+
*/
|
|
2328
|
+
if (symbol === undefined) {
|
|
2329
|
+
throw new ArgumentsRequired(this.id + ' cancelOrders() requires a symbol argument');
|
|
2330
|
+
}
|
|
2331
|
+
await this.loadMarkets();
|
|
2332
|
+
const market = this.market(symbol);
|
|
2333
|
+
const request = {
|
|
2334
|
+
'market': market['id'],
|
|
2335
|
+
};
|
|
2336
|
+
const idsString = ids.join(',');
|
|
2337
|
+
let response = undefined;
|
|
2338
|
+
if (market['spot']) {
|
|
2339
|
+
request['batch_ids'] = idsString;
|
|
2340
|
+
response = await this.privateDeleteOrderPendingBatch(this.extend(request, params));
|
|
2341
|
+
}
|
|
2342
|
+
else {
|
|
2343
|
+
request['order_ids'] = idsString;
|
|
2344
|
+
response = await this.perpetualPrivatePostOrderCancelBatch(this.extend(request, params));
|
|
2345
|
+
}
|
|
2346
|
+
//
|
|
2347
|
+
// spot
|
|
2348
|
+
//
|
|
2349
|
+
// {
|
|
2350
|
+
// "code": 0,
|
|
2351
|
+
// "data": [
|
|
2352
|
+
// {
|
|
2353
|
+
// "code": 0,
|
|
2354
|
+
// "data": {
|
|
2355
|
+
// "account_id": 0,
|
|
2356
|
+
// "amount": "0.0005",
|
|
2357
|
+
// "asset_fee": "0",
|
|
2358
|
+
// "avg_price": "0.00",
|
|
2359
|
+
// "client_id": "x-167673045-d4e03c38f4d19b4e",
|
|
2360
|
+
// "create_time": 1701229157,
|
|
2361
|
+
// "deal_amount": "0",
|
|
2362
|
+
// "deal_fee": "0",
|
|
2363
|
+
// "deal_money": "0",
|
|
2364
|
+
// "fee_asset": null,
|
|
2365
|
+
// "fee_discount": "1",
|
|
2366
|
+
// "finished_time": 0,
|
|
2367
|
+
// "id": 107745856682,
|
|
2368
|
+
// "left": "0",
|
|
2369
|
+
// "maker_fee_rate": "0.002",
|
|
2370
|
+
// "market": "BTCUSDT",
|
|
2371
|
+
// "money_fee": "0",
|
|
2372
|
+
// "order_type": "limit",
|
|
2373
|
+
// "price": "22000",
|
|
2374
|
+
// "status": "not_deal",
|
|
2375
|
+
// "stock_fee": "0",
|
|
2376
|
+
// "taker_fee_rate": "0.002",
|
|
2377
|
+
// "type": "buy"
|
|
2378
|
+
// },
|
|
2379
|
+
// "message": ""
|
|
2380
|
+
// },
|
|
2381
|
+
// ],
|
|
2382
|
+
// "message": "Success"
|
|
2383
|
+
// }
|
|
2384
|
+
//
|
|
2385
|
+
// swap
|
|
2386
|
+
//
|
|
2387
|
+
// {
|
|
2388
|
+
// "code": 0,
|
|
2389
|
+
// "data": [
|
|
2390
|
+
// {
|
|
2391
|
+
// "code": 0,
|
|
2392
|
+
// "message": "",
|
|
2393
|
+
// "order": {
|
|
2394
|
+
// "amount": "0.0005",
|
|
2395
|
+
// "client_id": "x-167673045-b0cee0c584718b65",
|
|
2396
|
+
// "create_time": 1701233683.294231,
|
|
2397
|
+
// "deal_asset_fee": "0.00000000000000000000",
|
|
2398
|
+
// "deal_fee": "0.00000000000000000000",
|
|
2399
|
+
// "deal_profit": "0.00000000000000000000",
|
|
2400
|
+
// "deal_stock": "0.00000000000000000000",
|
|
2401
|
+
// "effect_type": 1,
|
|
2402
|
+
// "fee_asset": "",
|
|
2403
|
+
// "fee_discount": "0.00000000000000000000",
|
|
2404
|
+
// "last_deal_amount": "0.00000000000000000000",
|
|
2405
|
+
// "last_deal_id": 0,
|
|
2406
|
+
// "last_deal_price": "0.00000000000000000000",
|
|
2407
|
+
// "last_deal_role": 0,
|
|
2408
|
+
// "last_deal_time": 0,
|
|
2409
|
+
// "last_deal_type": 0,
|
|
2410
|
+
// "left": "0.0005",
|
|
2411
|
+
// "leverage": "3",
|
|
2412
|
+
// "maker_fee": "0.00030",
|
|
2413
|
+
// "market": "BTCUSDT",
|
|
2414
|
+
// "option": 0,
|
|
2415
|
+
// "order_id": 115940476323,
|
|
2416
|
+
// "position_id": 0,
|
|
2417
|
+
// "position_type": 2,
|
|
2418
|
+
// "price": "25000.00",
|
|
2419
|
+
// "side": 2,
|
|
2420
|
+
// "source": "api.v1",
|
|
2421
|
+
// "stop_id": 0,
|
|
2422
|
+
// "stop_loss_price": "0.00000000000000000000",
|
|
2423
|
+
// "stop_loss_type": 0,
|
|
2424
|
+
// "take_profit_price": "0.00000000000000000000",
|
|
2425
|
+
// "take_profit_type": 0,
|
|
2426
|
+
// "taker_fee": "0.00050",
|
|
2427
|
+
// "target": 0,
|
|
2428
|
+
// "type": 1,
|
|
2429
|
+
// "update_time": 1701233721.718884,
|
|
2430
|
+
// "user_id": 3620173
|
|
2431
|
+
// }
|
|
2432
|
+
// },
|
|
2433
|
+
// ],
|
|
2434
|
+
// "message": "OK"
|
|
2435
|
+
// }
|
|
2436
|
+
//
|
|
2437
|
+
const data = this.safeValue(response, 'data', []);
|
|
2438
|
+
const results = [];
|
|
2439
|
+
for (let i = 0; i < data.length; i++) {
|
|
2440
|
+
const entry = data[i];
|
|
2441
|
+
const dataRequest = market['spot'] ? 'data' : 'order';
|
|
2442
|
+
const item = this.safeValue(entry, dataRequest, {});
|
|
2443
|
+
const order = this.parseOrder(item, market);
|
|
2444
|
+
results.push(order);
|
|
2445
|
+
}
|
|
2446
|
+
return results;
|
|
2447
|
+
}
|
|
2123
2448
|
async editOrder(id, symbol, type, side, amount = undefined, price = undefined, params = {}) {
|
|
2124
2449
|
/**
|
|
2125
2450
|
* @method
|