rubi client
Client
- class rubi.client.Client(network: Network, message_queue: Queue | None = None, wallet: eth_typing.ChecksumAddress | str | None = None, key: str | None = None)
Bases:
objectThis class is a client for Rubicon. It aims to provide a simple and understandable interface when interacting with the Rubicon protocol. If not instantiated with a wallet and key then all the methods that require signing will throw an error.
- Parameters:
network (Network) – A Network instance
message_queue (Optional[Queue]) – Optional message queue for processing events (optional, default is None).
wallet (Optional[ChecksumAddress]) – Wallet address (optional, default is None).
key (Optional[str]) – Key for the wallet (optional, default is None).
- add_pair(pair_name: str, base_asset_allowance: Decimal | None = None, quote_asset_allowance: Decimal | None = None) None
Add a Pair to the Client. This method creates a Pair instance and adds it to the Client’s internal _pairs dictionary. Additionally, this method updates the spender allowance of the Rubicon Market for both base asset and the quote asset.
- Parameters:
pair_name (str) – Name of the Pair in the format “<base_asset>/<quote_asset>”.
base_asset_allowance (Optional[Decimal]) – Allowance for the base asset (optional, default is None).
quote_asset_allowance (Optional[Decimal]) – Allowance for the quote asset (optional, default is None).
- batch_cancel_limit_orders(transaction: Transaction) TransactionReceipt
Cancel multiple limit orders in a batch transaction.
- Parameters:
transaction (Transaction) – Transaction object containing multiple limit order cancellations.
- Returns:
The transaction hash of the executed batch limit order cancellations.
- Return type:
str
- batch_place_limit_orders(transaction: Transaction) TransactionReceipt
Place multiple limit orders in a batch transaction.
- Parameters:
transaction (Transaction) – Transaction object containing multiple limit orders.
- Returns:
The transaction hash of the executed batch limit orders.
- Return type:
str
- batch_update_limit_orders(transaction: Transaction) TransactionReceipt
Update multiple limit orders in a batch transaction.
- Parameters:
transaction (Transaction) – Transaction object containing multiple limit order updates.
- Returns:
The transaction hash of the executed batch limit order updates.
- Return type:
str
- cancel_limit_order(transaction: Transaction) TransactionReceipt
Place a limit order cancel transaction by executing the specified transaction object. The transaction object should contain a single order of type NewCancelOrder.
- Parameters:
transaction (Transaction) – Transaction object containing the cancel order.
- Returns:
The transaction hash of the executed cancel order.
- Return type:
str
- Raises:
Exception – If the transaction contains more than one order.
- classmethod from_http_node_url(http_node_url: str, custom_token_addresses_file: str | None = None, message_queue: Queue | None = None, wallet: eth_typing.ChecksumAddress | str | None = None, key: str | None = None)
Initialize a Client using a http_node_url.
- Parameters:
http_node_url (str) – URL of the HTTP node.
custom_token_addresses_file (Optional[str]) – The name of a yaml file (relative to the current working directory) with custom token addresses. Overwrites the token config found in network_config/{chain}/network.yaml. (optional, default is None).
message_queue (Optional[Queue]) – Optional message queue for processing events (optional, default is None).
wallet (Optional[Union[ChecksumAddress, str]]) – Wallet address (optional, default is None).
key (str) – Key for the wallet (optional, default is None).
- get_network_tokens() Dict[eth_typing.ChecksumAddress, ERC20]
Returns a Dict of addresses to ERC20 objects for all tokens on the network.
- get_nonce() web3.types.Nonce
Get the current transaction count of the wallet to determine the nonce
- Returns:
The current nonce of the wallet
- Return type:
Nonce
- get_offers(first: int = 10000000, order_by: str = 'timestamp', order_direction: str = 'desc', formatted: bool = True, book_side: OrderSide = OrderSide.NEUTRAL, maker: eth_typing.ChecksumAddress | str | None = None, from_address: eth_typing.ChecksumAddress | str | None = None, pair_name: str | None = None, pay_gem: eth_typing.ChecksumAddress | str | None = None, buy_gem: eth_typing.ChecksumAddress | str | None = None, open: bool | None = None, start_time: int | None = None, end_time: int | None = None) DataFrame
- get_orderbook(pair_name: str) OrderBook
Retrieve the order book for a specific pair from the Rubicon Router.
- Parameters:
pair_name (str) – Name of the pair to retrieve the order book for.
- Returns:
The order book for the specified pair.
- Return type:
- Raises:
PairDoesNotExistException – If the pair does not exist in the client.
- get_pair(pair_name: str) Pair
Retrieves the Pair object associated with the specified pair name. If the pair does not exist in the client, it raises a PairDoesNotExistException.
- Parameters:
pair_name (str) – Name of the pair.
- Returns:
The Pair object.
- Return type:
- Raises:
PairDoesNotExistException – If the pair does not exist in the client.
- get_pairs_list() List[str]
Get a list of all pair names in the clients internal _pairs dictionary.
- Returns:
List of pair names.
- Return type:
List[str]
- get_trades(first: int = 10000000, order_by: str = 'timestamp', order_direction: str = 'desc', formatted: bool = True, book_side: OrderSide = OrderSide.NEUTRAL, taker: eth_typing.ChecksumAddress | str | None = None, from_address: eth_typing.ChecksumAddress | str | None = None, pair_name: str | None = None, start_time: int | None = None, end_time: int | None = None) DataFrame
- place_limit_order(transaction: Transaction) TransactionReceipt
Place a limit order transaction by executing the specified transaction object. The transaction object should contain a single order of type NewLimitOrder.
- Parameters:
transaction (Transaction) – Transaction object containing the limit order.
- Returns:
The transaction hash of the executed limit order.
- Return type:
str
- Raises:
Exception – If the transaction contains more than one order.
- place_market_order(transaction: Transaction) TransactionReceipt
Place a market order transaction by executing the specified transaction object. The transaction object should contain a single order of type NewMarketOrder. The order is retrieved from the transaction and the corresponding market buy or sell method is called based on the order side.
- Parameters:
transaction (Transaction) – Transaction object containing the market order.
- Returns:
The transaction hash of the executed market order.
- Return type:
str
- Raises:
Exception – If the transaction contains more than one order.
- remove_pair(pair_name: str) None
Removes a pair from the client. It updates the pair’s asset allowances to zero and deletes the pair and its corresponding order book from the client.
- Parameters:
pair_name (str) – Name of the pair to remove.
- Raises:
PairDoesNotExistException – If the pair does not exist in the client before removal.
- start_event_poller(pair_name: str, event_type: Type[BaseEvent], filters: Dict[str, Any] | None = None, event_handler: Callable | None = None, poll_time: int = 2) None
Starts a background event poller that continuously listens for events of the specified event type related to the specified pair. The retrieved events are processed by the event handler and added to the message queue of the client. The poller will run until the pair is removed from the client.
- Parameters:
pair_name (str) – Name of the pair to start the event poller for.
event_type (Type[BaseEvent]) – Type of the event to listen for.
filters (Optional[Dict[str, Any]], optional) – Optional filters to apply when retrieving events, defaults to the events default filters (optional, default is None). These are added to the default filters for the event
event_handler (Optional[Callable], optional) – Optional event handler function to process the retrieved events, defaults to the self._default_event_handler (optional, default is None).
poll_time (int, optional) – Polling interval in seconds, defaults to 2 seconds.
- Raises:
Exception – If the message queue is not configured.
PairDoesNotExistException – If the pair does not exist in the client.
- start_orderbook_poller(pair_name: str, poll_time: int = 2) None
Starts a background thread that continuously polls the order book for the specified pair at a specified polling interval. The retrieved order book is added to the message queue of the client. The poller will run until the pair is removed from the client.
- Parameters:
pair_name (str) – Name of the pair to start the order book poller for.
poll_time (int, optional) – Polling interval in seconds, defaults to 2 seconds.
- Raises:
Exception – If the message queue is not configured.
PairDoesNotExistException – If the pair does not exist in the client.
- update_pair_allowance(pair_name: str, new_base_asset_allowance: Decimal | None = None, new_quote_asset_allowance: Decimal | None = None) None
Update the allowance for the base and quote assets of a pair if the current allowance is different from the new allowance. This method also updates the Pair data structure so that the allowance can be read without having to do a call to the chain.
- Parameters:
pair_name (str) – Name of the pair.
new_base_asset_allowance (Optional[Decimal]) – New allowance for the base asset. (optional, default is None).
new_quote_asset_allowance (Optional[Decimal]) – New allowance for the quote asset. (optional, default is None).
- Raises:
PairDoesNotExistException – If the pair does not exist in the clients internal _pairs dict.