Add bfxapi/enums.py file. Split enumerations in bfxapi/rest/enums.py and bfxapi/websocket/enums.py. Rename enumeration classes to use singular name identifiers.

This commit is contained in:
Davide Casale
2022-12-22 18:42:55 +01:00
parent 4f63f4068e
commit 454a7542ed
6 changed files with 55 additions and 54 deletions

42
bfxapi/enums.py Normal file
View File

@@ -0,0 +1,42 @@
from enum import Enum
class OrderType(str, Enum):
LIMIT = "LIMIT"
EXCHANGE_LIMIT = "EXCHANGE LIMIT"
MARKET = "MARKET"
EXCHANGE_MARKET = "EXCHANGE MARKET"
STOP = "STOP"
EXCHANGE_STOP = "EXCHANGE STOP"
STOP_LIMIT = "STOP LIMIT"
EXCHANGE_STOP_LIMIT = "EXCHANGE STOP LIMIT"
TRAILING_STOP = "TRAILING STOP"
EXCHANGE_TRAILING_STOP = "EXCHANGE TRAILING STOP"
FOK = "FOK"
EXCHANGE_FOK = "EXCHANGE FOK"
IOC = "IOC"
EXCHANGE_IOC = "EXCHANGE IOC"
class Flag(int, Enum):
HIDDEN = 64
CLOSE = 512
REDUCE_ONLY = 1024
POST_ONLY = 4096
OCO = 16384
NO_VAR_RATES = 524288
class Error(int, Enum):
ERR_UNK = 10000
ERR_GENERIC = 10001
ERR_CONCURRENCY = 10008
ERR_PARAMS = 10020
ERR_CONF_FAIL = 10050
ERR_AUTH_FAIL = 10100
ERR_AUTH_PAYLOAD = 10111
ERR_AUTH_SIG = 10112
ERR_AUTH_HMAC = 10113
ERR_AUTH_NONCE = 10114
ERR_UNAUTH_FAIL = 10200
ERR_SUB_FAIL = 10300
ERR_SUB_MULTI = 10301
ERR_UNSUB_FAIL = 10400
ERR_READY = 11000

View File

@@ -9,7 +9,7 @@ from typing import List, Union, Literal, Optional, Any, cast
from . import serializers
from .typings import *
from .enums import OrderType, Config, Precision, Sort
from .enums import Config, Precision, Sort, OrderType, Error
from .exceptions import ResourceNotFound, RequestParametersError, InvalidAuthenticationCredentials, UnknownGenericError
from .. utils.integers import Int16, Int32, Int45, Int64
@@ -50,10 +50,10 @@ class _Requests(object):
data = response.json()
if len(data) and data[0] == "error":
if data[1] == 10020:
if data[1] == Error.ERR_PARAMS:
raise RequestParametersError(f"The request was rejected with the following parameter error: <{data[2]}>")
if data[1] == None or data[1] == 10000 or data[1] == 10001:
if data[1] == None or data[1] == Error.ERR_UNK or data[1] == Error.ERR_GENERIC:
raise UnknownGenericError("The server replied to the request with a generic error with message: <{data[2]}>.")
return data
@@ -72,13 +72,13 @@ class _Requests(object):
data = response.json()
if len(data) and data[0] == "error":
if data[1] == 10020:
if data[1] == Error.ERR_PARAMS:
raise RequestParametersError(f"The request was rejected with the following parameter error: <{data[2]}>")
if data[1] == 10100:
if data[1] == Error.ERR_AUTH_FAIL:
raise InvalidAuthenticationCredentials("Cannot authenticate with given API-KEY and API-SECRET.")
if data[1] == None or data[1] == 10000 or data[1] == 10001:
if data[1] == None or data[1] == Error.ERR_UNK or data[1] == Error.ERR_GENERIC:
raise UnknownGenericError(f"The server replied to the request with a generic error with message: <{data[2]}>.")
return data

View File

@@ -1,20 +1,4 @@
from enum import Enum
class OrderType(str, Enum):
LIMIT = "LIMIT"
EXCHANGE_LIMIT = "EXCHANGE LIMIT"
MARKET = "MARKET"
EXCHANGE_MARKET = "EXCHANGE MARKET"
STOP = "STOP"
EXCHANGE_STOP = "EXCHANGE STOP"
STOP_LIMIT = "STOP LIMIT"
EXCHANGE_STOP_LIMIT = "EXCHANGE STOP LIMIT"
TRAILING_STOP = "TRAILING STOP"
EXCHANGE_TRAILING_STOP = "EXCHANGE TRAILING STOP"
FOK = "FOK"
EXCHANGE_FOK = "EXCHANGE FOK"
IOC = "IOC"
EXCHANGE_IOC = "EXCHANGE IOC"
from ..enums import *
class Config(str, Enum):
MAP_CURRENCY_SYM = "pub:map:currency:sym"

View File

@@ -1,33 +1,8 @@
from enum import Enum
from ..enums import *
class Channels(str, Enum):
TICKER = "ticker"
TRADES = "trades"
BOOK = "book"
CANDLES = "candles"
STATUS = "status"
class Flags(int, Enum):
HIDDEN = 64
CLOSE = 512
REDUCE_ONLY = 1024
POST_ONLY = 4096
OCO = 16384
NO_VAR_RATES = 524288
class Errors(int, Enum):
ERR_UNK = 10000
ERR_GENERIC = 10001
ERR_CONCURRENCY = 10008
ERR_PARAMS = 10020
ERR_CONF_FAIL = 10050
ERR_AUTH_FAIL = 10100
ERR_AUTH_PAYLOAD = 10111
ERR_AUTH_SIG = 10112
ERR_AUTH_HMAC = 10113
ERR_AUTH_NONCE = 10114
ERR_UNAUTH_FAIL = 10200
ERR_SUB_FAIL = 10300
ERR_SUB_MULTI = 10301
ERR_UNSUB_FAIL = 10400
ERR_READY = 11000
STATUS = "status"