ccxt 4.4.90__py2.py3-none-any.whl → 4.4.92__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.
Files changed (71) hide show
  1. ccxt/__init__.py +1 -3
  2. ccxt/abstract/lbank.py +1 -0
  3. ccxt/async_support/__init__.py +1 -3
  4. ccxt/async_support/base/exchange.py +6 -3
  5. ccxt/async_support/base/ws/client.py +173 -64
  6. ccxt/async_support/base/ws/future.py +23 -50
  7. ccxt/async_support/binance.py +1 -1
  8. ccxt/async_support/bitmart.py +7 -0
  9. ccxt/async_support/bitmex.py +2 -1
  10. ccxt/async_support/bitvavo.py +7 -1
  11. ccxt/async_support/cex.py +61 -0
  12. ccxt/async_support/cryptocom.py +17 -2
  13. ccxt/async_support/cryptomus.py +1 -1
  14. ccxt/async_support/exmo.py +25 -10
  15. ccxt/async_support/gate.py +2 -2
  16. ccxt/async_support/htx.py +1 -1
  17. ccxt/async_support/hyperliquid.py +104 -53
  18. ccxt/async_support/kraken.py +26 -1
  19. ccxt/async_support/krakenfutures.py +1 -1
  20. ccxt/async_support/lbank.py +113 -33
  21. ccxt/async_support/mexc.py +1 -0
  22. ccxt/async_support/modetrade.py +2 -2
  23. ccxt/async_support/okx.py +2 -2
  24. ccxt/async_support/paradex.py +1 -1
  25. ccxt/base/exchange.py +22 -23
  26. ccxt/base/types.py +1 -0
  27. ccxt/binance.py +1 -1
  28. ccxt/bitmart.py +7 -0
  29. ccxt/bitmex.py +2 -1
  30. ccxt/bitvavo.py +7 -1
  31. ccxt/cex.py +61 -0
  32. ccxt/cryptocom.py +17 -2
  33. ccxt/cryptomus.py +1 -1
  34. ccxt/exmo.py +24 -10
  35. ccxt/gate.py +2 -2
  36. ccxt/htx.py +1 -1
  37. ccxt/hyperliquid.py +104 -53
  38. ccxt/kraken.py +26 -1
  39. ccxt/krakenfutures.py +1 -1
  40. ccxt/lbank.py +113 -33
  41. ccxt/mexc.py +1 -0
  42. ccxt/modetrade.py +2 -2
  43. ccxt/okx.py +2 -2
  44. ccxt/paradex.py +1 -1
  45. ccxt/pro/__init__.py +1 -1
  46. ccxt/pro/bitstamp.py +1 -1
  47. ccxt/pro/bybit.py +9 -140
  48. ccxt/pro/kraken.py +246 -258
  49. ccxt/pro/mexc.py +0 -1
  50. {ccxt-4.4.90.dist-info → ccxt-4.4.92.dist-info}/METADATA +6 -7
  51. {ccxt-4.4.90.dist-info → ccxt-4.4.92.dist-info}/RECORD +54 -71
  52. ccxt/abstract/coinlist.py +0 -57
  53. ccxt/async_support/base/ws/aiohttp_client.py +0 -147
  54. ccxt/async_support/bitcoincom.py +0 -18
  55. ccxt/async_support/bitfinex1.py +0 -1711
  56. ccxt/async_support/bitpanda.py +0 -17
  57. ccxt/async_support/coinlist.py +0 -2542
  58. ccxt/async_support/poloniexfutures.py +0 -1875
  59. ccxt/bitcoincom.py +0 -18
  60. ccxt/bitfinex1.py +0 -1710
  61. ccxt/bitpanda.py +0 -17
  62. ccxt/coinlist.py +0 -2542
  63. ccxt/poloniexfutures.py +0 -1875
  64. ccxt/pro/bitcoincom.py +0 -35
  65. ccxt/pro/bitfinex1.py +0 -635
  66. ccxt/pro/bitpanda.py +0 -16
  67. ccxt/pro/poloniexfutures.py +0 -1004
  68. ccxt/pro/wazirx.py +0 -766
  69. {ccxt-4.4.90.dist-info → ccxt-4.4.92.dist-info}/LICENSE.txt +0 -0
  70. {ccxt-4.4.90.dist-info → ccxt-4.4.92.dist-info}/WHEEL +0 -0
  71. {ccxt-4.4.90.dist-info → ccxt-4.4.92.dist-info}/top_level.txt +0 -0
ccxt/__init__.py CHANGED
@@ -22,7 +22,7 @@
22
22
 
