Documentation Index
Fetch the complete documentation index at: https://mintlify.com/hummingbot/hummingbot/llms.txt
Use this file to discover all available pages before exploring further.
ConnectorBase is the abstract base class that all Hummingbot exchange connectors extend. It provides the fundamental interface for trading operations, balance management, and order execution.
Class Definition
class ConnectorBase(NetworkIterator):
def __init__(self, balance_asset_limit: Optional[Dict[str, Dict[str, Decimal]]] = None):
super().__init__()
self._account_balances = {} # Dict[asset_name:str, Decimal]
self._account_available_balances = {} # Dict[asset_name:str, Decimal]
Core Properties
Returns the connector name (typically the class name).
Returns the display name for the connector (defaults to name).
Indicates whether the connector is ready to be used. Must be implemented by subclasses.
A dictionary of statuses of various connector components. Must be implemented by subclasses.
in_flight_orders
Dict[str, InFlightOrderBase]
Returns a dictionary of all in-flight orders tracked by this connector. Must be implemented by subclasses.
Returns a list of all events logged by this connector.
Returns the available balance for all assets.
Flag indicating whether the connector provides real-time balance updates.
Balance Management
get_balance
def get_balance(self, currency: str) -> Decimal:
"""
Returns the total balance for the given currency.
"""
The currency (token) name to get balance for.
Total balance for the given currency.
get_available_balance
def get_available_balance(self, currency: str) -> Decimal:
"""
Returns available balance for trading. Accounts for in-flight orders and
applies balance limits if configured.
"""
The currency (token) name.
Available balance for trading for the specified currency.
get_all_balances
def get_all_balances(self) -> Dict[str, Decimal]:
"""
Returns total balances of all assets.
"""
Dictionary mapping asset names to total balances.
Order Execution
buy
def buy(
self,
trading_pair: str,
amount: Decimal,
order_type: OrderType,
price: Decimal,
**kwargs
) -> str:
"""
Buys an amount of base asset (of the given trading pair).
"""
The market (e.g. BTC-USDT) to buy from.
The amount in base token value.
The order type (MARKET or LIMIT).
Additional parameters (e.g., expiration_ts, position_action).
The order ID (client_order_id) of the created buy order.
sell
def sell(
self,
trading_pair: str,
amount: Decimal,
order_type: OrderType,
price: Decimal,
**kwargs
) -> str:
"""
Sells an amount of base asset (of the given trading pair).
"""
Same parameters as buy, but executes a sell order.
The order ID (client_order_id) of the created sell order.
cancel
def cancel(self, trading_pair: str, client_order_id: str):
"""
Cancels an order.
"""
The market (e.g. BTC-USDT) of the order.
cancel_all
async def cancel_all(self, timeout_seconds: float) -> List[CancellationResult]:
"""
Cancels all in-flight orders and waits for cancellation results.
"""
The timeout at which the operation will be canceled.
List of CancellationResult indicating whether each order was successfully canceled.
Batch Operations
batch_order_create
def batch_order_create(
self,
orders_to_create: List[Union[LimitOrder, MarketOrder]]
) -> List[Union[LimitOrder, MarketOrder]]:
"""
Issues a batch order creation as a single API request for exchanges that
implement this feature. The default implementation sends requests one by one.
"""
orders_to_create
List[Union[LimitOrder, MarketOrder]]
List of LimitOrder or MarketOrder objects representing orders to create.
return
List[Union[LimitOrder, MarketOrder]]
List of created orders complete with generated order IDs.
batch_order_cancel
def batch_order_cancel(self, orders_to_cancel: List[LimitOrder]):
"""
Issues a batch order cancelation as a single API request for exchanges that
implement this feature. The default implementation sends requests one by one.
"""
List of orders to cancel.
Price and Trading Rules
get_price
def get_price(self, trading_pair: str, is_buy: bool, amount: Decimal = s_decimal_NaN) -> Decimal:
"""
Gets the price for the market trading pair.
"""
Whether to get buy price (True) or sell price (False).
The price for the trading pair.
get_order_price_quantum
def get_order_price_quantum(self, trading_pair: str, price: Decimal) -> Decimal:
"""
Returns a price step, the minimum price increment for a given trading pair.
"""
The minimum price increment.
get_order_size_quantum
def get_order_size_quantum(self, trading_pair: str, order_size: Decimal) -> Decimal:
"""
Returns an order amount step, the minimum amount increment for a given trading pair.
"""
The minimum amount increment.
quantize_order_price
def quantize_order_price(self, trading_pair: str, price: Decimal) -> Decimal:
"""
Applies trading rule to quantize order price.
"""
The quantized price that conforms to exchange rules.
quantize_order_amount
def quantize_order_amount(self, trading_pair: str, amount: Decimal) -> Decimal:
"""
Applies trading rule to quantize order amount.
"""
The quantized amount that conforms to exchange rules.
Async Methods
get_quote_price
async def get_quote_price(
self,
trading_pair: str,
is_buy: bool,
amount: Decimal
) -> Decimal:
"""
Returns a quote price (or exchange rate) for a given amount.
"""
True for buy order, False for sell order.
get_order_price
async def get_order_price(
self,
trading_pair: str,
is_buy: bool,
amount: Decimal
) -> Decimal:
"""
Returns the price required for order submission. This price could differ
from the quote price (e.g. for an exchange with order book).
"""
Same parameters as get_quote_price.
The price to specify in an order.
all_trading_pairs
async def all_trading_pairs(self) -> List[str]:
"""
List of all trading pairs supported by the connector.
"""
List of trading pair symbols in the Hummingbot format.
Balance Calculations
in_flight_asset_balances
def in_flight_asset_balances(
self,
in_flight_orders: Dict[str, InFlightOrderBase]
) -> Dict[str, Decimal]:
"""
Calculates total asset balances locked in in_flight_orders including fee (estimated).
For BUY orders: quote asset balance locked.
For SELL orders: base asset balance locked.
"""
in_flight_orders
Dict[str, InFlightOrderBase]
Dictionary of in-flight orders.
Dictionary of tokens and their balance locked in orders.
order_filled_balances
def order_filled_balances(self, starting_timestamp: float = 0) -> Dict[str, Decimal]:
"""
Calculates total asset balance changes from filled orders since the timestamp.
"""
The starting timestamp to filter order filled events.
Dictionary of tokens and their balance changes.
estimate_fee_pct
def estimate_fee_pct(self, is_maker: bool) -> Decimal:
"""
Estimates the trading fee for maker or taker type of order.
"""
Whether to get trading fee for maker (True) or taker (False) order.
An estimated fee in percentage value.
Lifecycle Methods
start
def start(self, clock: Clock, timestamp: float):
"""
Starts the connector with the given clock.
"""
tick
def tick(self, timestamp: float):
"""
Called automatically by the clock for each tick (1 second by default).
"""
stop_tracking_order
def stop_tracking_order(self, order_id: str):
"""
Stops tracking an in-flight order.
"""
Utility Methods
split_trading_pair
@staticmethod
def split_trading_pair(trading_pair: str) -> Tuple[str, str]:
"""
Splits a trading pair into base and quote assets.
"""
The trading pair to split (e.g., “BTC-USDT”).
Tuple of (base_asset, quote_asset).
Usage Example
from hummingbot.connector.connector_base import ConnectorBase
from decimal import Decimal
from hummingbot.core.data_type.common import OrderType
class MyExchangeConnector(ConnectorBase):
@property
def ready(self) -> bool:
return self._trading_pairs_ready and self._account_balances_ready
@property
def status_dict(self) -> Dict[str, bool]:
return {
"trading_pairs_initialized": self._trading_pairs_ready,
"account_balances_initialized": self._account_balances_ready,
}
def buy(self, trading_pair: str, amount: Decimal,
order_type: OrderType, price: Decimal, **kwargs) -> str:
# Implement buy order logic
order_id = self._create_order(trading_pair, True, amount, order_type, price)
return order_id
def sell(self, trading_pair: str, amount: Decimal,
order_type: OrderType, price: Decimal, **kwargs) -> str:
# Implement sell order logic
order_id = self._create_order(trading_pair, False, amount, order_type, price)
return order_id
Market Events
The connector emits the following market events:
ReceivedAsset
BuyOrderCompleted
SellOrderCompleted
WithdrawAsset
OrderCancelled
OrderFilled
OrderExpired
OrderFailure
TransactionFailure
BuyOrderCreated
SellOrderCreated
FundingPaymentCompleted
RangePositionLiquidityAdded
RangePositionLiquidityRemoved
RangePositionUpdateFailure