exchanges-wrapper 2.1.6__tar.gz → 2.1.8__tar.gz

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 (20) hide show
  1. {exchanges_wrapper-2.1.6 → exchanges_wrapper-2.1.8}/PKG-INFO +2 -2
  2. {exchanges_wrapper-2.1.6 → exchanges_wrapper-2.1.8}/README.md +1 -1
  3. {exchanges_wrapper-2.1.6 → exchanges_wrapper-2.1.8}/exchanges_wrapper/__init__.py +1 -1
  4. {exchanges_wrapper-2.1.6 → exchanges_wrapper-2.1.8}/exchanges_wrapper/client.py +16 -13
  5. {exchanges_wrapper-2.1.6 → exchanges_wrapper-2.1.8}/exchanges_wrapper/exch_srv.py +2 -0
  6. {exchanges_wrapper-2.1.6 → exchanges_wrapper-2.1.8}/exchanges_wrapper/http_client.py +4 -2
  7. {exchanges_wrapper-2.1.6/exchanges_wrapper → exchanges_wrapper-2.1.8/exchanges_wrapper/parsers}/bybit_parser.py +6 -1
  8. {exchanges_wrapper-2.1.6 → exchanges_wrapper-2.1.8}/exchanges_wrapper/web_sockets.py +4 -4
  9. {exchanges_wrapper-2.1.6 → exchanges_wrapper-2.1.8}/LICENSE.md +0 -0
  10. {exchanges_wrapper-2.1.6 → exchanges_wrapper-2.1.8}/exchanges_wrapper/definitions.py +0 -0
  11. {exchanges_wrapper-2.1.6 → exchanges_wrapper-2.1.8}/exchanges_wrapper/errors.py +0 -0
  12. {exchanges_wrapper-2.1.6 → exchanges_wrapper-2.1.8}/exchanges_wrapper/events.py +0 -0
  13. {exchanges_wrapper-2.1.6 → exchanges_wrapper-2.1.8}/exchanges_wrapper/exch_srv_cfg.toml.template +0 -0
  14. {exchanges_wrapper-2.1.6 → exchanges_wrapper-2.1.8}/exchanges_wrapper/lib.py +0 -0
  15. {exchanges_wrapper-2.1.6 → exchanges_wrapper-2.1.8}/exchanges_wrapper/martin/__init__.py +0 -0
  16. {exchanges_wrapper-2.1.6/exchanges_wrapper → exchanges_wrapper-2.1.8/exchanges_wrapper/parsers}/bitfinex_parser.py +0 -0
  17. {exchanges_wrapper-2.1.6/exchanges_wrapper → exchanges_wrapper-2.1.8/exchanges_wrapper/parsers}/huobi_parser.py +0 -0
  18. {exchanges_wrapper-2.1.6/exchanges_wrapper → exchanges_wrapper-2.1.8/exchanges_wrapper/parsers}/okx_parser.py +0 -0
  19. {exchanges_wrapper-2.1.6 → exchanges_wrapper-2.1.8}/exchanges_wrapper/proto/martin.proto +0 -0
  20. {exchanges_wrapper-2.1.6 → exchanges_wrapper-2.1.8}/pyproject.toml +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: exchanges-wrapper
3
- Version: 2.1.6
3
+ Version: 2.1.8
4
4
  Summary: REST API and WebSocket asyncio wrapper with grpc powered multiplexer server
5
5
  Author-email: Thomas Marchand <thomas.marchand@tuta.io>, Jerry Fedorenko <jerry.fedorenko@yahoo.com>
6
6
  Requires-Python: >=3.9
@@ -142,7 +142,7 @@ docker run -itP \
142
142
 
143
143
  ### Documentations
144
144
  * Served methods and examples of their use are described at ```example/exch_client.py```
