tailwind #9

Manually merged
peperunas merged 157 commits from tailwind into master 2020-12-28 18:38:52 +00:00
3 changed files with 32 additions and 6 deletions
Showing only changes of commit 2a6dc24300 - Show all commits

View File

@ -58,7 +58,7 @@ class BfxBot:
await self.__status[Symbol.from_str(p.symbol)].add_position(p)
# updating orders
active_orders = await self.__bfx.get_active_orders(str(symbol))
active_orders = await self.__bfx.get_active_orders(symbol)
for o in active_orders:
self.__status[symbol].add_order(o)

View File

@ -1,11 +1,35 @@
from bfxapi.rest.bfx_rest import BfxRest
from retrying_async import retry
from bfxbot.currency import Symbol
class BfxWrapper(BfxRest):
def __init__(self, api_key: str, api_secret: str):
super().__init__(API_KEY=api_key, API_SECRET=api_secret)
@retry()
async def get_public_ticker(self, symbol):
if isinstance(symbol, Symbol):
symbol = str(symbol)
return await super().get_public_ticker(symbol)
@retry()
async def get_active_position(self):
return await super().get_active_position()
@retry()
async def get_active_orders(self, symbol):
if isinstance(symbol, Symbol):
symbol = str(symbol)
return await super().get_active_orders(symbol)
async def get_current_prices(self, symbol) -> (float, float, float):
if isinstance(symbol, Symbol):
symbol = str(symbol)
tickers = await self.get_public_ticker(symbol)
bid_price = tickers[0]

View File

@ -54,12 +54,12 @@ class TrailingStopStrategy(Strategy):
def __init__(self):
self.stop_percentage: float = None
def position_on_new_tick(self, position: Position, ss: SymbolStatus) -> (PositionState, List[Event]):
def position_on_new_tick(self, current_position: Position, ss: SymbolStatus) -> (PositionState, List[Event]):
events = []
pl_perc = net_pl_percentage(position.profit_loss_percentage, TAKER_FEE)
prev = ss.previous_pw(position.id)
event_metadata = EventMetadata(position_id=position.id)
pl_perc = net_pl_percentage(current_position.profit_loss_percentage, TAKER_FEE)
prev = ss.previous_pw(current_position.id)
event_metadata = EventMetadata(position_id=current_position.id)
if pl_perc > self.GOOD_PROFIT_PERC:
state = PositionState.PROFIT
@ -73,12 +73,14 @@ class TrailingStopStrategy(Strategy):
events.append(Event(EventKind.CLOSE_POSITION, ss.current_tick, event_metadata))
state = PositionState.CRITICAL
pw = PositionWrapper(position, state=state, net_profit_loss=position.profit_loss,
pw = PositionWrapper(current_position, state=state, net_profit_loss=current_position.profit_loss,
net_profit_loss_percentage=pl_perc)
if not prev or prev.state() == state:
return pw, events
print(f"{prev.state()} vs {state}")
if state == PositionState.PROFIT:
events.append(Event(EventKind.REACHED_GOOD_PROFIT, ss.current_tick, event_metadata))
elif state == PositionState.MINIMUM_PROFIT: