Skip to content

Commit

Permalink
Handle executed price
Browse files Browse the repository at this point in the history
  • Loading branch information
hieuh25 committed Nov 25, 2024
1 parent ab0acd3 commit 258e487
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def strategy_universe(
return TradingStrategyUniverse.create_from_dataset(dataset, asset_usdc.address)


@flaky.flaky
# @flaky.flaky
def test_generic_routing_multihops_trade(
web3: Web3,
hot_wallet: HotWallet,
Expand All @@ -119,6 +119,7 @@ def test_generic_routing_multihops_trade(
generic_pricing_model: GenericPricing,
asset_usdc: AssetIdentifier,
asset_wbtc: AssetIdentifier,
asset_wmatic: AssetIdentifier,
wbtc_weth_spot_pair: TradingPairIdentifier,
weth_usdc_spot_pair: TradingPairIdentifier,
wmatic_weth_spot_pair: TradingPairIdentifier,
Expand Down Expand Up @@ -219,7 +220,6 @@ def test_generic_routing_multihops_trade(
assert len(state.portfolio.open_positions) == 2

p = state.portfolio.open_positions[2]
print(p)
assert p.get_opening_price() == pytest.approx(0.8526643063862225)

# Check our wallet holds all tokens we expect.
Expand All @@ -231,8 +231,10 @@ def test_generic_routing_multihops_trade(
{
asset_usdc.address,
asset_wbtc.address,
asset_wmatic.address,
},
decimalise=True,
)
assert 0 < balances[asset_wbtc.address] < 1000, f"Got balance: {balances}"
assert balances[asset_usdc.address] == pytest.approx(9_500), f"Got balance: {balances}"
assert 0 < balances[asset_wmatic.address] < 1000, f"Got balance: {balances}"
assert balances[asset_usdc.address] == pytest.approx(9_000), f"Got balance: {balances}"
4 changes: 2 additions & 2 deletions tradeexecutor/ethereum/uniswap_v3/uniswap_v3_routing.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ def settle_trade(
if trade.is_buy():
assert path[0] == reserve.address, f"Was expecting the route path to start with reserve token {reserve}, got path {result.path}"

price = result.get_human_price(quote_token_details.address == result.token0.address)
price = result.get_human_price(base_token_details.address == result.token1.address)
executed_reserve = result.amount_in / Decimal(10 ** reserve.decimals)
executed_amount = result.amount_out / Decimal(10 ** base_token_details.decimals)

Expand All @@ -359,7 +359,7 @@ def settle_trade(
# Ordered other way around
assert path[0] == base_token_details.address.lower(), f"Path is {path}, base token is {base_token_details}"
assert path[-1] == reserve.address
price = result.get_human_price(quote_token_details.address == result.token0.address)
price = result.get_human_price(base_token_details.address == result.token0.address)
executed_amount = -result.amount_in / Decimal(10 ** base_token_details.decimals)
executed_reserve = result.amount_out / Decimal(10 ** reserve.decimals)

Expand Down

0 comments on commit 258e487

Please sign in to comment.