Merge bfxapi.rest.types and bfxapi.websocket.types in bfxapi.tests sub-package.

This commit is contained in:
Davide Casale
2023-04-20 03:44:13 +02:00
parent 34a1b0099e
commit 0f9fa1bf6a
32 changed files with 164 additions and 759 deletions

View File

@@ -1,16 +1,8 @@
__all__ = [
"BfxBaseException",
"LabelerSerializerException",
]
class BfxBaseException(Exception):
"""
Base class for every custom exception in bfxapi/rest/exceptions.py and bfxapi/websocket/exceptions.py.
"""
class LabelerSerializerException(BfxBaseException):
"""
This exception indicates an error thrown by the _Serializer class in bfxapi/labeler.py.
"""

View File

@@ -2,7 +2,11 @@ from typing import Dict, List, Tuple, Union, Literal, Optional
from decimal import Decimal
from datetime import datetime
from .. types import Notification, \
from .. middleware import Middleware
from .. enums import Sort, OrderType, FundingOfferType
from ... types import JSON, Notification, \
UserInfo, LoginHistory, BalanceAvailable, \
Order, Position, Trade, \
FundingTrade, OrderTrade, Ledger, \
@@ -14,13 +18,9 @@ from .. types import Notification, \
PositionIncrease, PositionHistory, PositionSnapshot, \
PositionAudit, DerivativePositionCollateral, DerivativePositionCollateralLimits
from .. import serializers
from ... types import serializers
from .. serializers import _Notification
from .. enums import Sort, OrderType, FundingOfferType
from .. middleware import Middleware
from ...utils.json_encoder import JSON
from ... types.serializers import _Notification
class RestAuthenticatedEndpoints(Middleware):
def get_user_info(self) -> UserInfo:

View File

@@ -5,13 +5,13 @@ from typing import Callable, TypeVar, cast, \
from decimal import Decimal
from .. types import \
InvoiceSubmission, InvoicePage, InvoiceStats, \
CurrencyConversion, MerchantDeposit, MerchantUnlinkedDeposit
from .. middleware import Middleware
from .. enums import MerchantSettingsKey
from .. middleware import Middleware
from ... types import \
InvoiceSubmission, InvoicePage, InvoiceStats, \
CurrencyConversion, MerchantDeposit, MerchantUnlinkedDeposit
#region Defining methods to convert dictionary keys to snake_case and camelCase.

View File

@@ -2,7 +2,11 @@ from typing import List, Dict, Union, Literal, Optional, Any, cast
from decimal import Decimal
from .. types import \
from .. middleware import Middleware
from .. enums import Config, Sort
from ... types import \
PlatformStatus, TradingPairTicker, FundingCurrencyTicker, \
TickersHistory, TradingPairTrade, FundingCurrencyTrade, \
TradingPairBook, FundingCurrencyBook, TradingPairRawBook, \
@@ -11,9 +15,7 @@ from .. types import \
FundingStatistic, PulseProfile, PulseMessage, \
TradingMarketAveragePrice, FundingMarketAveragePrice, FxRate
from .. import serializers
from .. enums import Config, Sort
from .. middleware import Middleware
from ... types import serializers
class RestPublicEndpoints(Middleware):
def conf(self, config: Config) -> Any:

26
bfxapi/types/__init__.py Normal file
View File

@@ -0,0 +1,26 @@
from . dataclasses import JSON, \
PlatformStatus, TradingPairTicker, FundingCurrencyTicker, \
TickersHistory, TradingPairTrade, FundingCurrencyTrade, \
TradingPairBook, FundingCurrencyBook, TradingPairRawBook, \
FundingCurrencyRawBook, Statistic, Candle, \
DerivativesStatus, Liquidation, Leaderboard, \
FundingStatistic, PulseProfile, PulseMessage, \
TradingMarketAveragePrice, FundingMarketAveragePrice, FxRate
from . dataclasses import \
UserInfo, LoginHistory, BalanceAvailable, \
Order, Position, Trade, \
FundingTrade, OrderTrade, Ledger, \
FundingOffer, FundingCredit, FundingLoan, \
FundingAutoRenew, FundingInfo, Wallet, \
Transfer, Withdrawal, DepositAddress, \
LightningNetworkInvoice, Movement, SymbolMarginInfo, \
BaseMarginInfo, PositionClaim, PositionIncreaseInfo, \
PositionIncrease, PositionHistory, PositionSnapshot, \
PositionAudit, DerivativePositionCollateral, DerivativePositionCollateralLimits
from . dataclasses import \
InvoiceSubmission, InvoicePage, InvoiceStats, \
CurrencyConversion, MerchantDeposit, MerchantUnlinkedDeposit
from . notification import Notification

View File

@@ -1,18 +1,13 @@
#pylint: disable=duplicate-code
#pylint: disable-next=wildcard-import,unused-wildcard-import
from typing import *
from typing import Union, Type, \
List, Dict, Literal, Optional, Any
from dataclasses import dataclass
from .. labeler import _Type, partial, compose
from . labeler import _Type, partial, compose
#pylint: disable-next=unused-import
from .. notification import Notification
JSON = Union[Dict[str, "JSON"], List["JSON"], bool, int, float, str, Type[None]]
from ..utils.json_encoder import JSON
#region Type hinting for Rest Public Endpoints
#region Dataclass definitions for types of public use
@dataclass
class PlatformStatus(_Type):
@@ -198,7 +193,7 @@ class FxRate(_Type):
#endregion
#region Type hinting for Rest Authenticated Endpoints
#region Dataclass definitions for types of auth use
@dataclass
class UserInfo(_Type):
@@ -565,7 +560,7 @@ class DerivativePositionCollateralLimits(_Type):
#endregion
#region Type hinting for Rest Merchant Endpoints
#region Dataclass definitions for types of merchant use
@compose(dataclass, partial)
class InvoiceSubmission(_Type):

