Skip to content
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
executable file 198 lines (151 sloc) 6.81 KB
from decimal import Decimal
import pandas as pd
from typing import (
from hummingbot.core.data_type.cancellation_result import CancellationResult
from import (
from hummingbot.core.event.event_logger import EventLogger
from hummingbot.core.data_type.limit_order import LimitOrder
from hummingbot.core.network_iterator import NetworkIterator
from hummingbot.core.data_type.order_book import OrderBook
from .deposit_info import DepositInfo
NaN = float("nan")
cdef class MarketBase(NetworkIterator):
def __init__(self):
self.event_reporter = EventReporter(
self.event_logger = EventLogger(
for event_tag in self.MARKET_EVENTS:
self.c_add_listener(event_tag.value, self.event_reporter)
self.c_add_listener(event_tag.value, self.event_logger)
def split_symbol(symbol: str) -> Tuple[str, str]:
return tuple(symbol.split('-'))
except Exception:
raise ValueError(f"Error parsing symbol {symbol}")
def status_dict(self) -> Dict[str, bool]:
return {}
def name(self) -> str:
return self.__class__.__name__
def event_logs(self) -> List[any]:
return self.event_logger.event_log
def order_books(self) -> Dict[str, OrderBook]:
raise NotImplementedError
def ready(self) -> bool:
raise NotImplementedError
def limit_orders(self) -> List[LimitOrder]:
raise NotImplementedError
def tracking_states(self) -> Dict[str, any]:
return {}
def restore_tracking_states(self, saved_states: Dict[str, any]):
Restores the tracking states from a previously saved state.
:param saved_states: Previously saved tracking states from `tracking_states` property.
async def get_active_exchange_markets(self) -> pd.DataFrame:
:return: data frame with symbol as index, and at least the following columns --
["baseAsset", "quoteAsset", "volume", "USDVolume"]
raise NotImplementedError
def get_balance(self, currency: str) -> float:
return self.c_get_balance(currency)
def get_available_balance(self, currency: str) -> float:
return self.c_get_available_balance(currency)
def get_all_balances(self) -> Dict[str, float]:
raise NotImplementedError
def get_price(self, symbol: str, is_buy: bool) -> float:
return self.c_get_price(symbol, is_buy)
def withdraw(self, address: str, currency: str, amount: float) -> str:
return self.c_withdraw(address, currency, amount)
async def get_deposit_info(self, asset: str) -> DepositInfo:
raise NotImplementedError
def get_order_book(self, symbol: str) -> OrderBook:
return self.c_get_order_book(symbol)
def buy(self, symbol: str, amount: float, order_type = OrderType.MARKET, price: float = 0.0, **kwargs) -> str:
return self.c_buy(symbol, amount, order_type, price, kwargs)
def sell(self, symbol: str, amount: float, order_type = OrderType.MARKET, price: float = 0.0, **kwargs) -> str:
return self.c_sell(symbol, amount, order_type, price, kwargs)
def cancel(self, symbol: str, client_order_id: str):
return self.c_cancel(symbol, client_order_id)
async def cancel_all(self, timeout_seconds: float) -> List[CancellationResult]:
raise NotImplementedError
def get_fee(self,
base_currency: str,
quote_currency: str,
order_type: OrderType,
order_side: TradeType,
amount: float,
price: float = NaN) -> TradeFee:
return self.c_get_fee(base_currency, quote_currency, order_type, order_side, amount, price)
def get_order_price_quantum(self, symbol: str, price: float) -> Decimal:
return self.c_get_order_price_quantum(symbol, price)
def get_order_size_quantum(self, symbol: str, order_size: float) -> Decimal:
return self.c_get_order_size_quantum(symbol, order_size)
def quantize_order_price(self, symbol: str, price: float) -> Decimal:
return self.c_quantize_order_price(symbol, price)
def quantize_order_amount(self, symbol: str, amount: float) -> Decimal:
return self.c_quantize_order_amount(symbol, amount)
cdef str c_buy(self, str symbol, double amount, object order_type = OrderType.MARKET, double price = 0.0, dict kwargs = {}):
raise NotImplementedError
cdef str c_sell(self, str symbol, double amount, object order_type = OrderType.MARKET, double price = 0.0, dict kwargs = {}):
raise NotImplementedError
cdef c_cancel(self, str symbol, str client_order_id):
raise NotImplementedError
cdef object c_get_fee(self,
str base_currency,
str quote_currency,
object order_type,
object order_side,
double amount,
double price):
raise NotImplementedError
cdef double c_get_balance(self, str currency) except? -1:
raise NotImplementedError
cdef double c_get_available_balance(self, str currency) except? -1:
raise NotImplementedError
cdef str c_withdraw(self, str address, str currency, double amount):
raise NotImplementedError
cdef OrderBook c_get_order_book(self, str symbol):
raise NotImplementedError
cdef double c_get_price(self, str symbol, bint is_buy) except? -1:
raise NotImplementedError
cdef object c_get_order_price_quantum(self, str symbol, double price):
raise NotImplementedError
cdef object c_get_order_size_quantum(self, str symbol, double order_size):
raise NotImplementedError
cdef object c_quantize_order_price(self, str symbol, double price):
price_quantum = self.c_get_order_price_quantum(symbol, price)
return round(Decimal(price) / price_quantum) * price_quantum
cdef object c_quantize_order_amount(self, str symbol, double amount, double price = 0.0):
order_size_quantum = self.c_get_order_size_quantum(symbol, amount)
return (Decimal(amount) // order_size_quantum) * order_size_quantum
You can’t perform that action at this time.