rubi.rubicon_types package

Submodules

rubi.rubicon_types.order module

class rubi.rubicon_types.order.BaseNewOrder(pair_name: str, order_type: OrderType, order_side: OrderSide)

Bases: object

Base class for representing a new order.

Parameters:
  • pair_name (str) – The name of the trading pair.

  • order_type (OrderType) – The type of the order.

  • order_side (OrderSide) – The side of the order (buy or sell).

class rubi.rubicon_types.order.FeeEvent(id: int, pair_name: str, fee_to: eth_typing.ChecksumAddress, market_order_owner: eth_typing.ChecksumAddress, fee: Decimal, fee_asset: str)

Bases: object

classmethod from_event(pair: Pair, event: EmitFeeEvent) FeeEvent
class rubi.rubicon_types.order.NewCancelOrder(pair_name: str, order_id: int)

Bases: BaseNewOrder

Class representing a limit order cancellation

Parameters:
  • pair_name (str) – The name of the trading pair.

  • order_id (int) – The ID of the order to cancel.

class rubi.rubicon_types.order.NewLimitOrder(pair_name: str, order_side: OrderSide, size: Decimal, price: Decimal)

Bases: BaseNewOrder

Class representing a new limit order

Parameters:
  • pair_name (str) – The name of the pair being traded e.g. WETH/USDC.

  • order_side (OrderSide) – The side of the order (buy or sell).

  • size (Decimal) – The size of the order.

  • price (Decimal) – The price of the order.

class rubi.rubicon_types.order.NewMarketOrder(pair_name: str, order_side: OrderSide, size: Decimal, worst_execution_price: Decimal | None)

Bases: BaseNewOrder

Class representing a new market order.

Parameters:
  • pair_name (str) – The name of the pair being traded e.g. WETH/USDC.

  • order_side (OrderSide) – The side of the order (BUY or SELL).

  • size (Decimal) – The size of the order.

  • worst_execution_price (Decimal) – The worst execution price for the order (optional). Defaults to 0 if selling and 10 million if buying as random bounds.

class rubi.rubicon_types.order.OrderEvent(limit_order_id: int, limit_order_owner: eth_typing.ChecksumAddress, market_order_owner: eth_typing.ChecksumAddress | None, pair_name: str, order_side: OrderSide | None, order_type: OrderType, price: Decimal | None, size: Decimal | None)

Bases: object

Class to represent Rubicon Market events as an order

Parameters:
  • limit_order_id (int) – The ID of the limit order.

  • limit_order_owner (ChecksumAddress) – The owner of the limit order.

  • market_order_owner (Optional[ChecksumAddress]) – The owner of the market order (optional). Only has a value if event is an emitTakeEvent.

  • pair_name (str) – The name of the pair being traded e.g. WETH/USDC.

  • order_side (OrderSide) – The side of the order (BUY or SELL).

  • order_type (OrderType) – The type of the order (MARKET, LIMIT, LIMIT_TAKEN, LIMIT_DELETED, or CANCEL).

  • price (Decimal) – The price of the order.

  • size (Decimal) – The size of the order.

classmethod from_event(pair: Pair, event: BaseEvent, wallet: eth_typing.ChecksumAddress) OrderEvent

Create an OrderEvent from a BaseEvent emitted by the Rubicon Market.

Parameters:
  • pair (Pair) – The asset pair associated with the event.

  • event (BaseEvent) – The event to convert.

  • wallet (ChecksumAddress) – The wallet address associated with the event.

Returns:

The created OrderEvent.

Return type:

OrderEvent

Raises:

Exception – If the event cannot be converted into an OrderEvent. This occurs if the Base event has a type other than EmitOfferEvent, EmitCancelEvent, EmitTakeEvent or EmitDeleteEvent

class rubi.rubicon_types.order.OrderSide(value)

Bases: Enum

Enumeration representing the order side.

BUY = 'BUY'
NEUTRAL = 'NEUTRAL'
SELL = 'SELL'
opposite() OrderSide
sign() int
Returns:

Numerical value of the side.

Return type:

int

class rubi.rubicon_types.order.OrderType(value)

Bases: Enum

Enumeration representing the order type.

CANCEL = 'CANCEL'
LIMIT = 'LIMIT'
LIMIT_DELETED = 'LIMIT_DELETED'
LIMIT_TAKEN = 'LIMIT_TAKEN'
MARKET = 'MARKET'
class rubi.rubicon_types.order.Transaction(orders: List[BaseNewOrder], nonce: int | None = None, gas: int | None = None, max_fee_per_gas: int | None = None, max_priority_fee_per_gas: int | None = None)

Bases: object

Class representing a transaction to be executed on chain

Parameters:
  • orders (List[BaseNewOrder]) – The list of orders to include in the transaction.

  • nonce (int) – The nonce for the transaction (optional).

  • gas (int) – The gas limit for the transaction (optional).

  • max_fee_per_gas (int) – The maximum fee per gas for the transaction (optional).

  • max_priority_fee_per_gas (int) – The maximum priority fee per gas for the transaction (optional).

