ccxt 4.1.68__py2.py3-none-any.whl → 4.1.70__py2.py3-none-any.whl

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.
ccxt/coinex.py CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  from ccxt.base.exchange import Exchange
7
7
  from ccxt.abstract.coinex import ImplicitAPI
8
- from ccxt.base.types import Balances, Currency, Int, Market, Order, OrderSide, OrderType, Str, Strings, Ticker, Tickers, Trade, Transaction
8
+ from ccxt.base.types import Balances, Currency, Int, Market, Order, OrderRequest, OrderSide, OrderType, Str, Strings, Ticker, Tickers, Trade, Transaction
9
9
  from typing import List
10
10
  from ccxt.base.errors import ExchangeError
11
11
  from ccxt.base.errors import PermissionDenied
@@ -54,8 +54,10 @@ class coinex(Exchange, ImplicitAPI):
54
54
  'borrowIsolatedMargin': True,
55
55
  'cancelAllOrders': True,
56
56
  'cancelOrder': True,
57
+ 'cancelOrders': True,
57
58
  'createDepositAddress': True,
58
59
  'createOrder': True,
60
+ 'createOrders': True,
59
61
  'createReduceOnlyOrder': True,
60
62
  'editOrder': True,
61
63
  'fetchBalance': True,
@@ -1493,6 +1495,8 @@ class coinex(Exchange, ImplicitAPI):
1493
1495
 
1494
1496
  def parse_order_status(self, status):
