mirror of
https://github.com/aljazceru/bitfinex-api-py.git
synced 2025-12-18 22:34:21 +01:00
Fix and rewrite module bfx_websocket_inputs in bfxapi.websocket._client.
This commit is contained in:
@@ -1,52 +1,54 @@
|
||||
from typing import TYPE_CHECKING, Callable, Awaitable, \
|
||||
Tuple, List, Dict, Union, Optional, Any
|
||||
from typing import \
|
||||
Callable, Awaitable, Tuple, \
|
||||
List, Union, Optional, \
|
||||
Any
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from bfxapi.enums import \
|
||||
OrderType, FundingOfferType
|
||||
from decimal import Decimal
|
||||
|
||||
from decimal import Decimal
|
||||
from bfxapi.enums import \
|
||||
OrderType, \
|
||||
FundingOfferType
|
||||
|
||||
_Handler = Callable[[str, Any], Awaitable[None]]
|
||||
|
||||
class BfxWebSocketInputs:
|
||||
def __init__(self, handle_websocket_input: Callable[[str, Any], Awaitable[None]]) -> None:
|
||||
def __init__(self, handle_websocket_input: _Handler) -> None:
|
||||
self.__handle_websocket_input = handle_websocket_input
|
||||
|
||||
async def submit_order(self,
|
||||
type: "OrderType",
|
||||
type: OrderType,
|
||||
symbol: str,
|
||||
amount: Union["Decimal", float, str],
|
||||
amount: Union[str, float, Decimal],
|
||||
price: Union[str, float, Decimal],
|
||||
*,
|
||||
price: Optional[Union["Decimal", float, str]] = None,
|
||||
lev: Optional[int] = None,
|
||||
price_trailing: Optional[Union["Decimal", float, str]] = None,
|
||||
price_aux_limit: Optional[Union["Decimal", float, str]] = None,
|
||||
price_oco_stop: Optional[Union["Decimal", float, str]] = None,
|
||||
price_trailing: Optional[Union[str, float, Decimal]] = None,
|
||||
price_aux_limit: Optional[Union[str, float, Decimal]] = None,
|
||||
price_oco_stop: Optional[Union[str, float, Decimal]] = None,
|
||||
gid: Optional[int] = None,
|
||||
cid: Optional[int] = None,
|
||||
flags: Optional[int] = 0,
|
||||
tif: Optional[str] = None,
|
||||
meta: Optional[Dict[str, Any]] = None) -> None:
|
||||
flags: Optional[int] = None,
|
||||
tif: Optional[str] = None) -> None:
|
||||
await self.__handle_websocket_input("on", {
|
||||
"type": type, "symbol": symbol, "amount": amount,
|
||||
"price": price, "lev": lev, "price_trailing": price_trailing,
|
||||
"price_aux_limit": price_aux_limit, "price_oco_stop": price_oco_stop, "gid": gid,
|
||||
"cid": cid, "flags": flags, "tif": tif,
|
||||
"meta": meta
|
||||
})
|
||||
|
||||
async def update_order(self,
|
||||
id: int,
|
||||
*,
|
||||
amount: Optional[Union["Decimal", float, str]] = None,
|
||||
price: Optional[Union["Decimal", float, str]] = None,
|
||||
amount: Optional[Union[str, float, Decimal]] = None,
|
||||
price: Optional[Union[str, float, Decimal]] = None,
|
||||
cid: Optional[int] = None,
|
||||
cid_date: Optional[str] = None,
|
||||
gid: Optional[int] = None,
|
||||
flags: Optional[int] = 0,
|
||||
flags: Optional[int] = None,
|
||||
lev: Optional[int] = None,
|
||||
delta: Optional[Union["Decimal", float, str]] = None,
|
||||
price_aux_limit: Optional[Union["Decimal", float, str]] = None,
|
||||
price_trailing: Optional[Union["Decimal", float, str]] = None,
|
||||
delta: Optional[Union[str, float, Decimal]] = None,
|
||||
price_aux_limit: Optional[Union[str, float, Decimal]] = None,
|
||||
price_trailing: Optional[Union[str, float, Decimal]] = None,
|
||||
tif: Optional[str] = None) -> None:
|
||||
await self.__handle_websocket_input("ou", {
|
||||
"id": id, "amount": amount, "price": price,
|
||||
@@ -69,7 +71,7 @@ class BfxWebSocketInputs:
|
||||
ids: Optional[List[int]] = None,
|
||||
cids: Optional[List[Tuple[int, str]]] = None,
|
||||
gids: Optional[List[int]] = None,
|
||||
all: bool = False) -> None:
|
||||
all: Optional[bool] = None) -> None:
|
||||
await self.__handle_websocket_input("oc_multi", {
|
||||
"ids": ids, "cids": cids, "gids": gids,
|
||||
"all": all
|
||||
@@ -77,13 +79,13 @@ class BfxWebSocketInputs:
|
||||
|
||||
#pylint: disable-next=too-many-arguments
|
||||
async def submit_funding_offer(self,
|
||||
type: "FundingOfferType",
|
||||
type: FundingOfferType,
|
||||
symbol: str,
|
||||
amount: Union["Decimal", float, str],
|
||||
rate: Union["Decimal", float, str],
|
||||
amount: Union[str, float, Decimal],
|
||||
rate: Union[str, float, Decimal],
|
||||
period: int,
|
||||
*,
|
||||
flags: Optional[int] = 0) -> None:
|
||||
flags: Optional[int] = None) -> None:
|
||||
await self.__handle_websocket_input("fon", {
|
||||
"type": type, "symbol": symbol, "amount": amount,
|
||||
"rate": rate, "period": period, "flags": flags
|
||||
|
||||
@@ -10,6 +10,8 @@ from typing_extensions import \
|
||||
from abc import \
|
||||
ABC, abstractmethod
|
||||
|
||||
from functools import wraps
|
||||
|
||||
from datetime import datetime
|
||||
|
||||
import hmac, hashlib, json
|
||||
@@ -60,6 +62,7 @@ class Connection(ABC):
|
||||
def _require_websocket_connection(
|
||||
function: Callable[Concatenate[_S, _P], Awaitable[_R]]
|
||||
) -> Callable[Concatenate[_S, _P], Awaitable[_R]]:
|
||||
@wraps(function)
|
||||
async def wrapper(self: _S, *args: Any, **kwargs: Any) -> _R:
|
||||
if self.open:
|
||||
return await function(self, *args, **kwargs)
|
||||
@@ -72,6 +75,7 @@ class Connection(ABC):
|
||||
def _require_websocket_authentication(
|
||||
function: Callable[Concatenate[_S, _P], Awaitable[_R]]
|
||||
) -> Callable[Concatenate[_S, _P], Awaitable[_R]]:
|
||||
@wraps(function)
|
||||
async def wrapper(self: _S, *args: Any, **kwargs: Any) -> _R:
|
||||
if not self.authentication:
|
||||
raise ActionRequiresAuthentication("To perform this action you need to " \
|
||||
|
||||
Reference in New Issue
Block a user