fixed currency creation on quote

This commit is contained in:
Giulio De Pasquale 2020-12-24 13:47:54 +00:00
parent 54878ef323
commit 296f0abd67

View File

@ -68,10 +68,14 @@ class BfxWrapper(BfxRest):
start_time = time - self.DEFAULT_TIME_DELTA start_time = time - self.DEFAULT_TIME_DELTA
end_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) if currency != str(quote):
currency_price = average(list(map(lambda x: x[3], trades))) 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) b = Balance(c, quote)
movements.add_balance(b) movements.add_balance(b)
@ -93,10 +97,15 @@ class BfxWrapper(BfxRest):
start_time = time - self.DEFAULT_TIME_DELTA start_time = time - self.DEFAULT_TIME_DELTA
end_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) b = Balance(c, quote)
bg.add_balance(b) bg.add_balance(b)
@ -183,7 +192,7 @@ class BfxWrapper(BfxRest):
return await self.post(api_path, return await self.post(api_path,
{'symbol': str(symbol), 'type': order_type.value, "dir": direction.value, "rate": rate}) {'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: if start > end:
raise ValueError raise ValueError
@ -196,6 +205,11 @@ class BfxWrapper(BfxRest):
movements_quote = movements_bg.quote_equivalent() movements_quote = movements_bg.quote_equivalent()
profit_loss = end_quote - (start_quote + movements_quote) 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 profit_loss_percentage = profit_loss / (start_quote + movements_quote) * 100
return profit_loss, profit_loss_percentage return profit_loss, profit_loss_percentage