1495
1497
  statuses = {
1498
+ 'rejected': 'rejected',
1499
+ 'open': 'open',
1496
1500
  'not_deal': 'open',
1497
1501
  'part_deal': 'open',
1498
1502
  'done': 'closed',
@@ -1526,7 +1530,7 @@ class coinex(Exchange, ImplicitAPI):
1526
1530
  # "client_id": "",
1527
1531
  # }
1528
1532
  #
1529
- # Spot and Margin createOrder, cancelOrder, fetchOrder
1533
+ # Spot and Margin createOrder, createOrders, cancelOrder, cancelOrders, fetchOrder
1530
1534
  #
1531
1535
  # {
1532
1536
  # "amount":"1.5",
@@ -1725,13 +1729,50 @@ class coinex(Exchange, ImplicitAPI):
1725
1729
  # "user_id": 3620173
1726
1730
  # }
1727
1731
  #
1732
+ # swap: cancelOrders
1733
+ #
1734
+ # {
1735
+ # "amount": "0.0005",
1736
+ # "client_id": "x-167673045-b0cee0c584718b65",
1737
+ # "create_time": 1701233683.294231,
1738
+ # "deal_asset_fee": "0.00000000000000000000",
1739
+ # "deal_fee": "0.00000000000000000000",
1740
+ # "deal_profit": "0.00000000000000000000",
1741
+ # "deal_stock": "0.00000000000000000000",
1742
+ # "effect_type": 1,
1743
+ # "fee_asset": "",
1744
+ # "fee_discount": "0.00000000000000000000",
1745
+ # "last_deal_amount": "0.00000000000000000000",
1746
+ # "last_deal_id": 0,
1747
+ # "last_deal_price": "0.00000000000000000000",
1748
+ # "last_deal_role": 0,
1749
+ # "last_deal_time": 0,
1750
+ # "last_deal_type": 0,
1751
+ # "left": "0.0005",
1752
+ # "leverage": "3",
1753
+ # "maker_fee": "0.00030",
1754
+ # "market": "BTCUSDT",
1755
+ # "option": 0,
1756
+ # "order_id": 115940476323,
1757
+ # "position_id": 0,
1758
+ # "position_type": 2,
1759
+ # "price": "25000.00",
1760
+ # "side": 2,
1761
+ # "source": "api.v1",
1762
+ # "stop_id": 0,
1763
+ # "stop_loss_price": "0.00000000000000000000",
1764
+ # "stop_loss_type": 0,
1765
+ # "take_profit_price": "0.00000000000000000000",
1766
+ # "take_profit_type": 0,
1767
+ # "taker_fee": "0.00050",
1768
+ # "target": 0,
1769
+ # "type": 1,
1770
+ # "update_time": 1701233721.718884,
1771
+ # "user_id": 3620173
1772
+ # }
1773
+ #
1774
+ rawStatus = self.safe_string(order, 'status')
1728
1775
  timestamp = self.safe_timestamp(order, 'create_time')
1729
- priceString = self.safe_string(order, 'price')
1730
- costString = self.safe_string(order, 'deal_money')
1731
- amountString = self.safe_string(order, 'amount')
1732
- filledString = self.safe_string(order, 'deal_amount')
1733
- averageString = self.safe_string(order, 'avg_price')
1734
- remainingString = self.safe_string(order, 'left')
1735
1776
  marketId = self.safe_string(order, 'market')
1736
1777
  defaultType = self.safe_string(self.options, 'defaultType')
1737
1778
  orderType = 'swap' if ('source' in order) else defaultType
@@ -1740,7 +1781,6 @@ class coinex(Exchange, ImplicitAPI):
1740
1781
  feeCurrency = self.safe_currency_code(feeCurrencyId)
1741
1782
  if feeCurrency is None:
1742
1783
  feeCurrency = market['quote']
1743
- status = self.parse_order_status(self.safe_string(order, 'status'))
1744
1784
  rawSide = self.safe_integer(order, 'side')
1745
1785
  side: Str = None
1746
1786
  if rawSide == 1:
@@ -1768,21 +1808,23 @@ class coinex(Exchange, ImplicitAPI):
1768
1808
  'datetime': self.iso8601(timestamp),
1769
1809
  'timestamp': timestamp,
1770
1810
  'lastTradeTimestamp': self.safe_timestamp(order, 'update_time'),
1771
- 'status': status,
1811
+ 'status': self.parse_order_status(rawStatus),
1772
1812
  'symbol': market['symbol'],
1773
1813
  'type': type,
1774
1814
  'timeInForce': None,
1775
1815
  'postOnly': None,
1776
1816
  'reduceOnly': None,
1777
1817
  'side': side,
1778
- 'price': priceString,
1818
+ 'price': self.safe_string(order, 'price'),
1779
1819
  'stopPrice': self.safe_string(order, 'stop_price'),
1780
1820
  'triggerPrice': self.safe_string(order, 'stop_price'),
1781
- 'cost': costString,
1782
- 'average': averageString,
1783
- 'amount': amountString,
1784
- 'filled': filledString,
1785
- 'remaining': remainingString,
1821
+ 'takeProfitPrice': self.safe_number(order, 'take_profit_price'),
1822
+ 'stopLossPrice': self.safe_number(order, 'stop_loss_price'),
1823
+ 'cost': self.safe_string(order, 'deal_money'),
1824
+ 'average': self.safe_string(order, 'avg_price'),
1825
+ 'amount': self.safe_string(order, 'amount'),
1826
+ 'filled': self.safe_string(order, 'deal_amount'),
1827
+ 'remaining': self.safe_string(order, 'left'),
1786
1828
  'trades': None,
1787
1829
  'fee': {
1788
1830
  'currency': feeCurrency,
@@ -1791,32 +1833,7 @@ class coinex(Exchange, ImplicitAPI):
1791
1833
  'info': order,
1792
1834
  }, market)
1793
1835
 
1794
- def create_order(self, symbol: str, type: OrderType, side: OrderSide, amount, price=None, params={}):
1795
- """
1796
- create a trade order
1797
- :see: https://viabtc.github.io/coinex_api_en_doc/futures/#docsfutures001_http017_put_limit
1798
- :see: https://viabtc.github.io/coinex_api_en_doc/futures/#docsfutures001_http018_put_market
1799
- :see: https://viabtc.github.io/coinex_api_en_doc/futures/#docsfutures001_http019_put_limit_stop
1800
- :see: https://viabtc.github.io/coinex_api_en_doc/futures/#docsfutures001_http020_put_market_stop
1801
- :see: https://viabtc.github.io/coinex_api_en_doc/futures/#docsfutures001_http031_market_close
1802
- :see: https://viabtc.github.io/coinex_api_en_doc/futures/#docsfutures001_http030_limit_close
1803
- :param str symbol: unified symbol of the market to create an order in
1804
- :param str type: 'market' or 'limit'
1805
- :param str side: 'buy' or 'sell'
1806
- :param float amount: how much of currency you want to trade in units of base currency
1807
- :param float [price]: the price at which the order is to be fullfilled, in units of the quote currency, ignored in market orders
1808
- :param dict [params]: extra parameters specific to the exchange API endpoint
1809
- :param float triggerPrice: price at which to triger stop orders
1810
- :param float stopPrice: price at which to triger stop orders
1811
- :param float stopLossPrice: price at which to trigger stop-loss orders
1812
- :param float takeProfitPrice: price at which to trigger take-profit orders
1813
- :param str [params.timeInForce]: "GTC", "IOC", "FOK", "PO"
1814
- :param bool params.postOnly:
1815
- :param bool params.reduceOnly:
1816
- :param bool [params.position_id]: *required for reduce only orders* the position id to reduce
1817
- :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
1818
- """
1819
- self.load_markets()
1836
+ def create_order_request(self, symbol, type, side, amount, price=None, params={}):
1820
1837
  market = self.market(symbol)
