UniswapV2ExecutionModelVersion0#

API documentation for tradeexecutor.ethereum.uniswap_v2.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 will be 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:

create_default_routing_model(strategy_universe)

Get the default routing model for this executor.

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

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

get_balance_address()

Get the address where the strat holds tokens.

get_routing_state_details()

Prototype does not know much about routing.

get_safe_latest_block()

Fix the block number for all checks and actions.

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

get_balance_address()[source]#

Get the address where the strat holds tokens.

Returns:

None if this executor does not use on-chain addresses.

get_safe_latest_block()[source]#

Fix the block number for all checks and actions.

  • At the start of each action cycle (strategy decision, position triggers) we fix ourselves to a certain block number we know is “safe” and the data in at this block number is unlike to change

  • We then perform all deposit and redemptions and accounting checks using this block number as end block, to get a

Returns:

A good safe latest block number.

Return None if the block number is irrelevant for the execution, like backtesting and such.

Return type:

int

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]