mirror of
https://github.com/aljazceru/bitfinex-api-py.git
synced 2025-12-18 22:34:21 +01:00
Merge pull request #242 from Davi0kProgramsThings/v3.0.2
Merge branch `Davi0kProgramsThings:v3.0.2` into branch `bitfinexcom:master`.
This commit is contained in:
38
MANIFEST
38
MANIFEST
@@ -1,38 +0,0 @@
|
||||
# file GENERATED by distutils, do NOT edit
|
||||
setup.py
|
||||
bfxapi/__init__.py
|
||||
bfxapi/_client.py
|
||||
bfxapi/_version.py
|
||||
bfxapi/exceptions.py
|
||||
bfxapi/_utils/__init__.py
|
||||
bfxapi/_utils/json_decoder.py
|
||||
bfxapi/_utils/json_encoder.py
|
||||
bfxapi/_utils/logging.py
|
||||
bfxapi/rest/__init__.py
|
||||
bfxapi/rest/_bfx_rest_interface.py
|
||||
bfxapi/rest/exceptions.py
|
||||
bfxapi/rest/_interface/__init__.py
|
||||
bfxapi/rest/_interface/interface.py
|
||||
bfxapi/rest/_interface/middleware.py
|
||||
bfxapi/rest/_interfaces/__init__.py
|
||||
bfxapi/rest/_interfaces/rest_auth_endpoints.py
|
||||
bfxapi/rest/_interfaces/rest_merchant_endpoints.py
|
||||
bfxapi/rest/_interfaces/rest_public_endpoints.py
|
||||
bfxapi/types/__init__.py
|
||||
bfxapi/types/dataclasses.py
|
||||
bfxapi/types/labeler.py
|
||||
bfxapi/types/notification.py
|
||||
bfxapi/types/serializers.py
|
||||
bfxapi/websocket/__init__.py
|
||||
bfxapi/websocket/_connection.py
|
||||
bfxapi/websocket/exceptions.py
|
||||
bfxapi/websocket/subscriptions.py
|
||||
bfxapi/websocket/_client/__init__.py
|
||||
bfxapi/websocket/_client/bfx_websocket_bucket.py
|
||||
bfxapi/websocket/_client/bfx_websocket_client.py
|
||||
bfxapi/websocket/_client/bfx_websocket_inputs.py
|
||||
bfxapi/websocket/_event_emitter/__init__.py
|
||||
bfxapi/websocket/_event_emitter/bfx_event_emitter.py
|
||||
bfxapi/websocket/_handlers/__init__.py
|
||||
bfxapi/websocket/_handlers/auth_events_handler.py
|
||||
bfxapi/websocket/_handlers/public_channels_handler.py
|
||||
@@ -1 +1 @@
|
||||
__version__ = "3.0.1"
|
||||
__version__ = "3.0.2"
|
||||
|
||||
@@ -248,7 +248,7 @@ class RestAuthEndpoints(Interface):
|
||||
|
||||
def get_base_margin_info(self) -> BaseMarginInfo:
|
||||
return serializers.BaseMarginInfo.parse(
|
||||
*(self._m.post("auth/r/info/margin/base")[1])
|
||||
*self._m.post("auth/r/info/margin/base")
|
||||
)
|
||||
|
||||
def get_symbol_margin_info(self, symbol: str) -> SymbolMarginInfo:
|
||||
@@ -551,7 +551,7 @@ class RestAuthEndpoints(Interface):
|
||||
|
||||
def get_funding_info(self, key: str) -> FundingInfo:
|
||||
return serializers.FundingInfo.parse(
|
||||
*(self._m.post(f"auth/r/info/funding/{key}")[2])
|
||||
*self._m.post(f"auth/r/info/funding/{key}")
|
||||
)
|
||||
|
||||
def transfer_between_wallets(
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
from .dataclasses import (
|
||||
BalanceAvailable,
|
||||
BalanceInfo,
|
||||
BaseMarginInfo,
|
||||
Candle,
|
||||
CurrencyConversion,
|
||||
|
||||
@@ -428,6 +428,7 @@ class FundingAutoRenew(_Type):
|
||||
|
||||
@dataclass()
|
||||
class FundingInfo(_Type):
|
||||
symbol: str
|
||||
yield_loan: float
|
||||
yield_lend: float
|
||||
duration_loan: float
|
||||
@@ -607,6 +608,12 @@ class DerivativePositionCollateralLimits(_Type):
|
||||
max_collateral: float
|
||||
|
||||
|
||||
@dataclass
|
||||
class BalanceInfo(_Type):
|
||||
aum: float
|
||||
aum_net: float
|
||||
|
||||
|
||||
# endregion
|
||||
|
||||
# region Dataclass definitions for types of merchant use
|
||||
|
||||
@@ -632,7 +632,15 @@ FundingAutoRenew = generate_labeler_serializer(
|
||||
FundingInfo = generate_labeler_serializer(
|
||||
name="FundingInfo",
|
||||
klass=dataclasses.FundingInfo,
|
||||
labels=["yield_loan", "yield_lend", "duration_loan", "duration_lend"],
|
||||
labels=[
|
||||
"_PLACEHOLDER",
|
||||
"symbol",
|
||||
"yield_loan",
|
||||
"yield_lend",
|
||||
"duration_loan",
|
||||
"duration_lend",
|
||||
],
|
||||
flat=True,
|
||||
)
|
||||
|
||||
Wallet = generate_labeler_serializer(
|
||||
@@ -745,7 +753,15 @@ SymbolMarginInfo = generate_labeler_serializer(
|
||||
BaseMarginInfo = generate_labeler_serializer(
|
||||
name="BaseMarginInfo",
|
||||
klass=dataclasses.BaseMarginInfo,
|
||||
labels=["user_pl", "user_swaps", "margin_balance", "margin_net", "margin_min"],
|
||||
labels=[
|
||||
"_PLACEHOLDER",
|
||||
"user_pl",
|
||||
"user_swaps",
|
||||
"margin_balance",
|
||||
"margin_net",
|
||||
"margin_min",
|
||||
],
|
||||
flat=True,
|
||||
)
|
||||
|
||||
PositionClaim = generate_labeler_serializer(
|
||||
@@ -888,4 +904,10 @@ DerivativePositionCollateralLimits = generate_labeler_serializer(
|
||||
labels=["min_collateral", "max_collateral"],
|
||||
)
|
||||
|
||||
BalanceInfo = generate_labeler_serializer(
|
||||
name="BalanceInfo",
|
||||
klass=dataclasses.BalanceInfo,
|
||||
labels=["aum", "aum_net"],
|
||||
)
|
||||
|
||||
# endregion
|
||||
|
||||
@@ -64,6 +64,10 @@ _COMMON = [
|
||||
"trade_execution",
|
||||
"trade_execution_update",
|
||||
"wallet_update",
|
||||
"base_margin_info",
|
||||
"symbol_margin_info",
|
||||
"funding_info_update",
|
||||
"balance_update",
|
||||
"notification",
|
||||
"on-req-notification",
|
||||
"ou-req-notification",
|
||||
@@ -105,7 +109,7 @@ class BfxEventEmitter(AsyncIOEventEmitter):
|
||||
) -> Union[_Handler, Callable[[_Handler], _Handler]]:
|
||||
if event not in BfxEventEmitter._EVENTS:
|
||||
raise UnknownEventError(
|
||||
f"Can't register to unknown event: <{event}> (to get a full"
|
||||
f"Can't register to unknown event: <{event}> (to get a full "
|
||||
"list of available events see https://docs.bitfinex.com/)."
|
||||
)
|
||||
|
||||
|
||||
@@ -33,6 +33,8 @@ class AuthEventsHandler:
|
||||
"flc": "funding_loan_close",
|
||||
"ws": "wallet_snapshot",
|
||||
"wu": "wallet_update",
|
||||
"fiu": "funding_info_update",
|
||||
"bu": "balance_update",
|
||||
}
|
||||
|
||||
__SERIALIZERS: Dict[Tuple[str, ...], serializers._Serializer] = {
|
||||
@@ -43,6 +45,8 @@ class AuthEventsHandler:
|
||||
("fcs", "fcn", "fcu", "fcc"): serializers.FundingCredit,
|
||||
("fls", "fln", "flu", "flc"): serializers.FundingLoan,
|
||||
("ws", "wu"): serializers.Wallet,
|
||||
("fiu",): serializers.FundingInfo,
|
||||
("bu",): serializers.BalanceInfo,
|
||||
}
|
||||
|
||||
def __init__(self, event_emitter: EventEmitter) -> None:
|
||||
@@ -51,7 +55,16 @@ class AuthEventsHandler:
|
||||
def handle(self, abbrevation: str, stream: Any) -> None:
|
||||
if abbrevation == "n":
|
||||
self.__notification(stream)
|
||||
|
||||
elif abbrevation == "miu":
|
||||
if stream[0] == "base":
|
||||
self.__event_emitter.emit(
|
||||
"base_margin_info", serializers.BaseMarginInfo.parse(*stream)
|
||||
)
|
||||
elif stream[0] == "sym":
|
||||
self.__event_emitter.emit(
|
||||
"symbol_margin_info", serializers.SymbolMarginInfo.parse(*stream)
|
||||
)
|
||||
else:
|
||||
for abbrevations, serializer in AuthEventsHandler.__SERIALIZERS.items():
|
||||
if abbrevation in abbrevations:
|
||||
event = AuthEventsHandler.__ABBREVIATIONS[abbrevation]
|
||||
|
||||
36
examples/websocket/auth/calc.py
Normal file
36
examples/websocket/auth/calc.py
Normal file
@@ -0,0 +1,36 @@
|
||||
# python -c "import examples.websocket.auth.calc"
|
||||
|
||||
import os
|
||||
|
||||
from bfxapi import Client
|
||||
from bfxapi.types import BaseMarginInfo, FundingInfo, SymbolMarginInfo
|
||||
|
||||
bfx = Client(
|
||||
api_key=os.getenv("BFX_API_KEY"),
|
||||
api_secret=os.getenv("BFX_API_SECRET"),
|
||||
)
|
||||
|
||||
|
||||
@bfx.wss.on("authenticated")
|
||||
async def on_authenticated(_):
|
||||
await bfx.wss.inputs.calc("margin_base", "margin_sym_tBTCUSD", "funding_sym_fUST")
|
||||
|
||||
|
||||
@bfx.wss.on("base_margin_info")
|
||||
def on_base_margin_info(data: BaseMarginInfo):
|
||||
print("Base margin info:", data)
|
||||
|
||||
|
||||
@bfx.wss.on("symbol_margin_info")
|
||||
def on_symbol_margin_info(data: SymbolMarginInfo):
|
||||
if data.symbol == "tBTCUSD":
|
||||
print("Symbol margin info:", data)
|
||||
|
||||
|
||||
@bfx.wss.on("funding_info_update")
|
||||
def on_funding_info_update(data: FundingInfo):
|
||||
if data.symbol == "fUST":
|
||||
print("Funding info update:", data)
|
||||
|
||||
|
||||
bfx.wss.run()
|
||||
Reference in New Issue
Block a user