diff --git a/bfxbot/bfxwrapper.py b/bfxbot/bfxwrapper.py index 32a23ee..640d432 100644 --- a/bfxbot/bfxwrapper.py +++ b/bfxbot/bfxwrapper.py @@ -68,10 +68,14 @@ class BfxWrapper(BfxRest): start_time = time - self.DEFAULT_TIME_DELTA end_time = time + self.DEFAULT_TIME_DELTA - trades = await self.get_public_trades(symbol=trading_pair, start=start_time, end=end_time) - currency_price = average(list(map(lambda x: x[3], trades))) + if currency != str(quote): + trades = await self.get_public_trades(symbol=trading_pair, start=start_time, end=end_time) + currency_price = average(list(map(lambda x: x[3], trades))) + + c = Currency(currency, amount, currency_price) + else: + c = Currency(currency, amount) - c = Currency(currency, amount, currency_price) b = Balance(c, quote) movements.add_balance(b) @@ -93,10 +97,15 @@ class BfxWrapper(BfxRest): start_time = time - self.DEFAULT_TIME_DELTA end_time = time + self.DEFAULT_TIME_DELTA - trades = await self.get_public_trades(symbol=trading_pair, start=start_time, end=end_time) - currency_price = average(list(map(lambda x: x[3], trades))) - c = Currency(currency, amount, currency_price) + if currency != str(quote): + trades = await self.get_public_trades(symbol=trading_pair, start=start_time, end=end_time) + currency_price = average(list(map(lambda x: x[3], trades))) + + c = Currency(currency, amount, currency_price) + else: + c = Currency(currency, amount) + b = Balance(c, quote) bg.add_balance(b) @@ -183,7 +192,7 @@ class BfxWrapper(BfxRest): return await self.post(api_path, {'symbol': str(symbol), 'type': order_type.value, "dir": direction.value, "rate": rate}) - async def profit_loss(self, start: int, end: int, ledger, quote: Currency): + async def profit_loss(self, start: int, end: int, ledger, quote: Symbol): if start > end: raise ValueError @@ -196,6 +205,11 @@ class BfxWrapper(BfxRest): movements_quote = movements_bg.quote_equivalent() profit_loss = end_quote - (start_quote + movements_quote) + + # print(f"Start: {start}, End: {end}") + # print(f"{start_bg} {end_bg} {movements_bg}") + profit_loss_percentage = profit_loss / (start_quote + movements_quote) * 100 + return profit_loss, profit_loss_percentage