args() Dict

Creates a dictionary of not None arguments to pass to contract functions.

Returns:

dictionary of arguments used to send transactions.

Return type:

Dict

class rubi.rubicon_types.order.UpdateLimitOrder(pair_name: str, order_side: OrderSide, order_id: int, size: Decimal, price: Decimal)

Bases: BaseNewOrder

Class representing an update to an existing limit order

Parameters:
  • pair_name (str) – The name of the pair being traded e.g. WETH/USDC.

  • order_side (OrderSide) – The side of the order (BUY or SELL).

  • order_id (int) – The ID of the order to update.

  • size (Decimal) – The updated size of the order.

  • price (Decimal) – The updated price of the order.

rubi.rubicon_types.orderbook module

class rubi.rubicon_types.orderbook.BookLevel(price: Decimal, size: Decimal)

Bases: object

Class representing a level in the order book.

Parameters:
  • price (Decimal) – The price of the level.

  • size (Decimal) – The size of the level.

class rubi.rubicon_types.orderbook.BookSide(book_side: OrderSide, levels: List[BookLevel])

Bases: object

Class Representing a side of the order book. Either bids or asks.

Parameters:
  • book_side (OrderSide) – The side of the order book (BUY or SELL).

  • levels (List[BookLevel]) – The list of levels on the side.

best_price() Decimal

Returns the price of the best level on the book side.

Returns:

The price of the best level.

Return type:

Decimal

classmethod from_rubicon_offers(book_side: OrderSide, offers: List[List[int]], base_asset: ERC20, quote_asset: ERC20) BookSide

Creates a BookSide instance from a list of Rubicon offers.

Parameters:
  • book_side (OrderSide) – The side of the order book (BUY or SELL).

  • offers (List[List[int]]) – The list of offers retrieved from the Rubicon for an asset pair pay_gem/buy_gem.

  • base_asset (ERC20) – The base asset of the order book.

  • quote_asset (ERC20) – The quote asset of the order book.

Returns:

The BookSide instance representing the order book side.

Return type:

BookSide

remove_liquidity_from_book(price: Decimal, size: Decimal)
class rubi.rubicon_types.orderbook.OrderBook(bids: BookSide, asks: BookSide)

Bases: object

Class represents an OrderBook.

Parameters:
  • bids (BookSide) – BookSide representing the bid orders.

  • asks (BookSide) – BookSide representing the ask orders.

best_ask() Decimal

Get the best ask price from the order book.

Returns:

Best ask price.

Return type:

Decimal

best_bid() Decimal

Get the best bid price from the order book.

Returns:

Best bid price.

Return type:

Decimal

classmethod from_rubicon_offer_book(offer_book: Tuple[List[List[int]], List[List[int]]], base_asset: ERC20, quote_asset: ERC20) OrderBook

Create an OrderBook from Rubicon offer book.

Parameters:
  • offer_book (Tuple[List[List[int]], List[List[int]]]) – Rubicon offer book containing bid and ask offers.

  • base_asset (ERC20) – An ERC20 instance representing the base asset.

  • quote_asset (ERC20) – An ERC20 instance representing the quote asset.

Returns:

OrderBook instance.

Return type:

OrderBook

mid_price() Decimal

Calculate the mid-price of the order book.

Returns:

mid-price.

Return type:

Decimal

spread() Decimal

Calculate the current bid ask spread of the order book.

Returns:

spread

Return type:

Decimal

rubi.rubicon_types.pair module

class rubi.rubicon_types.pair.Pair(name: str, base_asset: ERC20, quote_asset: ERC20, current_base_asset_allowance: Decimal | None, current_quote_asset_allowance: Decimal | None)

Bases: object

Class representing a trading asset pair, e.g. WETH/USDC would have WETH as the base asset and USDC as the quote asset.

Parameters:
  • name (str) – The name of the pair, e.g. WETH/USDC.

  • base_asset (ERC20) – Base asset of the pair.

  • quote_asset (ERC20) – Quote asset of the pair.

  • current_base_asset_allowance (Decimal) – The base asset spending allowance of the RubiconMarket contract, Optional.

  • current_quote_asset_allowance (Decimal) – The quote asset spending allowance of the RubiconMarket contract, Optional.

update_base_asset_allowance(new_base_asset_allowance: Decimal) None

Update the current base asset allowance.

Parameters:

new_base_asset_allowance (Decimal) – New base asset allowance.

Returns:

None

update_quote_asset_allowance(new_quote_asset_allowance: Decimal) None

Update the current quote asset allowance.

Parameters:

new_quote_asset_allowance (Decimal) – New quote asset allowance.

Returns:

None

exception rubi.rubicon_types.pair.PairDoesNotExistException(msg: str)

Bases: Exception

Exception raised when an asset pair does not exist.

Parameters:

msg (str) – Error message.