145
- * For [Protocol Buffers](https://developers.google.com/protocol-buffers/docs/overview) serializing structured data see ```proto/exchanges_wrapper/api.proto```
145
+ * For [Protocol Buffers](https://developers.google.com/protocol-buffers/docs/overview) serializing structured data see ```exchanges_wrapper/proto/martin.proto```
146
146
 
147
147
  ## Donate
148
148
  *USDT* (TRC20) TN8F3Dz8BU8VwECRh3LTKi7FrsU8eWfsZz
@@ -116,7 +116,7 @@ docker run -itP \
116
116
 
117
117
  ### Documentations
118
118
  * Served methods and examples of their use are described at ```example/exch_client.py```
119
- * For [Protocol Buffers](https://developers.google.com/protocol-buffers/docs/overview) serializing structured data see ```proto/exchanges_wrapper/api.proto```
119
+ * For [Protocol Buffers](https://developers.google.com/protocol-buffers/docs/overview) serializing structured data see ```exchanges_wrapper/proto/martin.proto```
120
120
 
121
121
  ## Donate
122
122
  *USDT* (TRC20) TN8F3Dz8BU8VwECRh3LTKi7FrsU8eWfsZz
@@ -12,7 +12,7 @@ __maintainer__ = "Jerry Fedorenko"
12
12
  __contact__ = "https://github.com/DogsTailFarmer"
13
13
  __email__ = "jerry.fedorenko@yahoo.com"
14
14
  __credits__ = ["https://github.com/DanyaSWorlD"]
15
- __version__ = "2.1.6"
15
+ __version__ = "2.1.8"
16
16
 
17
17
  from pathlib import Path
18
18
  import shutil
@@ -22,10 +22,10 @@ from exchanges_wrapper.web_sockets import UserEventsDataStream, \
22
22
  BBTPrivateEventsDataStream
23
23
  from exchanges_wrapper.definitions import OrderType
24
24
  from exchanges_wrapper.events import Events
25
- import exchanges_wrapper.bitfinex_parser as bfx
26
- import exchanges_wrapper.huobi_parser as hbp
27
- import exchanges_wrapper.okx_parser as okx
28
- import exchanges_wrapper.bybit_parser as bbt
25
+ import exchanges_wrapper.parsers.bitfinex_parser as bfx
26
+ import exchanges_wrapper.parsers.huobi_parser as hbp
27
+ import exchanges_wrapper.parsers.okx_parser as okx
28
+ import exchanges_wrapper.parsers.bybit_parser as bbt
29
29
  from crypto_ws_api.ws_session import UserWSSession
30
30
 
31
31
  logger = logging.getLogger(__name__)
@@ -117,6 +117,7 @@ class Client:
117
117
  return res
118
118
 
119
119
  async def load(self, symbol):
120
+ logger.info(f"Try load {self.exchange}:{symbol} info...")
120
121
  infos = await self.fetch_exchange_info(symbol)
121
122
  if not infos.get('serverTime'):
122
123
  raise UserWarning("Can't get exchange info, check availability and operational status of the exchange")
@@ -144,6 +145,7 @@ class Client:
144
145
  # load rate limits
145
146
  self.rate_limits = infos["rateLimits"]
146
147
  self.loaded = True
148
+ logger.info(f"Info for {self.exchange}:{symbol} loaded success")
147
149
 
148
150
  async def close(self):
149
151
  await self.session.close()
@@ -1177,18 +1179,19 @@ class Client:
1177
1179
  orders = await self.fetch_open_orders(trade_id, symbol, receive_window=receive_window, response_type=True)
1178
1180
  orders_id = [order.get('orderId') for order in orders]
1179
1181
  params = {'id': orders_id}
1180
- res = (
1181
- await self.user_wss_session.handle_request(trade_id, "oc_multi", _params=params)
1182
- or await self.http.send_api_call(
1182
+ res = await self.user_wss_session.handle_request(trade_id, "oc_multi", _params=params)
1183
+ if res is None or (res and isinstance(res, list) and res[6] == 'ERROR'):
1184
+ logger.debug(f"cancel_all_orders.bitfinex {orders_id}: res1: {res}")
1185
+ res = await self.http.send_api_call(
1183
1186
  "v2/auth/w/order/cancel/multi",
1184
1187
  method="POST",
1185
1188
  signed=True,
1186
- **params,
1187
- )
1188
- )
1189
- if res and res[6] == 'SUCCESS':
1190
- return bfx.orders(res[4], response_type=True, cancelled=True)
1191
- logger.debug(f"bitfinex: cancel_all_orders.res: {res}")
1189
+ **params
1190
+ )
1191
+ if res and isinstance(res, list) and res[6] == 'SUCCESS':
1192
+ binance_res = bfx.orders(res[4], response_type=True, cancelled=True)
1193
+ else:
1194
+ logger.debug(f"bitfinex: cancel_all_orders.res: {res}")
1192
1195
 
1193
1196
  elif self.exchange == 'huobi':
1194
1197
  orders = await self.fetch_open_orders(trade_id, symbol, receive_window=receive_window, response_type=True)
@@ -160,9 +160,11 @@ class Martin(mr.MartinBase):
160
160
  logger.info(f"OpenClientConnection start trade: {request.account_name}:{request.trade_id}")
161
161
  client_id = OpenClient.get_id(request.account_name)
162
162
  if client_id:
163
+ logger.debug(f"OpenClientConnection: {request.account_name}:{request.trade_id}:{client_id}")
163
164
  open_client = OpenClient.get_client(client_id)
164
165
  open_client.client.http.rate_limit_reached = False
165
166
  else:
167
+ logger.debug(f"OpenClientConnection: {request.account_name}:{request.trade_id}: set new client_id")
166
168
  try:
167
169
  open_client = OpenClient(request.account_name)
168
170
  client_id = id(open_client)
@@ -84,12 +84,14 @@ class HttpClient:
84
84
  return payload.get('result'), payload.get('time')
85
85
  elif payload.get('retCode') == 10002:
86
86
  raise ExchangeError(ERR_TIMESTAMP_OUTSIDE_RECV_WINDOW)
87
+ else:
88
+ raise ExchangeError(f"API request failed: {response.status}:{response.reason}:{payload}")
87
89
  elif self.exchange == 'huobi' and payload and (payload.get('status') == 'ok' or payload.get('ok')):
88
90
  return payload.get('data', payload.get('tick'))
89
91
  elif self.exchange == 'okx' and payload and payload.get('code') == '0':
90
92
  return payload.get('data', [])
91
- elif (self.exchange not in ('binance', 'bitfinex') or
92
- (self.exchange == 'binance' and payload and "code" in payload)):
93
+ elif self.exchange not in ('binance', 'bitfinex') \
94
+ or (self.exchange == 'binance' and payload and "code" in payload):
93
95
  raise ExchangeError(f"API request failed: {response.status}:{response.reason}:{payload}")
94
96
  else:
95
97
  return payload
@@ -374,7 +374,12 @@ def on_trade_update(res: dict) -> dict:
374
374
  last_executed_price = res.get("execPrice", res.get("avgPrice"))
375
375
  last_quote_asset_transacted = res.get("execValue", cumulative_quote_asset)
376
376
 
377
- status = 'NEW' if leaves_qty == order_quantity else 'PARTIALLY_FILLED' if leaves_qty > 0 else 'FILLED'
377
+ if leaves_qty == order_quantity:
378
+ status = 'NEW'
379
+ elif leaves_qty > 0:
380
+ status = 'PARTIALLY_FILLED'
381
+ else:
382
+ status = 'FILLED'
378
383
 
379
384
  return {
380
385
  "e": "executionReport",
@@ -10,10 +10,10 @@ from datetime import datetime, timezone
10
10
  from urllib.parse import urlencode, urlparse
11
11
  import websockets
12
12
 
13
- import exchanges_wrapper.bitfinex_parser as bfx
14
- import exchanges_wrapper.huobi_parser as hbp
15
- import exchanges_wrapper.okx_parser as okx
16
- import exchanges_wrapper.bybit_parser as bbt
13
+ import exchanges_wrapper.parsers.bitfinex_parser as bfx
14
+ import exchanges_wrapper.parsers.huobi_parser as hbp
15
+ import exchanges_wrapper.parsers.okx_parser as okx
16
+ import exchanges_wrapper.parsers.bybit_parser as bbt
17
17
  from crypto_ws_api.ws_session import generate_signature
18
18
  from exchanges_wrapper import LOG_PATH
19
19