23
23
  # ----------------------------------------------------------------------------
24
24
 
25
- __version__ = '4.4.90'
25
+ __version__ = '4.4.92'
26
26
 
27
27
  # ----------------------------------------------------------------------------
28
28
 
@@ -124,7 +124,6 @@ from ccxt.coinbaseinternational import coinbaseinternational # noqa: F4
124
124
  from ccxt.coincatch import coincatch # noqa: F401
125
125
  from ccxt.coincheck import coincheck # noqa: F401
126
126
  from ccxt.coinex import coinex # noqa: F401
127
- from ccxt.coinlist import coinlist # noqa: F401
128
127
  from ccxt.coinmate import coinmate # noqa: F401
129
128
  from ccxt.coinmetro import coinmetro # noqa: F401
130
129
  from ccxt.coinone import coinone # noqa: F401
@@ -232,7 +231,6 @@ exchanges = [
232
231
  'coincatch',
233
232
  'coincheck',
234
233
  'coinex',
235
- 'coinlist',
236
234
  'coinmate',
237
235
  'coinmetro',
238
236
  'coinone',
ccxt/abstract/lbank.py CHANGED
@@ -5,6 +5,7 @@ class ImplicitAPI:
5
5
  spot_public_get_currencypairs = spotPublicGetCurrencyPairs = Entry('currencyPairs', ['spot', 'public'], 'GET', {'cost': 2.5})
6
6
  spot_public_get_accuracy = spotPublicGetAccuracy = Entry('accuracy', ['spot', 'public'], 'GET', {'cost': 2.5})
7
7
  spot_public_get_usdtocny = spotPublicGetUsdToCny = Entry('usdToCny', ['spot', 'public'], 'GET', {'cost': 2.5})
8
+ spot_public_get_assetconfigs = spotPublicGetAssetConfigs = Entry('assetConfigs', ['spot', 'public'], 'GET', {'cost': 2.5})
8
9
  spot_public_get_withdrawconfigs = spotPublicGetWithdrawConfigs = Entry('withdrawConfigs', ['spot', 'public'], 'GET', {'cost': 2.5})
9
10
  spot_public_get_timestamp = spotPublicGetTimestamp = Entry('timestamp', ['spot', 'public'], 'GET', {'cost': 2.5})
10
11
  spot_public_get_ticker_24hr = spotPublicGetTicker24hr = Entry('ticker/24hr', ['spot', 'public'], 'GET', {'cost': 2.5})
@@ -4,7 +4,7 @@
4
4
 
5
5
  # -----------------------------------------------------------------------------
6
6
 
7
- __version__ = '4.4.90'
7
+ __version__ = '4.4.92'
8
8
 
9
9
  # -----------------------------------------------------------------------------
10
10
 
@@ -104,7 +104,6 @@ from ccxt.async_support.coinbaseinternational import coinbaseinternational
104
104
  from ccxt.async_support.coincatch import coincatch # noqa: F401
105
105
  from ccxt.async_support.coincheck import coincheck # noqa: F401
106
106
  from ccxt.async_support.coinex import coinex # noqa: F401
107
- from ccxt.async_support.coinlist import coinlist # noqa: F401
108
107
  from ccxt.async_support.coinmate import coinmate # noqa: F401
109
108
  from ccxt.async_support.coinmetro import coinmetro # noqa: F401
110
109
  from ccxt.async_support.coinone import coinone # noqa: F401
@@ -212,7 +211,6 @@ exchanges = [
212
211
  'coincatch',
213
212
  'coincheck',
214
213
  'coinex',
215
- 'coinlist',
216
214
  'coinmate',
217
215
  'coinmetro',
218
216
  'coinone',
@@ -2,7 +2,7 @@
2
2
 
3
3
  # -----------------------------------------------------------------------------
4
4
 
5
- __version__ = '4.4.90'
5
+ __version__ = '4.4.92'
6
6
 
7
7
  # -----------------------------------------------------------------------------
8
8
 
@@ -34,7 +34,7 @@ from ccxt.base.exchange import Exchange as BaseExchange, ArgumentsRequired
34
34
  # -----------------------------------------------------------------------------
35
35
 
36
36
  from ccxt.async_support.base.ws.functions import inflate, inflate64, gunzip
37
- from ccxt.async_support.base.ws.aiohttp_client import AiohttpClient
37
+ from ccxt.async_support.base.ws.client import Client
38
38
  from ccxt.async_support.base.ws.future import Future
39
39
  from ccxt.async_support.base.ws.order_book import OrderBook, IndexedOrderBook, CountedOrderBook
40
40
 
@@ -419,7 +419,7 @@ class Exchange(BaseExchange):
419
419
  }, ws_options)