1821
1838
  swap = market['swap']
1822
1839
  clientOrderId = self.safe_string_2(params, 'client_id', 'clientOrderId')
@@ -1830,11 +1847,10 @@ class coinex(Exchange, ImplicitAPI):
1830
1847
  timeInForceRaw = self.safe_string(params, 'timeInForce') # Spot: IOC, FOK, PO, GTC, ... NORMAL(default), MAKER_ONLY
1831
1848
  reduceOnly = self.safe_value(params, 'reduceOnly')
1832
1849
  if reduceOnly:
1833
- if market['type'] != 'swap':
1850
+ if not market['swap']:
1834
1851
  raise InvalidOrder(self.id + ' createOrder() does not support reduceOnly for ' + market['type'] + ' orders, reduceOnly orders are supported for swap markets only')
1835
1852
  if positionId is None:
1836
1853
  raise ArgumentsRequired(self.id + ' createOrder() requires a position_id/positionId parameter for reduceOnly orders')
1837
- method = None
1838
1854
  request = {
1839
1855
  'market': market['id'],
1840
1856
  }
@@ -1851,13 +1867,10 @@ class coinex(Exchange, ImplicitAPI):
1851
1867
  raise ArgumentsRequired(self.id + ' createOrder() requires a position_id parameter for stop loss and take profit orders')
1852
1868
  request['position_id'] = positionId
1853
1869
  if stopLossPrice:
1854
- method = 'perpetualPrivatePostPositionStopLoss'
1855
1870
  request['stop_loss_price'] = self.price_to_precision(symbol, stopLossPrice)
1856
1871
  elif takeProfitPrice:
1857
- method = 'perpetualPrivatePostPositionTakeProfit'
1858
1872
  request['take_profit_price'] = self.price_to_precision(symbol, takeProfitPrice)
1859
1873
  else:
1860
- method = 'perpetualPrivatePostOrderPut' + self.capitalize(type)
1861
1874
  requestSide = 2 if (side == 'buy') else 1
1862
1875
  if stopPrice is not None:
1863
1876
  request['stop_price'] = self.price_to_precision(symbol, stopPrice)
@@ -1865,10 +1878,7 @@ class coinex(Exchange, ImplicitAPI):
1865
1878
  request['amount'] = self.amount_to_precision(symbol, amount)
1866
1879
  request['side'] = requestSide
1867
1880
  if type == 'limit':
1868
- method = 'perpetualPrivatePostOrderPutStopLimit'
1869
1881
  request['price'] = self.price_to_precision(symbol, price)
1870
- elif type == 'market':
1871
- method = 'perpetualPrivatePostOrderPutStopMarket'
1872
1882
  request['amount'] = self.amount_to_precision(symbol, amount)
1873
1883
  timeInForce = None
1874
1884
  if (type != 'market') or (stopPrice is not None):
@@ -1884,7 +1894,6 @@ class coinex(Exchange, ImplicitAPI):
1884
1894
  request['effect_type'] = timeInForce # exchange takes 'IOC' and 'FOK'
1885
1895
  if type == 'limit' and stopPrice is None:
1886
1896
  if reduceOnly:
1887
- method = 'perpetualPrivatePostOrderCloseLimit'
1888
1897
  request['position_id'] = positionId
1889
1898
  else:
1890
1899
  request['side'] = requestSide
@@ -1892,13 +1901,11 @@ class coinex(Exchange, ImplicitAPI):
1892
1901
  request['amount'] = self.amount_to_precision(symbol, amount)
1893
1902
  elif type == 'market' and stopPrice is None:
1894
1903
  if reduceOnly:
