Skip to content

Commit

Permalink
Fix: Changing property name (StopIteration error)
Browse files Browse the repository at this point in the history
  • Loading branch information
shohart authored and edeng23 committed Apr 23, 2023
1 parent 64451a3 commit bbabb31
Show file tree
Hide file tree
Showing 4 changed files with 415 additions and 233 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,8 @@ venv/
crypto_trading.db
apprise.yml
.DS_Store
Scripts/
Lib/
Procfile
pyvenv.cfg
include/
48 changes: 34 additions & 14 deletions binance_trade_bot/backtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,15 @@ def get_ticker_price(self, ticker_symbol: str):
if end_date > datetime.now():
end_date = datetime.now()
end_date = end_date.strftime("%d %b %Y %H:%M:%S")
self.logger.info(f"Fetching prices for {ticker_symbol} between {self.datetime} and {end_date}")
self.logger.info(
f"Fetching prices for {ticker_symbol}: {self.datetime} - {end_date}"
)
for result in self.binance_client.get_historical_klines(
ticker_symbol, "1m", target_date, end_date, limit=1000
):
date = datetime.utcfromtimestamp(result[0] / 1000).strftime("%d %b %Y %H:%M:%S")
date = datetime.utcfromtimestamp(result[0] / 1000).strftime(
"%d %b %Y %H:%M:%S"
)
price = float(result[1])
cache[f"{ticker_symbol} - {date}"] = price
cache.commit()
Expand All @@ -75,18 +79,25 @@ def buy_alt(self, origin_coin: Coin, target_coin: Coin):
target_balance = self.get_currency_balance(target_symbol)
from_coin_price = self.get_ticker_price(origin_symbol + target_symbol)

order_quantity = self._buy_quantity(origin_symbol, target_symbol, target_balance, from_coin_price)
order_quantity = self._buy_quantity(
origin_symbol, target_symbol, target_balance, from_coin_price
)
target_quantity = order_quantity * from_coin_price
self.balances[target_symbol] -= target_quantity
self.balances[origin_symbol] = self.balances.get(origin_symbol, 0) + order_quantity * (
1 - self.get_fee(origin_coin, target_coin, False)
)
self.balances[origin_symbol] = self.balances.get(
origin_symbol, 0
) + order_quantity * (1 - self.get_fee(origin_coin, target_coin, False))
self.logger.info(
f"Bought {origin_symbol}, balance now: {self.balances[origin_symbol]} - bridge: "
f"Bought {origin_symbol}, balance now: "
f"{self.balances[origin_symbol]} - bridge: "
f"{self.balances[target_symbol]}"
)

event = defaultdict(lambda: None, order_price=from_coin_price, cumulative_quote_asset_transacted_quantity=0)
event = defaultdict(
lambda: None,
order_price=from_coin_price,
cumulative_quote_asset_transacted_quantity=0,
)

return BinanceOrder(event)

Expand All @@ -97,14 +108,17 @@ def sell_alt(self, origin_coin: Coin, target_coin: Coin):
origin_balance = self.get_currency_balance(origin_symbol)
from_coin_price = self.get_ticker_price(origin_symbol + target_symbol)

order_quantity = self._sell_quantity(origin_symbol, target_symbol, origin_balance)
target_quantity = order_quantity * from_coin_price
self.balances[target_symbol] = self.balances.get(target_symbol, 0) + target_quantity * (
1 - self.get_fee(origin_coin, target_coin, True)
order_quantity = self._sell_quantity(
origin_symbol, target_symbol, origin_balance
)
target_quantity = order_quantity * from_coin_price
self.balances[target_symbol] = self.balances.get(
target_symbol, 0
) + target_quantity * (1 - self.get_fee(origin_coin, target_coin, True))
self.balances[origin_symbol] -= order_quantity
self.logger.info(
f"Sold {origin_symbol}, balance now: {self.balances[origin_symbol]} - bridge: "
f"Sold {origin_symbol}, balance now: "
f"{self.balances[origin_symbol]} - bridge: "
f"{self.balances[target_symbol]}"
)
return {"price": from_coin_price}
Expand Down Expand Up @@ -132,7 +146,13 @@ class MockDatabase(Database):
def __init__(self, logger: Logger, config: Config):
super().__init__(logger, config, "sqlite:///")

def log_scout(self, pair: Pair, target_ratio: float, current_coin_price: float, other_coin_price: float):
def log_scout(
self,
pair: Pair,
target_ratio: float,
current_coin_price: float,
other_coin_price: float,
):
pass


Expand Down
Loading

0 comments on commit bbabb31

Please sign in to comment.