PricingModel#

tradeexecutor.strategy.pricing_model.PricingModel class.

class PricingModel[source]#

Bases: ABC

Get a price for the asset.

Needed for various aspects

  • Revaluate portfolio positiosn

  • Estimate buy/sell price for the live trading so we can calculate slippage

  • Get the historical price in backtesting

Timestamp is passed to the pricing method. However we expect it only be honoured during the backtesting - live execution may always use the latest price.

Note

For example, in futures markets there could be different fees on buy/sell transctions.

__init__()#

Methods

__init__()

get_buy_price(ts, pair, reserve)

Get the sell price for an asset.

get_sell_price(ts, pair, quantity)

Get the sell price for an asset.

quantize_base_quantity(pair, quantity[, ...])

Convert any base token quantity to the native token units by its ERC-20 decimals.

abstract get_sell_price(ts, pair, quantity)[source]#

Get the sell price for an asset.

Parameters
  • ts (datetime) – When to get the price. Used in backtesting. Live models may ignore.

  • pair (TradingPairIdentifier) – Trading pair we are intereted in

  • quantity (Optional[Decimal]) – If the sel quantity is known, get the price with price impact.

Return type

USDollarAmount

abstract get_buy_price(ts, pair, reserve)[source]#

Get the sell price for an asset.

Parameters
  • ts (datetime) – When to get the price. Used in backtesting. Live models may ignore.

  • pair (TradingPairIdentifier) – Trading pair we are intereted in

  • reserve (Optional[Decimal]) – If the buy token quantity quantity is known, get the buy price with price impact.

Return type

USDollarAmount

abstract quantize_base_quantity(pair, quantity, rounding='ROUND_DOWN')[source]#

Convert any base token quantity to the native token units by its ERC-20 decimals.

Parameters
Return type

Decimal