1895
- method = 'perpetualPrivatePostOrderCloseMarket'
1896
1904
  request['position_id'] = positionId
1897
1905
  else:
1898
1906
  request['side'] = requestSide
1899
1907
  request['amount'] = self.amount_to_precision(symbol, amount)
1900
1908
  else:
1901
- method = 'privatePostOrder' + self.capitalize(type)
1902
1909
  request['type'] = side
1903
1910
  if (type == 'market') and (side == 'buy'):
1904
1911
  if self.options['createMarketBuyOrderRequiresPrice']:
@@ -1918,10 +1925,6 @@ class coinex(Exchange, ImplicitAPI):
1918
1925
  request['price'] = self.price_to_precision(symbol, price)
1919
1926
  if stopPrice is not None:
1920
1927
  request['stop_price'] = self.price_to_precision(symbol, stopPrice)
1921
- if type == 'limit':
1922
- method = 'privatePostOrderStopLimit'
1923
- elif type == 'market':
1924
- method = 'privatePostOrderStopMarket'
1925
1928
  if (type != 'market') or (stopPrice is not None):
1926
1929
  # following options cannot be applied to vanilla market orders(but can be applied to stop-market orders)
1927
1930
  if (timeInForceRaw is not None) or postOnly:
@@ -1939,7 +1942,77 @@ class coinex(Exchange, ImplicitAPI):
1939
1942
  raise BadRequest(self.id + ' createOrder() requires an account_id parameter for margin orders')
1940
1943
  request['account_id'] = accountId
1941
1944
  params = self.omit(params, ['reduceOnly', 'positionId', 'timeInForce', 'postOnly', 'stopPrice', 'triggerPrice', 'stopLossPrice', 'takeProfitPrice'])
1942
- response = getattr(self, method)(self.extend(request, params))
1945
+ return self.extend(request, params)
1946
+
1947
+ def create_order(self, symbol: str, type: OrderType, side: OrderSide, amount, price=None, params={}):
1948
+ """
1949
+ create a trade order
1950
+ :see: https://viabtc.github.io/coinex_api_en_doc/futures/#docsfutures001_http017_put_limit
1951
+ :see: https://viabtc.github.io/coinex_api_en_doc/futures/#docsfutures001_http018_put_market
1952
+ :see: https://viabtc.github.io/coinex_api_en_doc/futures/#docsfutures001_http019_put_limit_stop
1953
+ :see: https://viabtc.github.io/coinex_api_en_doc/futures/#docsfutures001_http020_put_market_stop
1954
+ :see: https://viabtc.github.io/coinex_api_en_doc/futures/#docsfutures001_http031_market_close
1955
+ :see: https://viabtc.github.io/coinex_api_en_doc/futures/#docsfutures001_http030_limit_close
1956
+ :param str symbol: unified symbol of the market to create an order in
1957
+ :param str type: 'market' or 'limit'
1958
+ :param str side: 'buy' or 'sell'
1959
+ :param float amount: how much you want to trade in units of the base currency
1960
+ :param float [price]: the price at which the order is to be fullfilled, in units of the quote currency, ignored in market orders
1961
+ :param dict [params]: extra parameters specific to the exchange API endpoint
1962
+ :param float [params.triggerPrice]: price to trigger stop orders
1963
+ :param float [params.stopLossPrice]: price to trigger stop loss orders
1964
+ :param float [params.takeProfitPrice]: price to trigger take profit orders
1965
+ :param str [params.timeInForce]: 'GTC', 'IOC', 'FOK', 'PO'
1966
+ :param boolean [params.postOnly]: set to True if you wish to make a post only order
1967
+ :param boolean [params.reduceOnly]: *contract only* indicates if self order is to reduce the size of a position
1968
+ :param int [params.position_id]: *required for reduce only orders* the position id to reduce
1969
+ :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
1970
+ """
1971
+ self.load_markets()
1972
+ market = self.market(symbol)
1973
+ reduceOnly = self.safe_value(params, 'reduceOnly')
1974
+ triggerPrice = self.safe_number_2(params, 'stopPrice', 'triggerPrice')
1975
+ stopLossTriggerPrice = self.safe_number(params, 'stopLossPrice')
1976
+ takeProfitTriggerPrice = self.safe_number(params, 'takeProfitPrice')
1977
+ isTriggerOrder = triggerPrice is not None
1978
+ isStopLossTriggerOrder = stopLossTriggerPrice is not None
1979
+ isTakeProfitTriggerOrder = takeProfitTriggerPrice is not None
1980
+ isStopLossOrTakeProfitTrigger = isStopLossTriggerOrder or isTakeProfitTriggerOrder
1981
+ request = self.create_order_request(symbol, type, side, amount, price, params)
1982
+ response = None
1983
+ if market['spot']:
1984
+ if isTriggerOrder:
1985
+ if type == 'limit':
1986
+ response = self.privatePostOrderStopLimit(request)
1987
+ else:
1988
+ response = self.privatePostOrderStopMarket(request)
1989
+ else:
1990
+ if type == 'limit':
1991
+ response = self.privatePostOrderLimit(request)
1992
+ else:
1993
+ response = self.privatePostOrderMarket(request)
1994
+ else:
1995
+ if isTriggerOrder:
1996
+ if type == 'limit':
1997
+ response = self.perpetualPrivatePostOrderPutStopLimit(request)
1998
+ else:
1999
+ response = self.perpetualPrivatePostOrderPutStopMarket(request)
2000
+ elif isStopLossOrTakeProfitTrigger:
2001
+ if isStopLossTriggerOrder:
2002
+ response = self.perpetualPrivatePostPositionStopLoss(request)
2003
+ elif isTakeProfitTriggerOrder:
2004
+ response = self.perpetualPrivatePostPositionTakeProfit(request)
2005
+ else:
2006
+ if reduceOnly:
2007
+ if type == 'limit':
2008
+ response = self.perpetualPrivatePostOrderCloseLimit(request)
2009
+ else:
2010
+ response = self.perpetualPrivatePostOrderCloseMarket(request)
2011
+ else:
2012
+ if type == 'limit':
2013
+ response = self.perpetualPrivatePostOrderPutLimit(request)
2014
+ else:
2015
+ response = self.perpetualPrivatePostOrderPutMarket(request)
1943
2016
  #
