From 00a100f6187c569d698a60a6e3de09ef71c9e3d3 Mon Sep 17 00:00:00 2001 From: Giulio De Pasquale Date: Mon, 21 Dec 2020 12:00:33 +0000 Subject: [PATCH] added method to calculate maximum order amount --- bfxbot/bfxwrapper.py | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/bfxbot/bfxwrapper.py b/bfxbot/bfxwrapper.py index 1f1d373..73ed159 100644 --- a/bfxbot/bfxwrapper.py +++ b/bfxbot/bfxwrapper.py @@ -1,13 +1,29 @@ +from enum import Enum + from bfxapi.rest.bfx_rest import BfxRest from retrying_async import retry from bfxbot.currency import Symbol +class Direction(Enum): + UP = 1, + DOWN = -1 + + +class OrderType(Enum): + EXCHANGE = "EXCHANGE", + MARGIN = "MARGIN" + + class BfxWrapper(BfxRest): def __init__(self, api_key: str, api_secret: str): super().__init__(API_KEY=api_key, API_SECRET=api_secret) + ####################################### + # OVERRIDDEN METHODS TO IMPLEMENT RETRY + ####################################### + @retry() async def get_public_ticker(self, symbol): if isinstance(symbol, Symbol): @@ -33,6 +49,14 @@ class BfxWrapper(BfxRest): return await super().get_trades(symbol, start, end) + @retry() + async def post(self, api_path: str, data: dict): + return await super.post(api_path, data) + + ################################ + # NEW METHODS + ################################ + async def get_current_prices(self, symbol) -> (float, float, float): if isinstance(symbol, Symbol): symbol = str(symbol) @@ -59,7 +83,10 @@ class BfxWrapper(BfxRest): return balance - async def get_balance_delta(self, symbol: Symbol, start: float, end: float): - trades = await self.get_trades(symbol, start, end) + async def maximum_order_amount(self, symbol: Symbol, direction: Direction, + order_type: OrderType = OrderType.EXCHANGE, + rate: int = 1): + api_path = "auth/calc/order/avail" - return sum([t.amount for t in trades]) + return await self.post(api_path, + {'symbol': str(symbol), 'type': order_type.value, "dir": direction.value, "rate": rate})