Skip to content

Commit

Permalink
Merge pull request edeng23#27 from CryptoIsGarbage/merge-upstream
Browse files Browse the repository at this point in the history
Merge upstream
  • Loading branch information
Knifa committed Jun 8, 2021
2 parents 8c3ed27 + b594987 commit 71da3b0
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 36 deletions.
1 change: 0 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,5 @@ repos:
- schedule==1.1.0
- sqlalchemy==1.3.23
- sqlitedict==1.7.0
- twisted==21.2.0
- unicorn-binance-websocket-api==1.30.0
- unicorn-fy==0.11.0
2 changes: 1 addition & 1 deletion binance_trade_bot/auto_trader.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def transaction_through_bridge(self, pair: Pair):
# maybe we have a lot of usdt already?
bridgeBalance = self.manager.get_currency_balance(self.config.BRIDGE.symbol)
self.logger.debug(f"bridge {self.config.BRIDGE} balance {bridgeBalance}")
if bridgeBalance < 50:
if bridgeBalance < 10:
return None
self.logger.info(f"Looks like there is bridge currency, will continue with buy")

Expand Down
32 changes: 1 addition & 31 deletions binance_trade_bot/binance_api_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ def get_fee(self, origin_coin: Coin, target_coin: Coin, selling: bool):
base_fee = 0.001
else:
base_fee = fees[origin_coin + target_coin]

if not self.get_using_bnb_for_fees():
return base_fee

Expand Down Expand Up @@ -153,51 +154,21 @@ def get_alt_tick(self, origin_symbol: str, target_symbol: str):
def get_min_notional(self, origin_symbol: str, target_symbol: str):
return float(self.get_symbol_filter(origin_symbol, target_symbol, "MIN_NOTIONAL")["minNotional"])

def convert_legacy_order(self, legacyOrder):
self.logger.debug(f"Converting legacy order {legacyOrder}")
event = dict()
event["symbol"] = legacyOrder["symbol"]
event["side"] = legacyOrder["side"]
event["order_type"] = legacyOrder["type"]
event["order_id"] = legacyOrder["orderId"]
event["cumulative_quote_asset_transacted_quantity"] = legacyOrder["cummulativeQuoteQty"]
event["current_order_status"] = legacyOrder["status"]
event["order_price"] = legacyOrder["price"]
event["transaction_time"] = legacyOrder["time"]

return BinanceOrder(event)

def _wait_for_order(
self, order_id, origin_symbol: str, target_symbol: str
) -> Optional[BinanceOrder]: # pylint: disable=unsubscriptable-object
pollCounter = 0
while True:
order_status: BinanceOrder = self.cache.orders.get(order_id, None)
if order_status is not None:
break
self.logger.debug(f"Waiting for order {order_id} to be created")
pollCounter += 1
if pollCounter % 10 == 0:
self.logger.debug(f"Performing manual poll for {order_id} creation in case websockets broke")
try:
order_status = self.convert_legacy_order(self.binance_client.get_order(symbol=origin_symbol + target_symbol, orderId=order_id))
break
except BinanceAPIException as e:
self.logger.debug(f"Order exception: {e}")
except Exception as e: # pylint: disable=broad-except
self.logger.info(f"Unexpected order creation error: {e}")
time.sleep(1)

self.logger.debug(f"Order created: {order_status}")
pollCounter = 0

while order_status.status != "FILLED":
try:
order_status = self.cache.orders.get(order_id, order_status)
pollCounter += 1
if pollCounter % 60 == 0:
self.logger.debug(f"Performing manual poll for {order_id} status in case websockets broke")
order_status = self.convert_legacy_order(self.binance_client.get_order(symbol=origin_symbol + target_symbol, orderId=order_id))

self.logger.debug(f"Waiting for order {order_id} to be filled")

Expand Down Expand Up @@ -385,7 +356,6 @@ def _sell_alt(self, origin_coin: Coin, target_coin: Coin):
new_balance = self.get_currency_balance(origin_symbol, True)

new_target_balance = self.get_currency_balance(target_symbol)

self.logger.info(f"Sold {origin_symbol} for {new_target_balance} {target_symbol}")

trade_log.set_complete(order.cumulative_quote_qty)
Expand Down
4 changes: 3 additions & 1 deletion binance_trade_bot/binance_stream_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,9 @@ def _process_stream_data(self, stream_data):
elif event_type == "balanceUpdate": # !userData
self.logger.debug(f"Balance update: {stream_data}")
with self.cache.open_balances() as balances:
del balances[stream_data["asset"]]
asset = stream_data["asset"]
if asset in balances:
del balances[stream_data["asset"]]
elif event_type in ("outboundAccountPosition", "outboundAccountInfo"): # !userData
self.logger.debug(f"{event_type}: {stream_data}")
with self.cache.open_balances() as balances:
Expand Down
3 changes: 3 additions & 0 deletions binance_trade_bot/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ def _get_progress_table(db: Database) -> str:
for t in progress
]

if len(rows) == 0:
return "No trades."

header = " | ".join(
[
f"{'Coin':<6}",
Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ flask-cors==3.0.10
flask-socketio==5.0.1
Flask==1.1.2
gunicorn==20.1.0
psycopg2-binary==2.8.6 # PostgreSQL support
python-binance==0.7.11
python-socketio[client]==5.2.1
schedule==1.1.0
sqlalchemy==1.4.15
sqlitedict==1.7.0
twisted==21.2.0
unicorn-binance-websocket-api==1.30.0
unicorn-fy==0.11.0

psycopg2-binary==2.8.6 # PostgreSQL support

0 comments on commit 71da3b0

Please sign in to comment.