1944
2017
  # Spot and Margin
1945
2018
  #
@@ -2017,9 +2090,225 @@ class coinex(Exchange, ImplicitAPI):
2017
2090
  #
2018
2091
  # {"code":0,"data":{"status":"success"},"message":"OK"}
2019
2092
  #
2020
- data = self.safe_value(response, 'data')
2093
+ data = self.safe_value(response, 'data', {})
2021
2094
  return self.parse_order(data, market)
2022
2095
 
2096
+ def create_orders(self, orders: List[OrderRequest], params={}) -> List[Order]:
2097
+ """
2098
+ create a list of trade orders(all orders should be of the same symbol)
2099
+ :see: https://viabtc.github.io/coinex_api_en_doc/spot/#docsspot003_trade002_batch_limit_orders
2100
+ :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
2101
+ :param dict [params]: extra parameters specific to the api endpoint
2102
+ :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
2103
+ """
2104
+ self.load_markets()
2105
+ ordersRequests = []
2106
+ symbol = None
2107
+ for i in range(0, len(orders)):
2108
+ rawOrder = orders[i]
2109
+ marketId = self.safe_string(rawOrder, 'symbol')
2110
+ if symbol is None:
2111
+ symbol = marketId
2112
+ else:
2113
+ if symbol != marketId:
2114
+ raise BadRequest(self.id + ' createOrders() requires all orders to have the same symbol')
2115
+ type = self.safe_string(rawOrder, 'type')
2116
+ side = self.safe_string(rawOrder, 'side')
2117
+ amount = self.safe_value(rawOrder, 'amount')
2118
+ price = self.safe_value(rawOrder, 'price')
2119
+ orderParams = self.safe_value(rawOrder, 'params', {})
2120
+ if type != 'limit':
2121
+ raise NotSupported(self.id + ' createOrders() does not support ' + type + ' orders, only limit orders are accepted')
2122
+ orderRequest = self.create_order_request(marketId, type, side, amount, price, orderParams)
2123
+ ordersRequests.append(orderRequest)
2124
+ market = self.market(symbol)
2125
+ if not market['spot']:
2126
+ raise NotSupported(self.id + ' createOrders() does not support ' + market['type'] + ' orders, only spot orders are accepted')
2127
+ request = {
2128
+ 'market': market['id'],
2129
+ 'batch_orders': self.json(ordersRequests),
2130
+ }
2131
+ response = self.privatePostOrderLimitBatch(request)
2132
+ #
2133
+ # {
2134
+ # "code": 0,
2135
+ # "data": [
2136
+ # {
2137
+ # "code": 0,
2138
+ # "data": {
2139
+ # "amount": "0.0005",
2140
+ # "asset_fee": "0",
2141
+ # "avg_price": "0.00",
2142
+ # "client_id": "x-167673045-d34bfb41242d8fd1",
2143
+ # "create_time": 1701229157,
2144
+ # "deal_amount": "0",
2145
+ # "deal_fee": "0",
2146
+ # "deal_money": "0",
2147
+ # "fee_asset": null,
2148
+ # "fee_discount": "1",
2149
+ # "finished_time": null,
2150
+ # "id": 107745856676,
2151
+ # "left": "0.0005",
2152
+ # "maker_fee_rate": "0.002",
2153
+ # "market": "BTCUSDT",
2154
+ # "money_fee": "0",
2155
+ # "order_type": "limit",
2156
+ # "price": "23000",
2157
+ # "source_id": "",
2158
+ # "status": "not_deal",
2159
+ # "stock_fee": "0",
2160
+ # "taker_fee_rate": "0.002",
2161
+ # "type": "buy"
2162
+ # },
2163
+ # "message": "OK"
2164
+ # },
2165
+ # ],
2166
+ # "message": "Success"
2167
+ # }
2168
+ #
2169
+ data = self.safe_value(response, 'data', [])
2170
+ results = []
2171
+ for i in range(0, len(data)):
2172
+ entry = data[i]
2173
+ status = None
2174
+ code = self.safe_integer(entry, 'code')
2175
+ if code is not None:
2176
+ if code != 0:
2177
+ status = 'rejected'
2178
+ else:
2179
+ status = 'open'
2180
+ item = self.safe_value(entry, 'data', {})
2181
+ item['status'] = status
2182
+ order = self.parse_order(item, market)
2183
+ results.append(order)
2184
+ return results
2185
+
2186
+ def cancel_orders(self, ids, symbol: Str = None, params={}):
2187
+ """
2188
+ cancel multiple orders
2189
+ :see: https://viabtc.github.io/coinex_api_en_doc/spot/#docsspot003_trade016_batch_cancel_order
2190
+ :see: https://viabtc.github.io/coinex_api_en_doc/futures/#docsfutures001_http021-0_cancel_order_batch
2191
+ :param str[] ids: order ids
2192
+ :param str symbol: unified market symbol
2193
+ :param dict [params]: extra parameters specific to the exchange API endpoint
2194
+ :returns dict: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
2195
+ """
2196
+ if symbol is None:
2197
+ raise ArgumentsRequired(self.id + ' cancelOrders() requires a symbol argument')
2198
+ self.load_markets()
2199
+ market = self.market(symbol)
2200
+ request = {
2201
+ 'market': market['id'],
2202
+ }
2203
+ idsString = ','.join(ids)
2204
+ response = None
2205
+ if market['spot']:
2206
+ request['batch_ids'] = idsString
2207
+ response = self.privateDeleteOrderPendingBatch(self.extend(request, params))
2208
+ else:
2209
+ request['order_ids'] = idsString
2210
+ response = self.perpetualPrivatePostOrderCancelBatch(self.extend(request, params))
2211
+ #
2212
+ # spot
2213
+ #
2214
+ # {
2215
+ # "code": 0,
2216
+ # "data": [
2217
+ # {
2218
+ # "code": 0,
2219
+ # "data": {
2220
+ # "account_id": 0,
2221
+ # "amount": "0.0005",
2222
+ # "asset_fee": "0",
2223
+ # "avg_price": "0.00",
2224
+ # "client_id": "x-167673045-d4e03c38f4d19b4e",
2225
+ # "create_time": 1701229157,
2226
+ # "deal_amount": "0",
2227
+ # "deal_fee": "0",
2228
+ # "deal_money": "0",
2229
+ # "fee_asset": null,
2230
+ # "fee_discount": "1",
2231
+ # "finished_time": 0,
2232
+ # "id": 107745856682,
2233
+ # "left": "0",
2234
+ # "maker_fee_rate": "0.002",
2235
+ # "market": "BTCUSDT",
2236
+ # "money_fee": "0",
2237
+ # "order_type": "limit",
2238
+ # "price": "22000",
2239
+ # "status": "not_deal",
2240
+ # "stock_fee": "0",
2241
+ # "taker_fee_rate": "0.002",
2242
+ # "type": "buy"
2243
+ # },
2244
+ # "message": ""
2245
+ # },
2246
+ # ],
2247
+ # "message": "Success"
2248
+ # }
2249
+ #
2250
+ # swap
2251
+ #
2252
+ # {
2253
+ # "code": 0,
2254
+ # "data": [
2255
+ # {
2256
+ # "code": 0,
2257
+ # "message": "",
2258
+ # "order": {
2259
+ # "amount": "0.0005",
2260
+ # "client_id": "x-167673045-b0cee0c584718b65",
2261
+ # "create_time": 1701233683.294231,
2262
+ # "deal_asset_fee": "0.00000000000000000000",
2263
+ # "deal_fee": "0.00000000000000000000",
2264
+ # "deal_profit": "0.00000000000000000000",
2265
+ # "deal_stock": "0.00000000000000000000",
2266
+ # "effect_type": 1,
2267
+ # "fee_asset": "",
2268
+ # "fee_discount": "0.00000000000000000000",
2269
+ # "last_deal_amount": "0.00000000000000000000",
2270
+ # "last_deal_id": 0,
2271
+ # "last_deal_price": "0.00000000000000000000",
2272
+ # "last_deal_role": 0,
2273
+ # "last_deal_time": 0,
2274
+ # "last_deal_type": 0,
2275
+ # "left": "0.0005",
2276
+ # "leverage": "3",
2277
+ # "maker_fee": "0.00030",
2278
+ # "market": "BTCUSDT",
2279
+ # "option": 0,
2280
+ # "order_id": 115940476323,
2281
+ # "position_id": 0,
2282
+ # "position_type": 2,
2283
+ # "price": "25000.00",
2284
+ # "side": 2,
2285
+ # "source": "api.v1",
2286
+ # "stop_id": 0,
2287
+ # "stop_loss_price": "0.00000000000000000000",
2288
+ # "stop_loss_type": 0,
2289
+ # "take_profit_price": "0.00000000000000000000",
2290
+ # "take_profit_type": 0,
2291
+ # "taker_fee": "0.00050",
2292
+ # "target": 0,
2293
+ # "type": 1,
2294
+ # "update_time": 1701233721.718884,
2295
+ # "user_id": 3620173
2296
+ # }
2297
+ # },
2298
+ # ],
2299
+ # "message": "OK"
2300
+ # }
2301
+ #
2302
+ data = self.safe_value(response, 'data', [])
2303
+ results = []
2304
+ for i in range(0, len(data)):
2305
+ entry = data[i]
2306
+ dataRequest = 'data' if market['spot'] else 'order'
2307
+ item = self.safe_value(entry, dataRequest, {})
2308
+ order = self.parse_order(item, market)
2309
+ results.append(order)
2310
+ return results
2311
+
2023
2312
  def edit_order(self, id, symbol, type, side, amount=None, price=None, params={}):
