added ledger and API for profit/loss retrieval
This commit is contained in:
parent
f9e3ad500c
commit
54878ef323
@ -1,4 +1,5 @@
|
||||
import asyncio
|
||||
import time
|
||||
from typing import Dict, List, Optional, Tuple
|
||||
|
||||
from bfxapi import Order
|
||||
@ -23,6 +24,8 @@ class BfxBot:
|
||||
self.__ticker: Ticker = Ticker(tick_duration)
|
||||
self.__status: Dict[TradingPair, SymbolStatus] = {}
|
||||
self.__quote: Symbol = quote
|
||||
self.__account_info = None
|
||||
self.__ledger = None
|
||||
|
||||
if isinstance(symbols, TradingPair):
|
||||
symbols = [symbols]
|
||||
@ -112,6 +115,9 @@ class BfxBot:
|
||||
async def get_balances(self):
|
||||
return await self.__bfx.get_current_balances(self.__quote)
|
||||
|
||||
async def get_profit_loss(self, start: int, end: int):
|
||||
return await self.__bfx.profit_loss(start, end, self.__ledger, self.__quote)
|
||||
|
||||
def set_strategy(self, symbol, strategy: Strategy):
|
||||
if symbol in self.__status:
|
||||
self.__status[symbol].strategy = strategy
|
||||
@ -119,6 +125,9 @@ class BfxBot:
|
||||
self.__status[symbol] = SymbolStatus(symbol, strategy)
|
||||
|
||||
async def start(self):
|
||||
self.__account_info = self.__bfx.get_account_information()
|
||||
self.__ledger = await self.__bfx.ledger_history(0, time.time() * 1000)
|
||||
|
||||
await self.__update_status__()
|
||||
|
||||
def symbol_event_handler(self, symbol) -> Optional[EventHandler]:
|
||||
@ -137,3 +146,6 @@ class BfxBot:
|
||||
await asyncio.sleep(self.__ticker.seconds)
|
||||
self.__ticker.inc()
|
||||
await self.__update_status__()
|
||||
|
||||
async def __update_ledger(self):
|
||||
self.__ledger = await self.__bfx.ledger_history(0, time.time() * 1000)
|
||||
|
Loading…
Reference in New Issue
Block a user