Skip to content

Commit

Permalink
Revert "Fix: Changing property name (StopIteration error)"
Browse files Browse the repository at this point in the history
This reverts commit bbabb31.
  • Loading branch information
edeng23 committed May 5, 2023
1 parent bbabb31 commit 29ce7a1
Show file tree
Hide file tree
Showing 4 changed files with 233 additions and 415 deletions.
5 changes: 0 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,3 @@ venv/
crypto_trading.db
apprise.yml
.DS_Store
Scripts/
Lib/
Procfile
pyvenv.cfg
include/
48 changes: 14 additions & 34 deletions binance_trade_bot/backtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,11 @@ 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}: {self.datetime} - {end_date}"
)
self.logger.info(f"Fetching prices for {ticker_symbol} between {self.datetime} and {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 @@ -79,25 +75,18 @@ 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: "
f"{self.balances[origin_symbol]} - bridge: "
f"Bought {origin_symbol}, balance now: {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 @@ -108,17 +97,14 @@ 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
)
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[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: "
f"{self.balances[origin_symbol]} - bridge: "
f"Sold {origin_symbol}, balance now: {self.balances[origin_symbol]} - bridge: "
f"{self.balances[target_symbol]}"
)
return {"price": from_coin_price}
Expand Down Expand Up @@ -146,13 +132,7 @@ 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 29ce7a1

Please sign in to comment.