core/bfxbot/currency.py

68 lines
1.4 KiB
Python

import re
from enum import Enum
class BalanceKind(Enum):
EXCHANGE = "exchange",
MARGIN = "margin"
@staticmethod
def from_str(string: str):
string = string.lower()
if "margin" in string:
return BalanceKind.MARGIN
if "exchange" in string:
return BalanceKind.EXCHANGE
return None
class Balance:
def __init__(self, currency: str, amount: int, kind: BalanceKind, quote: str, quote_equivalent: float):
self.currency: str = currency
self.amount: int = amount
self.kind: BalanceKind = kind
self.quote: str = quote
self.quote_equivalent: float = quote_equivalent
class Direction(Enum):
UP = 1,
DOWN = -1
class OrderType(Enum):
EXCHANGE = "EXCHANGE",
MARGIN = "MARGIN"
class Symbol(Enum):
XMR = "XMR"
BTC = "BTC"
ETH = "ETH"
def __repr__(self):
return f"t{self.value}USD"
def __str__(self):
return self.__repr__()
@staticmethod
def from_str(string: str):
match = re.compile("t([a-zA-Z]+)USD").match(string)
if not match:
raise ValueError
currency = match.group(1).lower()
if currency in ("xmr"):
return Symbol.XMR
elif currency in ("btc"):
return Symbol.BTC
elif currency in ("eth"):
return Symbol.ETH
else:
return NotImplementedError