Skip to content

Commit

Permalink
2.1.8
Browse files Browse the repository at this point in the history
  • Loading branch information
DogsTailFarmer committed Apr 8, 2024
1 parent 1025a1f commit a18aecf
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 19 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 2.1.8 2024-04-08
### Update
* `Bitfinex`: add logging for `cancel_order()` and `cancel_all_orders()` methods
* Add debug logging for `open_client_connection()` and `client.load()`

## 2.1.7 2024-03-29
### Fix
* `Bybit`: http error handling: handling events that are not explicitly described
Expand Down
2 changes: 1 addition & 1 deletion exchanges_wrapper/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
__contact__ = "https://github.com/DogsTailFarmer"
__email__ = "[email protected]"
__credits__ = ["https://github.com/DanyaSWorlD"]
__version__ = "2.1.7"
__version__ = "2.1.8"

from pathlib import Path
import shutil
Expand Down
29 changes: 16 additions & 13 deletions exchanges_wrapper/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
BBTPrivateEventsDataStream
from exchanges_wrapper.definitions import OrderType
from exchanges_wrapper.events import Events
import exchanges_wrapper.bitfinex_parser as bfx
import exchanges_wrapper.huobi_parser as hbp
import exchanges_wrapper.okx_parser as okx
import exchanges_wrapper.bybit_parser as bbt
import exchanges_wrapper.parsers.bitfinex_parser as bfx
import exchanges_wrapper.parsers.huobi_parser as hbp
import exchanges_wrapper.parsers.okx_parser as okx
import exchanges_wrapper.parsers.bybit_parser as bbt
from crypto_ws_api.ws_session import UserWSSession

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -117,6 +117,7 @@ async def fetch_object(self, key):
return res

async def load(self, symbol):
logger.info(f"Try load {self.exchange}:{symbol} info...")
infos = await self.fetch_exchange_info(symbol)
if not infos.get('serverTime'):
raise UserWarning("Can't get exchange info, check availability and operational status of the exchange")
Expand Down Expand Up @@ -144,6 +145,7 @@ async def load(self, symbol):
# load rate limits
self.rate_limits = infos["rateLimits"]
self.loaded = True
logger.info(f"Info for {self.exchange}:{symbol} loaded success")

async def close(self):
await self.session.close()
Expand Down Expand Up @@ -1177,18 +1179,19 @@ async def cancel_all_orders(self, trade_id, symbol, receive_window=None):
orders = await self.fetch_open_orders(trade_id, symbol, receive_window=receive_window, response_type=True)
orders_id = [order.get('orderId') for order in orders]
params = {'id': orders_id}
res = (
await self.user_wss_session.handle_request(trade_id, "oc_multi", _params=params)
or await self.http.send_api_call(
res = await self.user_wss_session.handle_request(trade_id, "oc_multi", _params=params)
if res is None or (res and isinstance(res, list) and res[6] == 'ERROR'):
logger.debug(f"cancel_all_orders.bitfinex {orders_id}: res1: {res}")
res = await self.http.send_api_call(
"v2/auth/w/order/cancel/multi",
method="POST",
signed=True,
**params,
)
)
if res and res[6] == 'SUCCESS':
return bfx.orders(res[4], response_type=True, cancelled=True)
logger.debug(f"bitfinex: cancel_all_orders.res: {res}")
**params
)
if res and isinstance(res, list) and res[6] == 'SUCCESS':
binance_res = bfx.orders(res[4], response_type=True, cancelled=True)
else:
logger.debug(f"bitfinex: cancel_all_orders.res: {res}")

elif self.exchange == 'huobi':
orders = await self.fetch_open_orders(trade_id, symbol, receive_window=receive_window, response_type=True)
Expand Down
2 changes: 2 additions & 0 deletions exchanges_wrapper/exch_srv.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,11 @@ async def open_client_connection(self, request: mr.OpenClientConnectionRequest)
logger.info(f"OpenClientConnection start trade: {request.account_name}:{request.trade_id}")
client_id = OpenClient.get_id(request.account_name)
if client_id:
logger.debug(f"OpenClientConnection: {request.account_name}:{request.trade_id}:{client_id}")
open_client = OpenClient.get_client(client_id)
open_client.client.http.rate_limit_reached = False
else:
logger.debug(f"OpenClientConnection: {request.account_name}:{request.trade_id}: set new client_id")
try:
open_client = OpenClient(request.account_name)
client_id = id(open_client)
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,12 @@ def on_trade_update(res: dict) -> dict:
last_executed_price = res.get("execPrice", res.get("avgPrice"))
last_quote_asset_transacted = res.get("execValue", cumulative_quote_asset)

status = 'NEW' if leaves_qty == order_quantity else 'PARTIALLY_FILLED' if leaves_qty > 0 else 'FILLED'
if leaves_qty == order_quantity:
status = 'NEW'
elif leaves_qty > 0:
status = 'PARTIALLY_FILLED'
else:
status = 'FILLED'

return {
"e": "executionReport",
Expand Down
File renamed without changes.
File renamed without changes.
8 changes: 4 additions & 4 deletions exchanges_wrapper/web_sockets.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
from urllib.parse import urlencode, urlparse
import websockets

import exchanges_wrapper.bitfinex_parser as bfx
import exchanges_wrapper.huobi_parser as hbp
import exchanges_wrapper.okx_parser as okx
import exchanges_wrapper.bybit_parser as bbt
import exchanges_wrapper.parsers.bitfinex_parser as bfx
import exchanges_wrapper.parsers.huobi_parser as hbp
import exchanges_wrapper.parsers.okx_parser as okx
import exchanges_wrapper.parsers.bybit_parser as bbt
from crypto_ws_api.ws_session import generate_signature
from exchanges_wrapper import LOG_PATH

Expand Down

0 comments on commit a18aecf

Please sign in to comment.