420
420
  # we use aiohttp instead of fastClient now because of this
421
421
  # https://github.com/ccxt/ccxt/pull/25995
422
- self.clients[url] = AiohttpClient(url, on_message, on_error, on_close, on_connected, options)
422
+ self.clients[url] = Client(url, on_message, on_error, on_close, on_connected, options)
423
423
  # set http/s proxy (socks proxy should be set in other place)
424
424
  httpProxy, httpsProxy, socksProxy = self.check_ws_proxy_settings()
425
425
  if (httpProxy or httpsProxy):
@@ -638,6 +638,9 @@ class Exchange(BaseExchange):
638
638
  async def watch_trades(self, symbol: str, since: Int = None, limit: Int = None, params={}):
639
639
  raise NotSupported(self.id + ' watchTrades() is not supported yet')
640
640
 
641
+ async def un_watch_orders(self, symbol: Str = None, params={}):
642
+ raise NotSupported(self.id + ' unWatchOrders() is not supported yet')
643
+
641
644
  async def un_watch_trades(self, symbol: str, params={}):
642
645
  raise NotSupported(self.id + ' unWatchTrades() is not supported yet')
643
646
 
@@ -1,21 +1,31 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
- from asyncio import sleep, ensure_future, wait_for, TimeoutError
4
- from .functions import milliseconds, iso8601, deep_extend
5
- from ccxt import NetworkError, RequestTimeout, NotSupported
3
+ orjson = None
4
+ try:
5
+ import orjson as orjson
6
+ except ImportError:
7
+ pass
8
+
9
+ import json
10
+
11
+ from asyncio import sleep, ensure_future, wait_for, TimeoutError, BaseEventLoop, Future as asyncioFuture
12
+ from .functions import milliseconds, iso8601, deep_extend, is_json_encoded_object
13
+ from ccxt import NetworkError, RequestTimeout
6
14
  from ccxt.async_support.base.ws.future import Future
7
- from collections import deque
15
+ from ccxt.async_support.base.ws.functions import gunzip, inflate
16
+ from typing import Dict
17
+
18
+ from aiohttp import WSMsgType
19
+
8
20
 
9
21
  class Client(object):
10
22
 
11
23
  url = None
12
24
  ws = None
13
- futures = {}
25
+ futures: Dict[str, Future] = {}
14
26
  options = {} # ws-specific options
15
27
  subscriptions = {}
16
28
  rejections = {}
17
- message_queue = {}
18
- useMessageQueue = False
19
29
  on_message_callback = None
20
30
  on_error_callback = None
21
31
  on_close_callback = None
@@ -32,14 +42,14 @@ class Client(object):
32
42
  maxPingPongMisses = 2.0 # how many missed pongs to raise a timeout
33
43
  lastPong = None
34
44
  ping = None # ping-function if defined
45
+ proxy = None
35
46
  verbose = False # verbose output
36
47
  gunzip = False
37
48
  inflate = False
38
49
  throttle = None
39
50
  connecting = False
40
- asyncio_loop = None
51
+ asyncio_loop: BaseEventLoop = None
41
52
  ping_looper = None
42
- receive_looper = None
43
53
 
44
54
  def __init__(self, url, on_message_callback, on_error_callback, on_close_callback, on_connected_callback, config={}):