View File

@@ -1,6 +1,5 @@
from typing import Type, Generic, TypeVar, Iterable, Dict, List, Tuple, Any, cast
from .exceptions import LabelerSerializerException
from typing import Type, Generic, TypeVar, Iterable, \
Dict, List, Tuple, Any, cast
T = TypeVar("T", bound="_Type")
@@ -43,7 +42,7 @@ class _Serializer(Generic[T]):
args = tuple(_Serializer.__flatten(list(args)))
if len(self.__labels) > len(args):
raise LabelerSerializerException(f"{self.name} -> <labels> and <*args> " \
raise AssertionError(f"{self.name} -> <labels> and <*args> " \
"arguments should contain the same amount of elements.")
for index, label in enumerate(self.__labels):

View File

@@ -1,6 +1,6 @@
from typing import List, Optional, Any, Generic, TypeVar, cast
from dataclasses import dataclass
from .labeler import _Type, _Serializer
from . labeler import _Type, _Serializer
T = TypeVar("T")

View File

@@ -1,11 +1,10 @@
#pylint: disable=duplicate-code
from . import dataclasses
from . import types
from .. labeler import generate_labeler_serializer, generate_recursive_serializer
from . labeler import \
generate_labeler_serializer, generate_recursive_serializer
#pylint: disable-next=unused-import
from .. notification import _Notification
from . notification import _Notification
__serializers__ = [
"PlatformStatus", "TradingPairTicker", "FundingCurrencyTicker",
@@ -28,11 +27,11 @@ __serializers__ = [
"PositionAudit", "DerivativePositionCollateral", "DerivativePositionCollateralLimits",
]
#region Serializers definition for Rest Public Endpoints
#region Serializer definitions for types of public use
PlatformStatus = generate_labeler_serializer(
name="PlatformStatus",
klass=types.PlatformStatus,
klass=dataclasses.PlatformStatus,
labels=[
"status"
]
@@ -40,7 +39,7 @@ PlatformStatus = generate_labeler_serializer(
TradingPairTicker = generate_labeler_serializer(
name="TradingPairTicker",
klass=types.TradingPairTicker,
klass=dataclasses.TradingPairTicker,
labels=[
"bid",
"bid_size",
@@ -57,7 +56,7 @@ TradingPairTicker = generate_labeler_serializer(
FundingCurrencyTicker = generate_labeler_serializer(
name="FundingCurrencyTicker",
klass=types.FundingCurrencyTicker,
klass=dataclasses.FundingCurrencyTicker,
labels=[
"frr",
"bid",
@@ -80,7 +79,7 @@ FundingCurrencyTicker = generate_labeler_serializer(
TickersHistory = generate_labeler_serializer(
name="TickersHistory",
klass=types.TickersHistory,
klass=dataclasses.TickersHistory,
labels=[
"symbol",
"bid",
@@ -100,7 +99,7 @@ TickersHistory = generate_labeler_serializer(
TradingPairTrade = generate_labeler_serializer(
name="TradingPairTrade",
klass=types.TradingPairTrade,
klass=dataclasses.TradingPairTrade,
labels=[
"id",
"mts",
@@ -111,7 +110,7 @@ TradingPairTrade = generate_labeler_serializer(
FundingCurrencyTrade = generate_labeler_serializer(
name="FundingCurrencyTrade",
klass=types.FundingCurrencyTrade,
klass=dataclasses.FundingCurrencyTrade,
labels=[
"id",
"mts",
@@ -123,7 +122,7 @@ FundingCurrencyTrade = generate_labeler_serializer(
TradingPairBook = generate_labeler_serializer(
name="TradingPairBook",
klass=types.TradingPairBook,
klass=dataclasses.TradingPairBook,
labels=[
"price",
"count",
@@ -133,7 +132,7 @@ TradingPairBook = generate_labeler_serializer(
FundingCurrencyBook = generate_labeler_serializer(
name="FundingCurrencyBook",
klass=types.FundingCurrencyBook,
klass=dataclasses.FundingCurrencyBook,
labels=[
"rate",
"period",
@@ -144,7 +143,7 @@ FundingCurrencyBook = generate_labeler_serializer(
TradingPairRawBook = generate_labeler_serializer(
name="TradingPairRawBook",
klass=types.TradingPairRawBook,
klass=dataclasses.TradingPairRawBook,
labels=[
"order_id",
"price",
@@ -154,7 +153,7 @@ TradingPairRawBook = generate_labeler_serializer(
FundingCurrencyRawBook = generate_labeler_serializer(
name="FundingCurrencyRawBook",
klass=types.FundingCurrencyRawBook,
klass=dataclasses.FundingCurrencyRawBook,
labels=[
"offer_id",
"period",
@@ -165,7 +164,7 @@ FundingCurrencyRawBook = generate_labeler_serializer(
Statistic = generate_labeler_serializer(
name="Statistic",
klass=types.Statistic,
klass=dataclasses.Statistic,
labels=[
"mts",
"value"
@@ -174,7 +173,7 @@ Statistic = generate_labeler_serializer(
Candle = generate_labeler_serializer(
name="Candle",
klass=types.Candle,
klass=dataclasses.Candle,
labels=[
"mts",
"open",
@@ -187,7 +186,7 @@ Candle = generate_labeler_serializer(
DerivativesStatus = generate_labeler_serializer(
name="DerivativesStatus",
klass=types.DerivativesStatus,
klass=dataclasses.DerivativesStatus,
labels=[
"mts",
"_PLACEHOLDER",
@@ -217,7 +216,7 @@ DerivativesStatus = generate_labeler_serializer(
Liquidation = generate_labeler_serializer(
name="Liquidation",
klass=types.Liquidation,
klass=dataclasses.Liquidation,
labels=[
"_PLACEHOLDER",
"pos_id",
@@ -236,7 +235,7 @@ Liquidation = generate_labeler_serializer(
Leaderboard = generate_labeler_serializer(
name="Leaderboard",
klass=types.Leaderboard,
klass=dataclasses.Leaderboard,
labels=[
"mts",
"_PLACEHOLDER",
@@ -253,7 +252,7 @@ Leaderboard = generate_labeler_serializer(
FundingStatistic = generate_labeler_serializer(
name="FundingStatistic",
klass=types.FundingStatistic,
klass=dataclasses.FundingStatistic,
labels=[
"mts",
"_PLACEHOLDER",
@@ -272,7 +271,7 @@ FundingStatistic = generate_labeler_serializer(
PulseProfile = generate_labeler_serializer(
name="PulseProfile",
klass=types.PulseProfile,
klass=dataclasses.PulseProfile,
labels=[
"puid",
"mts",
@@ -296,7 +295,7 @@ PulseProfile = generate_labeler_serializer(
PulseMessage = generate_recursive_serializer(
name="PulseMessage",
klass=types.PulseMessage,
klass=dataclasses.PulseMessage,
serializers={ "profile": PulseProfile },
labels=[
"pid",
@@ -326,7 +325,7 @@ PulseMessage = generate_recursive_serializer(
TradingMarketAveragePrice = generate_labeler_serializer(
name="TradingMarketAveragePrice",
klass=types.TradingMarketAveragePrice,
klass=dataclasses.TradingMarketAveragePrice,
labels=[
"price_avg",
"amount"
@@ -335,7 +334,7 @@ TradingMarketAveragePrice = generate_labeler_serializer(
FundingMarketAveragePrice = generate_labeler_serializer(
name="FundingMarketAveragePrice",
klass=types.FundingMarketAveragePrice,
klass=dataclasses.FundingMarketAveragePrice,
labels=[
"rate_avg",
"amount"
@@ -344,7 +343,7 @@ FundingMarketAveragePrice = generate_labeler_serializer(
FxRate = generate_labeler_serializer(
name="FxRate",
klass=types.FxRate,
klass=dataclasses.FxRate,
labels=[
"current_rate"
]
@@ -352,11 +351,11 @@ FxRate = generate_labeler_serializer(
#endregion
#region Serializers definition for Rest Authenticated Endpoints
#region Serializer definitions for types of auth use
UserInfo = generate_labeler_serializer(
name="UserInfo",
klass=types.UserInfo,
klass=dataclasses.UserInfo,
labels=[
"id",
"email",
@@ -418,7 +417,7 @@ UserInfo = generate_labeler_serializer(
LoginHistory = generate_labeler_serializer(
name="LoginHistory",
klass=types.LoginHistory,
klass=dataclasses.LoginHistory,
labels=[
"id",
"_PLACEHOLDER",
@@ -433,7 +432,7 @@ LoginHistory = generate_labeler_serializer(
BalanceAvailable = generate_labeler_serializer(
name="BalanceAvailable",
klass=types.BalanceAvailable,
klass=dataclasses.BalanceAvailable,
labels=[
"amount"
]
@@ -441,7 +440,7 @@ BalanceAvailable = generate_labeler_serializer(
Order = generate_labeler_serializer(
name="Order",
klass=types.Order,
klass=dataclasses.Order,
labels=[
"id",
"gid",
@@ -480,7 +479,7 @@ Order = generate_labeler_serializer(
Position = generate_labeler_serializer(
name="Position",
klass=types.Position,
klass=dataclasses.Position,
labels=[
"symbol",
"status",
@@ -507,7 +506,7 @@ Position = generate_labeler_serializer(
Trade = generate_labeler_serializer(
name="Trade",
klass=types.Trade,
klass=dataclasses.Trade,
labels=[
"id",
"symbol",
@@ -526,7 +525,7 @@ Trade = generate_labeler_serializer(
FundingTrade = generate_labeler_serializer(
name="FundingTrade",
klass=types.FundingTrade,
klass=dataclasses.FundingTrade,
labels=[
"id",
"currency",
@@ -540,7 +539,7 @@ FundingTrade = generate_labeler_serializer(
OrderTrade = generate_labeler_serializer(
name="OrderTrade",
klass=types.OrderTrade,
klass=dataclasses.OrderTrade,
labels=[
"id",
"symbol",
@@ -559,7 +558,7 @@ OrderTrade = generate_labeler_serializer(
Ledger = generate_labeler_serializer(
name="Ledger",
klass=types.Ledger,
klass=dataclasses.Ledger,
labels=[
"id",
"currency",
@@ -575,7 +574,7 @@ Ledger = generate_labeler_serializer(
FundingOffer = generate_labeler_serializer(
name="FundingOffer",
klass=types.FundingOffer,
klass=dataclasses.FundingOffer,
labels=[
"id",
"symbol",
@@ -603,7 +602,7 @@ FundingOffer = generate_labeler_serializer(
FundingCredit = generate_labeler_serializer(
name="FundingCredit",
klass=types.FundingCredit,
klass=dataclasses.FundingCredit,
labels=[
"id",
"symbol",
@@ -632,7 +631,7 @@ FundingCredit = generate_labeler_serializer(
FundingLoan = generate_labeler_serializer(
name="FundingLoan",
klass=types.FundingLoan,
klass=dataclasses.FundingLoan,
labels=[
"id",
"symbol",
@@ -660,7 +659,7 @@ FundingLoan = generate_labeler_serializer(
FundingAutoRenew = generate_labeler_serializer(
name="FundingAutoRenew",
klass=types.FundingAutoRenew,
klass=dataclasses.FundingAutoRenew,
labels=[
"currency",
"period",
@@ -671,7 +670,7 @@ FundingAutoRenew = generate_labeler_serializer(
FundingInfo = generate_labeler_serializer(
name="FundingInfo",
klass=types.FundingInfo,
klass=dataclasses.FundingInfo,
labels=[
"yield_loan",
"yield_lend",
@@ -682,7 +681,7 @@ FundingInfo = generate_labeler_serializer(
Wallet = generate_labeler_serializer(
name="Wallet",
klass=types.Wallet,
klass=dataclasses.Wallet,
labels=[
"wallet_type",
"currency",
@@ -696,7 +695,7 @@ Wallet = generate_labeler_serializer(
Transfer = generate_labeler_serializer(
name="Transfer",
klass=types.Transfer,
klass=dataclasses.Transfer,
labels=[
"mts",
"wallet_from",
@@ -711,7 +710,7 @@ Transfer = generate_labeler_serializer(
Withdrawal = generate_labeler_serializer(
name="Withdrawal",
klass=types.Withdrawal,
klass=dataclasses.Withdrawal,
labels=[
"withdrawal_id",
"_PLACEHOLDER",
@@ -727,7 +726,7 @@ Withdrawal = generate_labeler_serializer(
DepositAddress = generate_labeler_serializer(
name="DepositAddress",
klass=types.DepositAddress,
klass=dataclasses.DepositAddress,
labels=[
"_PLACEHOLDER",
"method",
@@ -740,7 +739,7 @@ DepositAddress = generate_labeler_serializer(
LightningNetworkInvoice = generate_labeler_serializer(
name="LightningNetworkInvoice",
klass=types.LightningNetworkInvoice,
klass=dataclasses.LightningNetworkInvoice,
labels=[
"invoice_hash",
"invoice",
@@ -752,7 +751,7 @@ LightningNetworkInvoice = generate_labeler_serializer(
Movement = generate_labeler_serializer(
name="Movement",
klass=types.Movement,
klass=dataclasses.Movement,
labels=[
"id",
"currency",
@@ -781,7 +780,7 @@ Movement = generate_labeler_serializer(
SymbolMarginInfo = generate_labeler_serializer(
name="SymbolMarginInfo",
klass=types.SymbolMarginInfo,
klass=dataclasses.SymbolMarginInfo,
labels=[
"_PLACEHOLDER",
"symbol",
@@ -796,7 +795,7 @@ SymbolMarginInfo = generate_labeler_serializer(
BaseMarginInfo = generate_labeler_serializer(
name="BaseMarginInfo",
klass=types.BaseMarginInfo,
klass=dataclasses.BaseMarginInfo,
labels=[
"user_pl",
"user_swaps",
@@ -808,7 +807,7 @@ BaseMarginInfo = generate_labeler_serializer(
PositionClaim = generate_labeler_serializer(
name="PositionClaim",
klass=types.PositionClaim,
klass=dataclasses.PositionClaim,
labels=[
"symbol",
"position_status",
@@ -835,7 +834,7 @@ PositionClaim = generate_labeler_serializer(
PositionIncreaseInfo = generate_labeler_serializer(
name="PositionIncreaseInfo",
klass=types.PositionIncreaseInfo,
klass=dataclasses.PositionIncreaseInfo,
labels=[
"max_pos",
"current_pos",
@@ -862,7 +861,7 @@ PositionIncreaseInfo = generate_labeler_serializer(
PositionIncrease = generate_labeler_serializer(
name="PositionIncrease",
klass=types.PositionIncrease,
klass=dataclasses.PositionIncrease,
labels=[
"symbol",
"_PLACEHOLDER",
@@ -873,7 +872,7 @@ PositionIncrease = generate_labeler_serializer(
PositionHistory = generate_labeler_serializer(
name="PositionHistory",
klass=types.PositionHistory,
klass=dataclasses.PositionHistory,
labels=[
"symbol",
"status",
@@ -894,7 +893,7 @@ PositionHistory = generate_labeler_serializer(
PositionSnapshot = generate_labeler_serializer(
name="PositionSnapshot",
klass=types.PositionSnapshot,
klass=dataclasses.PositionSnapshot,
labels=[
"symbol",
"status",
@@ -915,7 +914,7 @@ PositionSnapshot = generate_labeler_serializer(
PositionAudit = generate_labeler_serializer(
name="PositionAudit",
klass=types.PositionAudit,
klass=dataclasses.PositionAudit,
labels=[
"symbol",
"status",
@@ -942,7 +941,7 @@ PositionAudit = generate_labeler_serializer(
DerivativePositionCollateral = generate_labeler_serializer(
name="DerivativePositionCollateral",
klass=types.DerivativePositionCollateral,
klass=dataclasses.DerivativePositionCollateral,
labels=[
"status"
]
@@ -950,7 +949,7 @@ DerivativePositionCollateral = generate_labeler_serializer(
DerivativePositionCollateralLimits = generate_labeler_serializer(
name="DerivativePositionCollateralLimits",
klass=types.DerivativePositionCollateralLimits,
klass=dataclasses.DerivativePositionCollateralLimits,
labels=[
"min_collateral",
"max_collateral"

View File

@@ -1,9 +1,9 @@
from .. import serializers
from .. serializers import _Notification
from .. exceptions import HandlerNotFound
from ... types import serializers
from ... types.serializers import _Notification
class AuthenticatedEventsHandler:
__once_abbreviations = {
"os": "order_snapshot", "ps": "position_snapshot", "fos": "funding_offer_snapshot",
@@ -16,8 +16,7 @@ class AuthenticatedEventsHandler:
"fon": "funding_offer_new", "fou": "funding_offer_update", "foc": "funding_offer_cancel",
"fcn": "funding_credit_new", "fcu": "funding_credit_update", "fcc": "funding_credit_close",
"fln": "funding_loan_new", "flu": "funding_loan_update", "flc": "funding_loan_close",
"te": "trade_execution", "tu": "trade_execution_update", "wu": "wallet_update",
"bu": "balance_update"
"te": "trade_execution", "tu": "trade_execution_update", "wu": "wallet_update"
}
__abbreviations = {
@@ -32,8 +31,7 @@ class AuthenticatedEventsHandler:
("fos", "fon", "fou", "foc",): serializers.FundingOffer,
("fcs", "fcn", "fcu", "fcc",): serializers.FundingCredit,
("fls", "fln", "flu", "flc",): serializers.FundingLoan,
("ws", "wu",): serializers.Wallet,
("bu",): serializers.Balance
("ws", "wu",): serializers.Wallet
}
ONCE_EVENTS = [

View File

@@ -1,7 +1,7 @@
from .. import serializers
from .. exceptions import HandlerNotFound
from ... types import serializers
class PublicChannelsHandler:
ONCE_PER_SUBSCRIPTION_EVENTS = [
"t_trades_snapshot", "f_trades_snapshot", "t_book_snapshot",

View File

@@ -1,368 +0,0 @@
#pylint: disable=duplicate-code
from . import types
from .. labeler import generate_labeler_serializer
#pylint: disable-next=unused-import
from .. notification import _Notification
__serializers__ = [
"TradingPairTicker", "FundingCurrencyTicker", "TradingPairTrade",
"FundingCurrencyTrade", "TradingPairBook", "FundingCurrencyBook",
"TradingPairRawBook", "FundingCurrencyRawBook", "Candle",
"DerivativesStatus",
"Order", "Position", "Trade",
"FundingOffer", "FundingCredit", "FundingLoan",
"Wallet", "Balance",
]
#region Serializers definition for WebSocket Public Channels
TradingPairTicker = generate_labeler_serializer(
name="TradingPairTicker",
klass=types.TradingPairTicker,
labels=[
"bid",
"bid_size",
"ask",
"ask_size",
"daily_change",
"daily_change_relative",
"last_price",
"volume",
"high",
"low"
]
)
FundingCurrencyTicker = generate_labeler_serializer(
name="FundingCurrencyTicker",
klass=types.FundingCurrencyTicker,
labels=[
"frr",
"bid",
"bid_period",
"bid_size",
"ask",
"ask_period",
"ask_size",
"daily_change",
"daily_change_relative",
"last_price",
"volume",
"high",
"low",
"_PLACEHOLDER",
"_PLACEHOLDER",
"frr_amount_available"
]
)
TradingPairTrade = generate_labeler_serializer(
name="TradingPairTrade",
klass=types.TradingPairTrade,
labels=[
"id",
"mts",
"amount",
"price"
]
)
FundingCurrencyTrade = generate_labeler_serializer(
name="FundingCurrencyTrade",
klass=types.FundingCurrencyTrade,
labels=[
"id",
"mts",
"amount",
"rate",
"period"
]
)
TradingPairBook = generate_labeler_serializer(
name="TradingPairBook",
klass=types.TradingPairBook,
labels=[
"price",
"count",
"amount"
]
)
FundingCurrencyBook = generate_labeler_serializer(
name="FundingCurrencyBook",
klass=types.FundingCurrencyBook,
labels=[
"rate",
"period",
"count",
"amount"
]
)
TradingPairRawBook = generate_labeler_serializer(
name="TradingPairRawBook",
klass=types.TradingPairRawBook,
labels=[
"order_id",
"price",
"amount"
]
)
FundingCurrencyRawBook = generate_labeler_serializer(
name="FundingCurrencyRawBook",
klass=types.FundingCurrencyRawBook,
labels=[
"offer_id",
"period",
"rate",
"amount"
]
)
Candle = generate_labeler_serializer(
name="Candle",
klass=types.Candle,
labels=[
"mts",
"open",
"close",
"high",
"low",
"volume"
]
)
DerivativesStatus = generate_labeler_serializer(
name="DerivativesStatus",
klass=types.DerivativesStatus,
labels=[
"mts",
"_PLACEHOLDER",
"deriv_price",
"spot_price",
"_PLACEHOLDER",
"insurance_fund_balance",
"_PLACEHOLDER",
"next_funding_evt_mts",
"next_funding_accrued",
"next_funding_step",
"_PLACEHOLDER",
"current_funding",
"_PLACEHOLDER",
"_PLACEHOLDER",
"mark_price",
"_PLACEHOLDER",
"_PLACEHOLDER",
"open_interest",
"_PLACEHOLDER",
"_PLACEHOLDER",
"_PLACEHOLDER",
"clamp_min",
"clamp_max"
]
)
#endregion
#region Serializers definition for WebSocket Authenticated Channels
Order = generate_labeler_serializer(
name="Order",
klass=types.Order,
labels=[
"id",
"gid",
"cid",
"symbol",
"mts_create",
"mts_update",
"amount",
"amount_orig",
"order_type",
"type_prev",
"mts_tif",
"_PLACEHOLDER",
"flags",
"order_status",
"_PLACEHOLDER",
"_PLACEHOLDER",
"price",
"price_avg",
"price_trailing",
"price_aux_limit",
"_PLACEHOLDER",
"_PLACEHOLDER",
"_PLACEHOLDER",
"notify",
"hidden",
"placed_id",
"_PLACEHOLDER",
"_PLACEHOLDER",
"routing",
"_PLACEHOLDER",
"_PLACEHOLDER",
"meta"
]
)
Position = generate_labeler_serializer(
name="Position",
klass=types.Position,
labels=[
"symbol",
"status",
"amount",
"base_price",
"margin_funding",
"margin_funding_type",
"pl",
"pl_perc",
"price_liq",
"leverage",
"flag",
"position_id",
"mts_create",
"mts_update",
"_PLACEHOLDER",
"type",
"_PLACEHOLDER",
"collateral",
"collateral_min",
"meta"
]
)
Trade = generate_labeler_serializer(
name="Trade",
klass=types.Trade,
labels=[
"id",
"symbol",
"mts_create",
"order_id",
"exec_amount",
"exec_price",
"order_type",
"order_price",
"maker",
"fee",
"fee_currency",
"cid"
]
)
FundingOffer = generate_labeler_serializer(
name="FundingOffer",
klass=types.FundingOffer,
labels=[
"id",
"symbol",
"mts_create",
"mts_update",
"amount",
"amount_orig",
"offer_type",
"_PLACEHOLDER",
"_PLACEHOLDER",
"flags",
"offer_status",
"_PLACEHOLDER",
"_PLACEHOLDER",
"_PLACEHOLDER",
"rate",
"period",
"notify",
"hidden",
"_PLACEHOLDER",
"renew",
"_PLACEHOLDER"
]
)
FundingCredit = generate_labeler_serializer(
name="FundingCredit",
klass=types.FundingCredit,
labels=[
"id",
"symbol",
"side",
"mts_create",
"mts_update",
"amount",
"flags",
"status",
"_PLACEHOLDER",
"_PLACEHOLDER",
"_PLACEHOLDER",
"rate",
"period",
"mts_opening",
"mts_last_payout",
"notify",
"hidden",
"_PLACEHOLDER",
"renew",
"_PLACEHOLDER",
"no_close",
"position_pair"
]
)
FundingLoan = generate_labeler_serializer(
name="FundingLoan",
klass=types.FundingLoan,
labels=[
"id",
"symbol",
"side",
"mts_create",
"mts_update",
"amount",
"flags",
"status",
"_PLACEHOLDER",
"_PLACEHOLDER",
"_PLACEHOLDER",
"rate",
"period",
"mts_opening",
"mts_last_payout",
"notify",
"hidden",
"_PLACEHOLDER",
"renew",
"_PLACEHOLDER",
"no_close"
]
)
Wallet = generate_labeler_serializer(
name="Wallet",
klass=types.Wallet,
labels=[
"wallet_type",
"currency",
"balance",
"unsettled_interest",
"available_balance",
"last_change",
"trade_details"
]
)
Balance = generate_labeler_serializer(
name="Balance",
klass=types.Balance,
labels=[
"aum",
"aum_net"
]
)
#endregion

View File

@@ -1,247 +0,0 @@
#pylint: disable=duplicate-code
#pylint: disable-next=wildcard-import,unused-wildcard-import
from typing import *
from dataclasses import dataclass
from .. labeler import _Type
#pylint: disable-next=unused-import
from .. notification import Notification
from ..utils.json_encoder import JSON
#region Type hinting for WebSocket Public Channels
@dataclass
class TradingPairTicker(_Type):
bid: float
bid_size: float
ask: float
ask_size: float
daily_change: float
daily_change_relative: float
last_price: float
volume: float
high: float
low: float
@dataclass
class FundingCurrencyTicker(_Type):
frr: float
bid: float
bid_period: int
bid_size: float
ask: float
ask_period: int
ask_size: float
daily_change: float
daily_change_relative: float
last_price: float
volume: float
high: float
low: float
frr_amount_available: float
@dataclass
class TradingPairTrade(_Type):
id: int
mts: int
amount: float
price: float
@dataclass
class FundingCurrencyTrade(_Type):
id: int
mts: int
amount: float
rate: float
period: int
@dataclass
class TradingPairBook(_Type):
price: float
count: int
amount: float
@dataclass
class FundingCurrencyBook(_Type):
rate: float
period: int
count: int
amount: float
@dataclass
class TradingPairRawBook(_Type):
order_id: int
price: float
amount: float
@dataclass
class FundingCurrencyRawBook(_Type):
offer_id: int
period: int
rate: float
amount: float
@dataclass
class Candle(_Type):
mts: int
open: int
close: int
high: int
low: int
volume: float
@dataclass
class DerivativesStatus(_Type):
mts: int
deriv_price: float
spot_price: float
insurance_fund_balance: float
next_funding_evt_mts: int
next_funding_accrued: float
next_funding_step: int
current_funding: float
mark_price: float
open_interest: float
clamp_min: float
clamp_max: float
#endregion
#region Type hinting for WebSocket Authenticated Channels
@dataclass
class Order(_Type):
id: int
gid: int
cid: int
symbol: str
mts_create: int
mts_update: int
amount: float
amount_orig: float
order_type: str
type_prev: str
mts_tif: int
flags: int
order_status: str
price: float
price_avg: float
price_trailing: float
price_aux_limit: float
notify: int
hidden: int
placed_id: int
routing: str
meta: JSON
@dataclass
class Position(_Type):
symbol: str
status: str
amount: float
base_price: float
margin_funding: float
margin_funding_type: int
pl: float
pl_perc: float
price_liq: float
leverage: float
flag: int
position_id: int
mts_create: int
mts_update: int
type: int
collateral: float
collateral_min: float
meta: JSON
@dataclass
class Trade(_Type):
id: int
symbol: str
mts_create: int
order_id: int
exec_amount: float
exec_price: float
order_type: str
order_price: float
maker:int
fee: Optional[float]
fee_currency: Optional[str]
cid: int
@dataclass
class FundingOffer(_Type):
id: int
symbol: str
mts_create: int
mts_update: int
amount: float
amount_orig: float
offer_type: str
flags: int
offer_status: str
rate: float
period: int
notify: int
hidden: int
renew: int
@dataclass
class FundingCredit(_Type):
id: int
symbol: str
side: int
mts_create: int
mts_update: int
amount: float
flags: int
status: str
rate: float
period: int
mts_opening: int
mts_last_payout: int
notify: int
hidden: int
renew: int
no_close: int
position_pair: str
@dataclass
class FundingLoan(_Type):
id: int
symbol: str
side: int
mts_create: int
mts_update: int
amount: float
flags: int
status: str
rate: float
period: int
mts_opening: int
mts_last_payout: int
notify: int
hidden: int
renew: int
no_close: int
@dataclass
class Wallet(_Type):
wallet_type: str
currency: str
balance: float
unsettled_interest: float
available_balance: float
last_change: str
trade_details: JSON
@dataclass
class Balance(_Type):
aum: float
aum_net: float
#endregion

View File

@@ -4,7 +4,7 @@ import os
from bfxapi import Client, REST_HOST
from bfxapi.rest.types import Notification, PositionClaim
from bfxapi.types import Notification, PositionClaim
bfx = Client(
rest_host=REST_HOST,

View File

@@ -2,11 +2,12 @@
import os
from typing import List
from bfxapi import Client, REST_HOST
from bfxapi.rest.types import List, Wallet, Transfer, \
DepositAddress, LightningNetworkInvoice, Withdrawal, \
Notification
from bfxapi.types import Wallet, Transfer, DepositAddress, \
LightningNetworkInvoice, Withdrawal, Notification
bfx = Client(
rest_host=REST_HOST,

View File

@@ -4,7 +4,7 @@ import os
from bfxapi import Client, REST_HOST
from bfxapi.rest.types import DerivativePositionCollateral, DerivativePositionCollateralLimits
from bfxapi.types import DerivativePositionCollateral, DerivativePositionCollateralLimits
bfx = Client(
rest_host=REST_HOST,

View File

@@ -3,8 +3,8 @@
import os
from bfxapi import Client, REST_HOST
from bfxapi.types import Notification, FundingOffer
from bfxapi.enums import FundingOfferType, Flag
from bfxapi.rest.types import Notification, FundingOffer
bfx = Client(
rest_host=REST_HOST,

View File

@@ -3,8 +3,8 @@
import os
from bfxapi import Client, REST_HOST
from bfxapi.types import Notification, Order
from bfxapi.enums import OrderType, Flag
from bfxapi.rest.types import Notification, Order
bfx = Client(
rest_host=REST_HOST,

View File

@@ -2,9 +2,11 @@
import os
from typing import List
from bfxapi import Client, REST_HOST
from bfxapi.rest.types import List, FundingLoan, Notification
from bfxapi.types import FundingLoan, Notification
bfx = Client(
rest_host=REST_HOST,

View File

@@ -4,7 +4,7 @@ import os
from bfxapi import Client, REST_HOST
from bfxapi.rest.types import InvoiceSubmission
from bfxapi.types import InvoiceSubmission
bfx = Client(
rest_host=REST_HOST,

View File

@@ -1,8 +1,10 @@
# python -c "import examples.rest.public.book"
from typing import List
from bfxapi import Client, PUB_REST_HOST
from bfxapi.rest.types import List, TradingPairBook, TradingPairRawBook, \
from bfxapi.types import TradingPairBook, TradingPairRawBook, \
FundingCurrencyBook, FundingCurrencyRawBook
bfx = Client(rest_host=PUB_REST_HOST)

View File

@@ -2,9 +2,11 @@
import datetime
from typing import List
from bfxapi import Client, PUB_REST_HOST
from bfxapi.rest.types import List, PulseMessage, PulseProfile
from bfxapi.types import PulseMessage, PulseProfile
bfx = Client(rest_host=PUB_REST_HOST)

View File

@@ -2,7 +2,7 @@
from bfxapi import Client, PUB_REST_HOST
from bfxapi.rest.types import TradingMarketAveragePrice, FundingMarketAveragePrice, FxRate
from bfxapi.types import TradingMarketAveragePrice, FundingMarketAveragePrice, FxRate
bfx = Client(rest_host=PUB_REST_HOST)

View File

@@ -1,8 +1,10 @@
# python -c "import examples.rest.public.trades"
from typing import List
from bfxapi import Client, PUB_REST_HOST
from bfxapi.types import TradingPairTrade, FundingCurrencyTrade
from bfxapi.rest.enums import Sort
from bfxapi.rest.types import List, TradingPairTrade, FundingCurrencyTrade
bfx = Client(rest_host=PUB_REST_HOST)

View File

@@ -4,7 +4,7 @@ import os
from bfxapi import Client, WSS_HOST
from bfxapi.enums import Error, OrderType
from bfxapi.websocket.types import Notification, Order
from bfxapi.types import Notification, Order
bfx = Client(
wss_host=WSS_HOST,

View File

@@ -4,7 +4,7 @@ import os
from bfxapi import Client
from bfxapi.enums import Error
from bfxapi.websocket.types import List, Wallet
from bfxapi.types import List, Wallet
bfx = Client(
api_key=os.getenv("BFX_API_KEY"),

View File

@@ -1,15 +1,15 @@
# python -c "import examples.websocket.public.derivatives_status"
from bfxapi import Client, PUB_WSS_HOST
from bfxapi.websocket.enums import Error, Channel
from bfxapi.websocket.types import DerivativesStatus
from bfxapi.types import DerivativesStatus
from bfxapi.websocket.subscriptions import Status
from bfxapi.websocket import subscriptions
from bfxapi.websocket.enums import Error, Channel
bfx = Client(wss_host=PUB_WSS_HOST)
@bfx.wss.on("derivatives_status_update")
def on_derivatives_status_update(subscription: subscriptions.Status, data: DerivativesStatus):
def on_derivatives_status_update(subscription: Status, data: DerivativesStatus):
print(f"{subscription}:", data)
@bfx.wss.on("wss-error")

View File

@@ -6,9 +6,9 @@ from typing import List
from bfxapi import Client, PUB_WSS_HOST
from bfxapi.websocket import subscriptions
from bfxapi.types import TradingPairBook
from bfxapi.websocket.subscriptions import Book
from bfxapi.websocket.enums import Channel, Error
from bfxapi.websocket.types import TradingPairBook
class OrderBook:
def __init__(self, symbols: List[str]):
@@ -54,12 +54,12 @@ def on_subscribed(subscription):
print(f"Subscription successful for pair <{subscription['pair']}>")
@bfx.wss.on("t_book_snapshot")
def on_t_book_snapshot(subscription: subscriptions.Book, snapshot: List[TradingPairBook]):
def on_t_book_snapshot(subscription: Book, snapshot: List[TradingPairBook]):
for data in snapshot:
order_book.update(subscription["symbol"], data)
@bfx.wss.on("t_book_update")
def on_t_book_update(subscription: subscriptions.Book, data: TradingPairBook):
def on_t_book_update(subscription: Book, data: TradingPairBook):
order_book.update(subscription["symbol"], data)
bfx.wss.run()

View File

@@ -6,9 +6,9 @@ from typing import List
from bfxapi import Client, PUB_WSS_HOST
from bfxapi.websocket import subscriptions
from bfxapi.types import TradingPairRawBook
from bfxapi.websocket.subscriptions import Book
from bfxapi.websocket.enums import Channel, Error
from bfxapi.websocket.types import TradingPairRawBook
class RawOrderBook:
def __init__(self, symbols: List[str]):
@@ -54,12 +54,12 @@ def on_subscribed(subscription):
print(f"Subscription successful for pair <{subscription['pair']}>")
@bfx.wss.on("t_raw_book_snapshot")
def on_t_raw_book_snapshot(subscription: subscriptions.Book, snapshot: List[TradingPairRawBook]):
def on_t_raw_book_snapshot(subscription: Book, snapshot: List[TradingPairRawBook]):
for data in snapshot:
raw_order_book.update(subscription["symbol"], data)
@bfx.wss.on("t_raw_book_update")
def on_t_raw_book_update(subscription: subscriptions.Book, data: TradingPairRawBook):
def on_t_raw_book_update(subscription: Book, data: TradingPairRawBook):
raw_order_book.update(subscription["symbol"], data)
bfx.wss.run()

View File

@@ -2,14 +2,14 @@
from bfxapi import Client, PUB_WSS_HOST
from bfxapi.websocket import subscriptions
from bfxapi.types import TradingPairTicker
from bfxapi.websocket.subscriptions import Ticker
from bfxapi.websocket.enums import Channel
from bfxapi.websocket.types import TradingPairTicker
bfx = Client(wss_host=PUB_WSS_HOST)
@bfx.wss.on("t_ticker_update")
def on_t_ticker_update(subscription: subscriptions.Ticker, data: TradingPairTicker):
def on_t_ticker_update(subscription: Ticker, data: TradingPairTicker):
print(f"Subscription with subId: {subscription['subId']}")
print(f"Data: {data}")

View File

@@ -1,19 +1,19 @@
# python -c "import examples.websocket.public.trades"
from bfxapi import Client, PUB_WSS_HOST
from bfxapi.websocket.enums import Error, Channel
from bfxapi.websocket.types import Candle, TradingPairTrade
from bfxapi.websocket import subscriptions
from bfxapi.types import Candle, TradingPairTrade
from bfxapi.websocket.subscriptions import Candles, Trades
from bfxapi.websocket.enums import Error, Channel
bfx = Client(wss_host=PUB_WSS_HOST)
@bfx.wss.on("candles_update")
def on_candles_update(_sub: subscriptions.Candles, candle: Candle):
def on_candles_update(_sub: Candles, candle: Candle):
print(f"New candle: {candle}")
@bfx.wss.on("t_trade_execution")
def on_t_trade_execution(_sub: subscriptions.Trades, trade: TradingPairTrade):
def on_t_trade_execution(_sub: Trades, trade: TradingPairTrade):
print(f"New trade: {trade}")
@bfx.wss.on("wss-error")

View File

@@ -32,7 +32,7 @@ setup(
"Source": "https://github.com/bitfinexcom/bitfinex-api-py",
},
packages=[
"bfxapi", "bfxapi.utils",
"bfxapi", "bfxapi.utils", "bfxapi.types",
"bfxapi.websocket", "bfxapi.websocket.client", "bfxapi.websocket.handlers",
"bfxapi.rest", "bfxapi.rest.endpoints", "bfxapi.rest.middleware",
],