UniswapV2TestTrader#

tradeexecutor.testing.ethereumtrader_uniswap_v2.UniswapV2TestTrader Python class in Trading Strategy framework.

class UniswapV2TestTrader[source]#

Bases: EthereumTrader

Helper class to trade against a locally deployed Uniswap v2 contract.

Allows to execute individual trades without need to go through decide_trades()

May be used with or without pricing_model.

__init__(uniswap, state, pair_universe, tx_builder, pricing_model=None)[source]#
Parameters:

Methods

__init__(uniswap, state, pair_universe, ...)

param web3:

broadcast_trades(trades[, ...])

Broadcast prepared trades.

buy(pair, amount_in_usd[, execute, ...])

Buy token (trading pair) for a certain value.

execute_trades_simple(trades[, ...])

Execute trades on web3 instance.

sell(pair, quantity[, execute, ...])

Sell tokens on an open position for a certain quantity.

Attributes

web3

__init__(uniswap, state, pair_universe, tx_builder, pricing_model=None)[source]#
Parameters:
buy(pair, amount_in_usd, execute=True, slippage_tolerance=None)[source]#

Buy token (trading pair) for a certain value.

Parameters:
Return type:

Tuple[TradingPosition, TradeExecution]

sell(pair, quantity, execute=True, slippage_tolerance=None)[source]#

Sell tokens on an open position for a certain quantity.

Parameters:
Return type:

Tuple[TradingPosition, TradeExecution]

execute_trades_simple(trades, stop_on_execution_failure=True, broadcast=True)[source]#

Execute trades on web3 instance.

A testing shortcut

  • Create BlockchainTransaction instances of each gives TradeExecution

  • Execute them on Web3 test connection (EthereumTester / Ganache)

  • Works with single Uniswap test deployment

Parameters:
  • trades (List[TradeExecution]) – Trades to be converted to blockchain transactions

  • stop_on_execution_failure – Raise exception on an error

  • broadcast – Broadcast trades over web3 connection

Return type:

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

broadcast_trades(trades, stop_on_execution_failure=True)[source]#

Broadcast prepared trades.

Parameters:

trades (List[TradeExecution]) –