mirror of
https://github.com/aljazceru/bitfinex-api-py.git
synced 2025-12-18 22:34:21 +01:00
# Description <!--- Describe your changes in detail --> PR includes some global refactoring in preparation for the v3.0.0 stable release. ## Motivation and Context <!--- Why is this change required? What problem does it solve? --> - ## Related Issue <!--- If suggesting a new feature or change, please discuss it in an issue first --> <!--- If fixing a bug, there should be an issue describing it with steps to reproduce --> <!--- Please link to the issue here: --> PR fixes the following issue: - ## Type of change <!-- Select the most suitable choice and remove the others from the checklist --> - [X] Bug fix (non-breaking change which fixes an issue); # Checklist: - [X] I've done a self-review of my code; - [X] I've made corresponding changes to the documentation; - [X] I've made sure my changes generate no warnings; - [X] mypy returns no errors when run on the root package; <!-- If you use pre-commit hooks you can always check off the following tasks --> - [X] I've run black to format my code; - [X] I've run isort to format my code's import statements; - [X] flake8 reports no errors when run on the entire code base;
131 lines
4.0 KiB
Python
131 lines
4.0 KiB
Python
from decimal import Decimal
|
|
from typing import Any, Awaitable, Callable, Dict, List, Optional, Tuple, Union
|
|
|
|
_Handler = Callable[[str, Any], Awaitable[None]]
|
|
|
|
|
|
class BfxWebSocketInputs:
|
|
def __init__(self, handle_websocket_input: _Handler) -> None:
|
|
self.__handle_websocket_input = handle_websocket_input
|
|
|
|
async def submit_order(
|
|
self,
|
|
type: str,
|
|
symbol: str,
|
|
amount: Union[str, float, Decimal],
|
|
price: Union[str, float, Decimal],
|
|
*,
|
|
lev: Optional[int] = 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] = None,
|
|
tif: Optional[str] = None,
|
|
meta: Optional[Dict[str, Any]] = 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[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] = None,
|
|
lev: Optional[int] = 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,
|
|
"cid": cid,
|
|
"cid_date": cid_date,
|
|
"gid": gid,
|
|
"flags": flags,
|
|
"lev": lev,
|
|
"delta": delta,
|
|
"price_aux_limit": price_aux_limit,
|
|
"price_trailing": price_trailing,
|
|
"tif": tif,
|
|
},
|
|
)
|
|
|
|
async def cancel_order(
|
|
self,
|
|
*,
|
|
id: Optional[int] = None,
|
|
cid: Optional[int] = None,
|
|
cid_date: Optional[str] = None,
|
|
) -> None:
|
|
await self.__handle_websocket_input(
|
|
"oc", {"id": id, "cid": cid, "cid_date": cid_date}
|
|
)
|
|
|
|
async def cancel_order_multi(
|
|
self,
|
|
*,
|
|
id: Optional[List[int]] = None,
|
|
cid: Optional[List[Tuple[int, str]]] = None,
|
|
gid: Optional[List[int]] = None,
|
|
all: Optional[bool] = None,
|
|
) -> None:
|
|
await self.__handle_websocket_input(
|
|
"oc_multi", {"id": id, "cid": cid, "gid": gid, "all": all}
|
|
)
|
|
|
|
async def submit_funding_offer(
|
|
self,
|
|
type: str,
|
|
symbol: str,
|
|
amount: Union[str, float, Decimal],
|
|
rate: Union[str, float, Decimal],
|
|
period: int,
|
|
*,
|
|
flags: Optional[int] = None,
|
|
) -> None:
|
|
await self.__handle_websocket_input(
|
|
"fon",
|
|
{
|
|
"type": type,
|
|
"symbol": symbol,
|
|
"amount": amount,
|
|
"rate": rate,
|
|
"period": period,
|
|
"flags": flags,
|
|
},
|
|
)
|
|
|
|
async def cancel_funding_offer(self, id: int) -> None:
|
|
await self.__handle_websocket_input("foc", {"id": id})
|
|
|
|
async def calc(self, *args: str) -> None:
|
|
await self.__handle_websocket_input("calc", list(map(lambda arg: [arg], args)))
|