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