UniswapV2ExecutionModelVersion0#

tradeexecutor.ethereum.uniswap_v2_execution_v0.UniswapV2ExecutionModelVersion0 Python class in Trading Strategy framework.

class UniswapV2ExecutionModelVersion0[source]#

Bases: ExecutionModel

Run order execution on a single Uniswap v2 style exchanges.

TODO: This model was used in the first prototype and later discarded.

__init__(uniswap, hot_wallet, min_balance_threshold=Decimal('0.5'), confirmation_block_count=6, confirmation_timeout=datetime.timedelta(seconds=300), max_slippage=0.01, stop_on_execution_failure=True)[source]#
Parameters:
  • state

  • uniswap (UniswapV2Deployment) –

  • hot_wallet (HotWallet) –

  • min_balance_threshold – Abort execution if our hot wallet gas fee balance drops below this

  • confirmation_block_count – How many blocks to wait for the receipt confirmations to mitigate unstable chain tip issues

  • confirmation_timeout – How long we wait transactions to clear

  • stop_on_execution_failure – Raise an exception if any of the trades fail top execute

Methods

__init__(uniswap, hot_wallet[, ...])

param state:

execute_trades(ts, state, trades, ...[, ...])

Execute the trades determined by the algo on a designed Uniswap v2 instance.

get_routing_state_details()

Prototype does not know much about routing.

initialize()

Set up the wallet

is_live_trading()

is_stop_loss_supported()

Do we support stop-loss/take profit functionality with this execution model?

is_v3()

preflight_check()

Check that we can connect to the web3 node

repair_unconfirmed_trades(state)

Repair unconfirmed trades.

Attributes

chain_id

Which chain the live execution is connected to.

__init__(uniswap, hot_wallet, min_balance_threshold=Decimal('0.5'), confirmation_block_count=6, confirmation_timeout=datetime.timedelta(seconds=300), max_slippage=0.01, stop_on_execution_failure=True)[source]#
Parameters:
  • state

  • uniswap (UniswapV2Deployment) –

  • hot_wallet (HotWallet) –

  • min_balance_threshold – Abort execution if our hot wallet gas fee balance drops below this

  • confirmation_block_count – How many blocks to wait for the receipt confirmations to mitigate unstable chain tip issues

  • confirmation_timeout – How long we wait transactions to clear

  • stop_on_execution_failure – Raise an exception if any of the trades fail top execute

property chain_id: int#

Which chain the live execution is connected to.

is_stop_loss_supported()[source]#

Do we support stop-loss/take profit functionality with this execution model?

  • For backtesting we need to have data stream for candles used to calculate stop loss

  • For production execution, we need to have special oracle data streams for checking real-time stop loss

Return type:

bool

preflight_check()[source]#

Check that we can connect to the web3 node

initialize()[source]#

Set up the wallet

execute_trades(ts, state, trades, routing_model, routing_state, check_balances=False)[source]#

Execute the trades determined by the algo on a designed Uniswap v2 instance.

Parameters:
Returns:

Tuple List of succeeded trades, List of failed trades

Return type:

Tuple[List[TradeExecution], List[TradeExecution]]

get_routing_state_details()[source]#

Prototype does not know much about routing.

Return type:

object

repair_unconfirmed_trades(state)[source]#

Repair unconfirmed trades.

Repair trades that failed to properly broadcast or confirm due to blockchain node issues.

Returns:

List of fixed trades

Parameters:

state (State) –

Return type:

List[TradeExecution]