45
55
  defaults = {
@@ -70,37 +80,19 @@ class Client(object):
70
80
  if message_hash in self.rejections:
71
81
  future.reject(self.rejections[message_hash])
72
82
  del self.rejections[message_hash]
73
- del self.message_queue[message_hash]
74
- return future
75
- if self.useMessageQueue and message_hash in self.message_queue:
76
- queue = self.message_queue[message_hash]
77
- if len(queue):
78
- future.resolve(queue.popleft())
79
- del self.futures[message_hash]
80
83
  return future
81
84
 
82
85
  def resolve(self, result, message_hash):
83
86
  if self.verbose and message_hash is None:
84
87
  self.log(iso8601(milliseconds()), 'resolve received None messageHash')
85
-
86
- if self.useMessageQueue:
87
- if message_hash not in self.message_queue:
88
- self.message_queue[message_hash] = deque(maxlen=10)
89
- queue = self.message_queue[message_hash]
90
- queue.append(result)
91
- if message_hash in self.futures:
92
- future = self.futures[message_hash]
93
- future.resolve(queue.popleft())
94
- del self.futures[message_hash]
95
- else:
96
- if message_hash in self.futures:
97
- future = self.futures[message_hash]
98
- future.resolve(result)
99
- del self.futures[message_hash]
88
+ if message_hash in self.futures:
89
+ future = self.futures[message_hash]
90
+ future.resolve(result)
91
+ del self.futures[message_hash]
100
92
  return result
101
93
 
102
94
  def reject(self, result, message_hash=None):
103
- if message_hash:
95
+ if message_hash is not None:
104
96
  if message_hash in self.futures:
105
97
  future = self.futures[message_hash]
106
98
  future.reject(result)
@@ -113,19 +105,38 @@ class Client(object):
113
105
  self.reject(result, message_hash)
114
106
  return result
115
107
 
116
- async def receive_loop(self):
108
+ def receive_loop(self):
117
109
  if self.verbose:
118
110
  self.log(iso8601(milliseconds()), 'receive loop')
119
- while not self.closed():
120
- try:
121
- message = await self.receive()
122
- # self.log(iso8601(milliseconds()), 'received', message)
123
- self.handle_message(message)
124
- except Exception as e:
125
- error = NetworkError(str(e))
126
- if self.verbose:
127
- self.log(iso8601(milliseconds()), 'receive_loop', 'Exception', error)
128
- self.reset(error)
111
+ if not self.closed():
112
+ # let's drain the aiohttp buffer to avoid latency
113
+ if len(self.buffer) > 1:
114
+ size_delta = 0
115
+ while len(self.buffer) > 1:
116
+ message, size = self.buffer.popleft()
117
+ size_delta += size
118
+ self.handle_message(message)
119
+ # we must update the size of the last message inside WebSocketDataQueue
120
+ # self.receive() calls WebSocketDataQueue.read() that calls WebSocketDataQueue._read_from_buffer()
121
+ # which updates the size of the buffer, the _size will overflow and pause the transport
122
+ # make sure to set the enviroment variable AIOHTTP_NO_EXTENSIONS=Y to check
123
+ # print(self.connection._conn.protocol._payload._size)
124
+ self.buffer[0] = (self.buffer[0][0], self.buffer[0][1] + size_delta)
125
+
126
+ task = self.asyncio_loop.create_task(self.receive())
127
+
128
+ def after_interrupt(resolved: asyncioFuture):
129
+ exception = resolved.exception()
130
+ if exception is None:
131
+ self.handle_message(resolved.result())
132
+ self.asyncio_loop.call_soon(self.receive_loop)
133
+ else:
134
+ error = NetworkError(str(exception))
135
+ if self.verbose:
136
+ self.log(iso8601(milliseconds()), 'receive_loop', 'Exception', error)
137
+ self.reject(error)
138
+
139
+ task.add_done_callback(after_interrupt)
129
140
 
130
141
  async def open(self, session, backoff_delay=0):
131
142
  # exponential backoff for consequent connections if necessary
@@ -146,7 +157,7 @@ class Client(object):
146
157
  self.on_connected_callback(self)
147
158
  # run both loops forever
148
159
  self.ping_looper = ensure_future(self.ping_loop(), loop=self.asyncio_loop)
149
- self.receive_looper = ensure_future(self.receive_loop(), loop=self.asyncio_loop)
160
+ self.asyncio_loop.call_soon(self.receive_loop)
150
161
  except TimeoutError:
151
162
  # connection timeout
152
163
  error = RequestTimeout('Connection timeout')
@@ -160,6 +171,13 @@ class Client(object):
160
171
  self.log(iso8601(milliseconds()), 'NetworkError', error)
161
172
  self.on_error(error)
162
173
 
174
+ @property
175
+ def buffer(self):
176
+ # looks like they exposed it in C
177
+ # this means we can bypass it
178
+ # https://github.com/aio-libs/aiohttp/blob/master/aiohttp/_websocket/reader_c.pxd#L53C24-L53C31
179
+ return self.connection._conn.protocol._payload._buffer
180
+
163
181
  def connect(self, session, backoff_delay=0):
164
182
  if not self.connection and not self.connecting:
165
183
  self.connecting = True
@@ -170,7 +188,7 @@ class Client(object):
170
188
  if self.verbose:
171
189
  self.log(iso8601(milliseconds()), 'on_error', error)
172
190
  self.error = error
173
- self.reset(error)
191
+ self.reject(error)
174
192
  self.on_error_callback(self, error)
175
193
  if not self.closed():
176
194
  ensure_future(self.close(1006), loop=self.asyncio_loop)
@@ -179,36 +197,127 @@ class Client(object):
179
197
  if self.verbose:
180
198
  self.log(iso8601(milliseconds()), 'on_close', code)
181
199
  if not self.error:
182
- self.reset(NetworkError('Connection closed by remote server, closing code ' + str(code)))
200
+ self.reject(NetworkError('Connection closed by remote server, closing code ' + str(code)))
183
201
  self.on_close_callback(self, code)
184
- if not self.closed():
185
- ensure_future(self.close(code), loop=self.asyncio_loop)
202
+ ensure_future(self.aiohttp_close(), loop=self.asyncio_loop)
186
203
 
187
- def reset(self, error):
188
- self.message_queue = {}
189
- self.reject(error)
204
+ def log(self, *args):
205
+ print(*args)
190
206
 
191
- async def ping_loop(self):
192
- if self.verbose:
193
- self.log(iso8601(milliseconds()), 'ping loop')
207
+ def closed(self):
208
+ return (self.connection is None) or self.connection.closed
194
209
 
195
210
  def receive(self):
196
- raise NotSupported('receive() not implemented')
211
+ return self.connection.receive()
212
+
213
+ # helper method for binary and text messages
214
+ def handle_text_or_binary_message(self, data):
215
+ if self.verbose:
216
+ self.log(iso8601(milliseconds()), 'message', data)
217
+ if isinstance(data, bytes):
218
+ data = data.decode()
219
+ # decoded = json.loads(data) if is_json_encoded_object(data) else data
220
+ decode = None
221
+ if is_json_encoded_object(data):
222
+ if orjson is None:
223
+ decode = json.loads(data)
224
+ else:
225
+ decode = orjson.loads(data)
226
+ else:
227
+ decode = data
228
+ self.on_message_callback(self, decode)
197
229
 
198
230
  def handle_message(self, message):
199
- raise NotSupported('handle_message() not implemented')
231
+ # self.log(iso8601(milliseconds()), message)
232
+ if message.type == WSMsgType.TEXT:
233
+ self.handle_text_or_binary_message(message.data)
234
+ elif message.type == WSMsgType.BINARY:
235
+ data = message.data
236
+ if self.gunzip:
237
+ data = gunzip(data)
238
+ elif self.inflate:
239
+ data = inflate(data)
240
+ self.handle_text_or_binary_message(data)
241
+ # autoping is responsible for automatically replying with pong
242
+ # to a ping incoming from a server, we have to disable autoping
243
+ # with aiohttp's websockets and respond with pong manually
244
+ # otherwise aiohttp's websockets client won't trigger WSMsgType.PONG
245
+ elif message.type == WSMsgType.PING:
246
+ if self.verbose:
247
+ self.log(iso8601(milliseconds()), 'ping', message)
248
+ ensure_future(self.connection.pong(message.data), loop=self.asyncio_loop)
249
+ elif message.type == WSMsgType.PONG:
250
+ self.lastPong = milliseconds()
251
+ if self.verbose:
252
+ self.log(iso8601(milliseconds()), 'pong', message)
253
+ pass
254
+ elif message.type == WSMsgType.CLOSE:
255
+ if self.verbose:
256
+ self.log(iso8601(milliseconds()), 'close', self.closed(), message)
257
+ self.on_close(message.data)
258
+ elif message.type == WSMsgType.ERROR:
259
+ if self.verbose:
260
+ self.log(iso8601(milliseconds()), 'error', message)
261
+ error = NetworkError(str(message))
262
+ self.on_error(error)
200
263
 
201
- def closed(self):
202
- raise NotSupported('closed() not implemented')
264
+ def create_connection(self, session):
265
+ # autoping is responsible for automatically replying with pong
266
+ # to a ping incoming from a server, we have to disable autoping
267
+ # with aiohttp's websockets and respond with pong manually
268
+ # otherwise aiohttp's websockets client won't trigger WSMsgType.PONG
269
+ # call aenter here to simulate async with otherwise we get the error "await not called with future"
270
+ # if connecting to a non-existent endpoint
271
+ if (self.proxy):
272
+ return session.ws_connect(self.url, autoping=False, autoclose=False, headers=self.options.get('headers'), proxy=self.proxy, max_msg_size=10485760).__aenter__()
273
+ return session.ws_connect(self.url, autoping=False, autoclose=False, headers=self.options.get('headers'), max_msg_size=10485760).__aenter__()
203
274
 
204
275
  async def send(self, message):
205
- raise NotSupported('send() not implemented')
276
+ if self.verbose:
277
+ self.log(iso8601(milliseconds()), 'sending', message)
278
+ send_msg = None
279
+ if isinstance(message, str):
280
+ send_msg = message
281
+ else:
282
+ if orjson is None:
283
+ send_msg = json.dumps(message, separators=(',', ':'))
284
+ else:
285
+ send_msg = orjson.dumps(message).decode('utf-8')
286
+ return await self.connection.send_str(send_msg)
206
287
 
207
288
  async def close(self, code=1000):
208
- raise NotSupported('close() not implemented')
289
+ if self.verbose:
290
+ self.log(iso8601(milliseconds()), 'closing', code)
291
+ for future in self.futures.values():
292
+ future.cancel()
293
+ await self.aiohttp_close()
209
294
 
210
- def create_connection(self, session):
211
- raise NotSupported('create_connection() not implemented')
295
+ async def aiohttp_close(self):
296
+ if not self.closed():
297
+ await self.connection.close()
298
+ # these will end automatically once self.closed() = True
299
+ # so we don't need to cancel them
300
+ if self.ping_looper:
301
+ self.ping_looper.cancel()
212
302
 
213
- def log(self, *args):
214
- print(*args)
303
+ async def ping_loop(self):
304
+ if self.verbose:
305
+ self.log(iso8601(milliseconds()), 'ping loop')
306
+ while self.keepAlive and not self.closed():
307
+ now = milliseconds()
308
+ self.lastPong = now if self.lastPong is None else self.lastPong
309
+ if (self.lastPong + self.keepAlive * self.maxPingPongMisses) < now:
310
+ self.on_error(RequestTimeout('Connection to ' + self.url + ' timed out due to a ping-pong keepalive missing on time'))
311
+ # the following ping-clause is not necessary with aiohttp's built-in ws
312
+ # since it has a heartbeat option (see create_connection above)
313
+ # however some exchanges require a text-type ping message
314
+ # therefore we need this clause anyway
315
+ else:
316
+ if self.ping:
317
+ try:
318
+ await self.send(self.ping(self))
319
+ except Exception as e:
320
+ self.on_error(e)
321
+ else:
322
+ await self.connection.ping()
323
+ await sleep(self.keepAlive / 1000)
@@ -1,69 +1,42 @@
1
1
  import asyncio
2
- from ccxt import ExchangeClosedByUser
3
2
 
4
- class Future(asyncio.Future):
5
3
 
6
- is_race_future = False
4
+ class Future(asyncio.Future):
7
5
 
8
6
  def resolve(self, result=None):
9
7
  if not self.done():
10
- try:
11
- self.set_result(result)
12
- except BaseException as e:
13
- print("Error in Future.resolve")
14
- raise e
8
+ self.set_result(result)
15
9
 
16
10
  def reject(self, error=None):
17
11
  if not self.done():
18
- # If not an exception, wrap it in a generic Exception
19
- if not isinstance(error, BaseException):
20
- error = Exception(error)
21
- try:
22
- self.set_exception(error)
23
- except BaseException as e:
24
- print("Error in Future.reject")
25
- raise e
12
+ self.set_exception(error)
26
13
 
27
14
  @classmethod
28
15
  def race(cls, futures):
29
16
  future = Future()
30
- for f in futures:
31
- f.is_race_future = True
32
17
  coro = asyncio.wait(futures, return_when=asyncio.FIRST_COMPLETED)
33
18
  task = asyncio.create_task(coro)
34
19
 
35
20
  def callback(done):
36
- try:
37
- complete, pending = done.result()
38
- # check for exceptions
39
- for i, f in enumerate(complete):
40
- try:
41
- f.result()
42
- except ExchangeClosedByUser as e:
43
- if len(pending) == 0 and i == len(complete) - 1:
44
- future.reject(e)
45
- # wait for all the sub promises to be reject before rejecting future
46
- continue
47
- except asyncio.CancelledError as e:
48
- continue
49
- except Exception as e:
50
- future.reject(e)
51
- return
52
- # no exceptions return first result
53
- futures_list = list(complete)
54
-
55
- are_all_canceled = all([f.cancelled() for f in futures_list])
56
- if are_all_canceled:
57
- future.reject(ExchangeClosedByUser('Connection closed by the user'))
58
- return
59
-
60
- first = futures_list[0]
61
-
62
- first_result = first.result()
63
- future.resolve(first_result)
64
- except asyncio.CancelledError as e:
65
- future.reject(e)
66
- except Exception as e:
67
- future.reject(e)
21
+ complete, _ = done.result()
22
+ # check for exceptions
23
+ exceptions = []
24
+ cancelled = False
25
+ for f in complete:
26
+ if f.cancelled():
27
+ cancelled = True
28
+ else:
29
+ err = f.exception()
30
+ if err:
31
+ exceptions.append(err)
32
+ # if any exceptions return with first exception
33
+ if len(exceptions) > 0:
34
+ future.set_exception(exceptions[0])
35
+ # else return first result
36
+ elif cancelled:
37
+ future.cancel()
38
+ else:
39
+ first_result = list(complete)[0].result()
40
+ future.set_result(first_result)
68
41
  task.add_done_callback(callback)
69
42
  return future
@@ -3904,7 +3904,7 @@ class binance(Exchange, ImplicitAPI):
3904
3904
  #
3905
3905
  # {
3906
3906
  # "symbol": "BTCUSDT",
3907
- # "markPrice": "11793.63104562", # mark price
3907
+ # "markPrice": "11793.63104561", # mark price
3908
3908
  # "indexPrice": "11781.80495970", # index price
3909
3909
  # "estimatedSettlePrice": "11781.16138815", # Estimated Settle Price, only useful in the last hour before the settlement starts
3910
3910
  # "lastFundingRate": "0.00038246", # This is the lastest estimated funding rate
@@ -2160,6 +2160,7 @@ class bitmart(Exchange, ImplicitAPI):
2160
2160
  :param dict [params]: extra parameters specific to the exchange API endpoint
2161
2161
  :param int [params.until]: the latest time in ms to fetch trades for
2162
2162
  :param boolean [params.marginMode]: *spot* whether to fetch trades for margin orders or spot orders, defaults to spot orders(only isolated margin orders are supported)
2163
+ :param str [params.stpMode]: self-trade prevention only for spot, defaults to none, ['none', 'cancel_maker', 'cancel_taker', 'cancel_both']
2163
2164
  :returns Trade[]: a list of `trade structures <https://docs.ccxt.com/#/?id=trade-structure>`
2164
2165
  """
2165
2166
  await self.load_markets()
@@ -2264,6 +2265,7 @@ class bitmart(Exchange, ImplicitAPI):
2264
2265
  :param int [since]: the earliest time in ms to fetch trades for
2265
2266
  :param int [limit]: the maximum number of trades to retrieve
2266
2267
  :param dict [params]: extra parameters specific to the exchange API endpoint
2268
+ :param str [params.stpMode]: self-trade prevention only for spot, defaults to none, ['none', 'cancel_maker', 'cancel_taker', 'cancel_both']
2267
2269
  :returns dict[]: a list of `trade structures <https://docs.ccxt.com/#/?id=trade-structure>`
2268
2270
  """
2269
2271
  await self.load_markets()
@@ -2706,6 +2708,7 @@ class bitmart(Exchange, ImplicitAPI):
2706
2708
  :param str [params.stopLossPrice]: *swap only* the price to trigger a stop-loss order
2707
2709
  :param str [params.takeProfitPrice]: *swap only* the price to trigger a take-profit order
2708
2710
  :param int [params.plan_category]: *swap tp/sl only* 1: tp/sl, 2: position tp/sl, default is 1
2711
+ :param str [params.stpMode]: self-trade prevention only for spot, defaults to none, ['none', 'cancel_maker', 'cancel_taker', 'cancel_both']
2709
2712
  :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
2710
2713
  """
2711
2714
  await self.load_markets()
@@ -2768,6 +2771,7 @@ class bitmart(Exchange, ImplicitAPI):
2768
2771
 
2769
2772
  :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
2770
2773
  :param dict [params]: extra parameters specific to the exchange API endpoint
2774
+ :param str [params.stpMode]: self-trade prevention only for spot, defaults to none, ['none', 'cancel_maker', 'cancel_taker', 'cancel_both']
2771
2775
  :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
2772
2776
  """
2773
2777
  await self.load_markets()
@@ -3270,6 +3274,7 @@ class bitmart(Exchange, ImplicitAPI):
3270
3274
  :param str [params.orderType]: *swap only* 'limit', 'market', or 'trailing'
3271
3275
  :param boolean [params.trailing]: *swap only* set to True if you want to fetch trailing orders
3272
3276
  :param boolean [params.trigger]: *swap only* set to True if you want to fetch trigger orders
3277
+ :param str [params.stpMode]: self-trade prevention only for spot, defaults to none, ['none', 'cancel_maker', 'cancel_taker', 'cancel_both']
3273
3278
  :returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
3274
3279
  """
3275
3280
  await self.load_markets()
@@ -3383,6 +3388,7 @@ class bitmart(Exchange, ImplicitAPI):
3383
3388
  :param dict [params]: extra parameters specific to the exchange API endpoint
3384
3389
  :param int [params.until]: timestamp in ms of the latest entry
3385
3390
  :param str [params.marginMode]: *spot only* 'cross' or 'isolated', for margin trading
3391
+ :param str [params.stpMode]: self-trade prevention only for spot, defaults to none, ['none', 'cancel_maker', 'cancel_taker', 'cancel_both']
3386
3392
  :returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
3387
3393
  """
3388
3394
  await self.load_markets()
@@ -3441,6 +3447,7 @@ class bitmart(Exchange, ImplicitAPI):
3441
3447
  :param str [params.clientOrderId]: *spot* fetch the order by client order id instead of order id
3442
3448
  :param str [params.orderType]: *swap only* 'limit', 'market', 'liquidate', 'bankruptcy', 'adl' or 'trailing'
3443
3449
  :param boolean [params.trailing]: *swap only* set to True if you want to fetch a trailing order
3450
+ :param str [params.stpMode]: self-trade prevention only for spot, defaults to none, ['none', 'cancel_maker', 'cancel_taker', 'cancel_both']
3444
3451
  :returns dict: An `order structure <https://docs.ccxt.com/#/?id=order-structure>`
3445
3452
  """
3446
3453
  await self.load_markets()
@@ -101,6 +101,7 @@ class bitmex(Exchange, ImplicitAPI):
101
101
  'fetchTransactions': 'emulated',
102
102
  'fetchTransfer': False,
103
103
  'fetchTransfers': False,
104
+ 'index': True,
104
105
  'reduceMargin': None,
105
106
  'sandbox': True,
106
107
  'setLeverage': True,
@@ -427,8 +428,8 @@ class bitmex(Exchange, ImplicitAPI):
427
428
  # # "mediumPrecision": "8",
428
429
  # # "shorterPrecision": "4",
429
430
  # # "symbol": "₿",
430
- # # "weight": "1",
431
431
  # # "tickLog": "0",
432
+ # # "weight": "1",
432
433
  # "enabled": True,
433
434
  # "isMarginCurrency": True,
434
435
  # "minDepositAmount": "10000",
@@ -666,7 +666,7 @@ class bitvavo(Exchange, ImplicitAPI):
666
666
  },
667
667
  })
668
668
  # set currencies here to avoid calling publicGetAssets twice
669
- self.currencies = self.deep_extend(self.currencies, result)
669
+ self.currencies = self.map_to_safe_map(self.deep_extend(self.currencies, result))
670
670
  return result
671
671
 
672
672
  async def fetch_ticker(self, symbol: str, params={}) -> Ticker:
@@ -1207,6 +1207,8 @@ class bitvavo(Exchange, ImplicitAPI):
1207
1207
  operatorId, params = self.handle_option_and_params(params, 'createOrder', 'operatorId')
1208
1208
  if operatorId is not None:
1209
1209
  request['operatorId'] = self.parse_to_int(operatorId)
1210
+ else:
1211
+ raise ArgumentsRequired(self.id + ' createOrder() requires an operatorId in params or options, eg: exchange.options[\'operatorId\'] = 1234567890')
1210
1212
  return self.extend(request, params)
1211
1213
 
1212
1214
  async def create_order(self, symbol: Str, type: OrderType, side: OrderSide, amount: float, price: Num = None, params={}):
@@ -1304,6 +1306,8 @@ class bitvavo(Exchange, ImplicitAPI):
1304
1306
  operatorId, params = self.handle_option_and_params(params, 'editOrder', 'operatorId')
1305
1307
  if operatorId is not None:
1306
1308
  request['operatorId'] = self.parse_to_int(operatorId)
1309
+ else:
1310
+ raise ArgumentsRequired(self.id + ' editOrder() requires an operatorId in params or options, eg: exchange.options[\'operatorId\'] = 1234567890')
1307
1311
  request['market'] = market['id']
1308
1312
  return request
1309
1313
 
@@ -1342,6 +1346,8 @@ class bitvavo(Exchange, ImplicitAPI):
1342
1346
  operatorId, params = self.handle_option_and_params(params, 'cancelOrder', 'operatorId')
1343
1347
  if operatorId is not None:
1344
1348
  request['operatorId'] = self.parse_to_int(operatorId)
1349
+ else:
1350
+ raise ArgumentsRequired(self.id + ' cancelOrder() requires an operatorId in params or options, eg: exchange.options[\'operatorId\'] = 1234567890')
1345
1351
  return self.extend(request, params)
1346
1352
 
1347
1353
  async def cancel_order(self, id: str, symbol: Str = None, params={}):