2024
2313
  """
2025
2314
  edit a trade order
ccxt/phemex.py CHANGED
@@ -161,7 +161,8 @@ class phemex(Exchange, ImplicitAPI):
161
161
  },
162
162
  'v1': {
163
163
  'get': {
164
- 'md/orderbook': 5, # ?symbol=<symbol>&id=<id>
164
+ 'md/fullbook': 5, # ?symbol=<symbol>
165
+ 'md/orderbook': 5, # ?symbol=<symbol>
165
166
  'md/trade': 5, # ?symbol=<symbol>&id=<id>
166
167
  'md/ticker/24hr': 5, # ?symbol=<symbol>&id=<id>
167
168
  'md/ticker/24hr/all': 5, # ?id=<id>
@@ -214,6 +215,11 @@ class phemex(Exchange, ImplicitAPI):
214
215
  'phemex-user/users/children': 5, # ?offset=<offset>&limit=<limit>&withCount=<withCount>
215
216
  'phemex-user/wallets/v2/depositAddress': 5, # ?_t=1592722635531&currency=USDT
216
217
  'phemex-user/wallets/tradeAccountDetail': 5, # ?bizCode=&currency=&end=1642443347321&limit=10&offset=0&side=&start=1&type=4&withCount=true
218
+ 'phemex-deposit/wallets/api/depositAddress': 5, # ?currency=<currency>&chainName=<chainName>
219
+ 'phemex-deposit/wallets/api/depositHist': 5, # ?currency=<currency>&offset=<offset>&limit=<limit>&withCount=<withCount>
220
+ 'phemex-deposit/wallets/api/chainCfg': 5, # ?currency=<currency>
221
+ 'phemex-withdraw/wallets/api/withdrawHist': 5, # ?currency=<currency>&chainName=<chainNameList>&offset=<offset>&limit=<limit>&withCount=<withCount>
222
+ 'phemex-withdraw/wallets/api/asset/info': 5, # ?currency=<currency>&amount=<amount>
217
223
  'phemex-user/order/closedPositionList': 5, # ?currency=USD&limit=10&offset=0&symbol=&withCount=true
218
224
  'exchange/margins/transfer': 5, # ?start=<start>&end=<end>&offset=<offset>&limit=<limit>&withCount=<withCount>
219
225
  'exchange/wallets/confirm/withdraw': 5, # ?code=<withdrawConfirmCode>
@@ -252,6 +258,9 @@ class phemex(Exchange, ImplicitAPI):
252
258
  'assets/futures/sub-accounts/transfer': 5, # for sub-account only
253
259
  'assets/universal-transfer': 5, # for Main account only
254
260
  'assets/convert': 5,
261
+ # withdraw
262
+ 'phemex-withdraw/wallets/api/createWithdraw': 5, # ?currency=<currency>&address=<address>&amount=<amount>&addressTag=<addressTag>&chainName=<chainName>
263
+ 'phemex-withdraw/wallets/api/cancelWithdraw': 5, # ?id=<id>
255
264
  },
256
265
  'put': {
257
266
  # spot
@@ -987,7 +996,10 @@ class phemex(Exchange, ImplicitAPI):
987
996
  if market['linear'] and market['settle'] == 'USDT':
988
997
  response = self.v2GetMdV2Orderbook(self.extend(request, params))
989
998
  else:
990
- response = self.v1GetMdOrderbook(self.extend(request, params))
999
+ if (limit is not None) and (limit <= 30):
1000
+ response = self.v1GetMdOrderbook(self.extend(request, params))
1001
+ else:
1002
+ response = self.v1GetMdFullbook(self.extend(request, params))
991
1003
  #
992
1004
  # {
993
1005
  # "error": null,
ccxt/pro/__init__.py CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  # ----------------------------------------------------------------------------
6
6
 
7
- __version__ = '4.1.68'
7
+ __version__ = '4.1.70'
8
8
 
9
9
  # ----------------------------------------------------------------------------
10
10
 
ccxt/pro/binance.py CHANGED
@@ -55,8 +55,8 @@ class binance(ccxt.async_support.binance):
55
55
  },
56
56
  'api': {
57
57
  'ws': {
58
- 'spot': 'wss://stream.binance.com:9443/ws',
59
- 'margin': 'wss://stream.binance.com:9443/ws',
58
+ 'spot': 'wss://stream.binance.com/ws',
59
+ 'margin': 'wss://stream.binance.com/ws',
60
60
  'future': 'wss://fstream.binance.com/ws',
61
61
  'delivery': 'wss://dstream.binance.com/ws',
62
62
  'ws': 'wss://ws-api.binance.com:443/ws-api/v3',
ccxt/pro/htx.py CHANGED
@@ -334,9 +334,10 @@ class htx(ccxt.async_support.htx):
334
334
  # which means whenever there is an order book change at that level, it pushes an update
335
335
  # 150-levels/400-level incremental MBP feed is based on the gap
336
336
  # between two snapshots at 100ms interval.
337
- limit = 20 if (limit is None) else limit
337
+ if limit is None:
338
+ limit = 150 if market['spot'] else 20
338
339
  if not self.in_array(limit, allowedLimits):
339
- raise ExchangeError(self.id + ' watchOrderBook swap market accepts limits of 20 and 150 only')
340
+ raise ExchangeError(self.id + ' watchOrderBook market accepts limits of 20 and 150 only')
340
341
  messageHash = None
341
342
  if market['spot']:
342
343
  messageHash = 'market.' + market['id'] + '.mbp.' + str(limit)