mirror of
https://github.com/aljazceru/bitfinex-api-py.git
synced 2025-12-19 06:44:22 +01:00
Move _Delay local class in global scope (bfxapi.websocket.client.bfx_websocket_client).
Apply pylint's linting rules to bfxapi/rest/__init__.py, bfxapi/rest/enums.py, bfxapi/rest/exceptions.py, bfxapi/rest/serializers.py and bfxapi/rest/types.py." Apply pylint's linting rules to bfxapi/rest/endpoints/__init__.py, bfxapi/rest/endpoints/bfx_rest_interface.py and bfxapi/rest/endpoints/rest_public_endpoints.py.
This commit is contained in:
@@ -29,6 +29,27 @@ def _require_websocket_authentication(function: F) -> F:
|
||||
|
||||
return cast(F, wrapper)
|
||||
|
||||
class _Delay:
|
||||
BACKOFF_MIN, BACKOFF_MAX = 1.92, 60.0
|
||||
|
||||
BACKOFF_INITIAL = 5.0
|
||||
|
||||
def __init__(self, backoff_factor):
|
||||
self.__backoff_factor = backoff_factor
|
||||
self.__backoff_delay = _Delay.BACKOFF_MIN
|
||||
self.__initial_delay = random.random() * _Delay.BACKOFF_INITIAL
|
||||
|
||||
def next(self):
|
||||
backoff_delay = self.peek()
|
||||
__backoff_delay = self.__backoff_delay * self.__backoff_factor
|
||||
self.__backoff_delay = min(__backoff_delay, _Delay.BACKOFF_MAX)
|
||||
|
||||
return backoff_delay
|
||||
|
||||
def peek(self):
|
||||
return (self.__backoff_delay == _Delay.BACKOFF_MIN) \
|
||||
and self.__initial_delay or self.__backoff_delay
|
||||
|
||||
class BfxWebsocketClient:
|
||||
VERSION = BfxWebsocketBucket.VERSION
|
||||
|
||||
@@ -135,27 +156,6 @@ class BfxWebsocketClient:
|
||||
if message[0] == 0 and message[1] != _HEARTBEAT:
|
||||
self.handler.handle(message[1], message[2])
|
||||
|
||||
class _Delay:
|
||||
BACKOFF_MIN, BACKOFF_MAX = 1.92, 60.0
|
||||
|
||||
BACKOFF_INITIAL = 5.0
|
||||
|
||||
def __init__(self, backoff_factor):
|
||||
self.__backoff_factor = backoff_factor
|
||||
self.__backoff_delay = _Delay.BACKOFF_MIN
|
||||
self.__initial_delay = random.random() * _Delay.BACKOFF_INITIAL
|
||||
|
||||
def next(self):
|
||||
backoff_delay = self.peek()
|
||||
__backoff_delay = self.__backoff_delay * self.__backoff_factor
|
||||
self.__backoff_delay = min(__backoff_delay, _Delay.BACKOFF_MAX)
|
||||
|
||||
return backoff_delay
|
||||
|
||||
def peek(self):
|
||||
return (self.__backoff_delay == _Delay.BACKOFF_MIN) \
|
||||
and self.__initial_delay or self.__backoff_delay
|
||||
|
||||
while True:
|
||||
if reconnection.status:
|
||||
await asyncio.sleep(delay.next())
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#pylint: disable=redefined-builtin,too-many-arguments
|
||||
#pylint: disable=redefined-builtin
|
||||
|
||||
from decimal import Decimal
|
||||
from datetime import datetime
|
||||
@@ -15,6 +15,7 @@ class BfxWebsocketInputs:
|
||||
type: OrderType,
|
||||
symbol: str,
|
||||
amount: Union[Decimal, float, str],
|
||||
*,
|
||||
price: Optional[Union[Decimal, float, str]] = None,
|
||||
lev: Optional[int] = None,
|
||||
price_trailing: Optional[Union[Decimal, float, str]] = None,
|
||||
@@ -35,6 +36,7 @@ class BfxWebsocketInputs:
|
||||
|
||||
async def update_order(self,
|
||||
id: int,
|
||||
*,
|
||||
amount: Optional[Union[Decimal, float, str]] = None,
|
||||
price: Optional[Union[Decimal, float, str]] = None,
|
||||
cid: Optional[int] = None,
|
||||
@@ -54,6 +56,7 @@ class BfxWebsocketInputs:
|
||||
})
|
||||
|
||||
async def cancel_order(self,
|
||||
*,
|
||||
id: Optional[int] = None,
|
||||
cid: Optional[int] = None,
|
||||
cid_date: Optional[str] = None):
|
||||
@@ -62,6 +65,7 @@ class BfxWebsocketInputs:
|
||||
})
|
||||
|
||||
async def cancel_order_multi(self,
|
||||
*,
|
||||
ids: Optional[List[int]] = None,
|
||||
cids: Optional[List[Tuple[int, str]]] = None,
|
||||
gids: Optional[List[int]] = None,
|
||||
@@ -71,12 +75,14 @@ class BfxWebsocketInputs:
|
||||
"all": int(all)
|
||||
})
|
||||
|
||||
#pylint: disable-next=too-many-arguments
|
||||
async def submit_funding_offer(self,
|
||||
type: FundingOfferType,
|
||||
symbol: str,
|
||||
amount: Union[Decimal, float, str],
|
||||
rate: Union[Decimal, float, str],
|
||||
period: int,
|
||||
*,
|
||||
flags: Optional[int] = 0):
|
||||
await self.__handle_websocket_input("fon", {
|
||||
"type": type, "symbol": symbol, "amount": amount,
|
||||
|
||||
@@ -3,11 +3,11 @@ from typing import *
|
||||
|
||||
from dataclasses import dataclass
|
||||
|
||||
from .. labeler import _Type
|
||||
|
||||
#pylint: disable-next=unused-import
|
||||
from .. notification import Notification
|
||||
|
||||
from .. labeler import _Type
|
||||
|
||||
from ..utils.json_encoder import JSON
|
||||
|
||||
#region Type hinting for Websocket Public Channels
|
||||
|
||||
Reference in New Issue
Block a user