SimulatedWallet#
API documentation for tradeexecutor.backtest.simulated_wallet.SimulatedWallet Python class in Trading Strategy framework.
- class SimulatedWallet[source]#
- Bases: - object- A wallet that keeps token balances by ERC-20 address. - Simulates different incoming and outgoing tokens from a wallet includive, aToken and vToken interest amounts with - rebalance().
- If a backtest tries to transfer a token it does not have, or does not have enough of it, raise an error 
- Will catch bugs in internal accounting 
 - Methods - __init__()- Allocates a dummy nonce for a transaction. - Show the status of the wallet as a printable DataFrame. - get_balance(token)- Get on-chain balance of one token. - get_token_symbol(token)- Get the human readable name of token for diagnostics output. - rebase(token, new_amount)- Set rebase token amount. - set_balance(token, amount)- Directly set balance. - update_balance(token, delta[, reason, epsilon])- Change the token balance of some delta. - update_token_info(asset)- Set the token info for a particular ERC-20. - verify_balances(expected[, epsilon])- Check that our simulated balances are what we expect. - Attributes - Raw balances token address -> balance - token address -> asset info for debug logging - Start with zero nonce like Ethereum acconts - tokens: Dict[str, AssetIdentifier]#
- token address -> asset info for debug logging 
 - nonce#
- Start with zero nonce like Ethereum acconts 
 - update_balance(token, delta, reason=None, epsilon=Decimal('1.00000000000000007154242405462192450852805618492324772617063644020163337700068950653076171875E-18'))[source]#
- Change the token balance of some delta. - Check that balance does not go zero. - Parameters:
- token (str | tradeexecutor.state.identifier.AssetIdentifier) – - Token we receive or send. - Give either raw address or asset definition. - Any asset definion is automatically added to our internal tracking list for diagnostics. 
- delta (Decimal) – The amount of token, human units 
- reason (str) – - Reason for this change. - Only used for backtesting diagnostics. 
- epsilon – If the balance goes below this dust threshold, go all the way to zero 
 
 
 - set_balance(token, amount)[source]#
- Directly set balance. - Parameters:
- token (str | tradeexecutor.state.identifier.AssetIdentifier) – - Token we receive or send. - Give either raw address or asset definition. - Any asset definion is automatically added to our internal tracking list for diagnostics. 
- amount (Decimal) – New absolute balance. 
 
 
 - rebase(token, new_amount)[source]#
- Set rebase token amount. - aToken / vToken accrues interest or debt. - Parameters:
- new_amount (Decimal) – Abs token amount on the chain 
- token (str | tradeexecutor.state.identifier.AssetIdentifier) – 
 
 
 - get_balance(token)[source]#
- Get on-chain balance of one token. - Returns:
- Human-readable token balance 
- Parameters:
- token (str | tradeexecutor.state.identifier.AssetIdentifier) – 
- Return type:
 
 - get_token_symbol(token)[source]#
- Get the human readable name of token for diagnostics output. - Parameters:
- token (str | tradeexecutor.state.identifier.AssetIdentifier) – 
- Return type:
 
 - update_token_info(asset)[source]#
- Set the token info for a particular ERC-20. - This way the wallet has metadata on what token it has and can produce better diagnostics output. - Automatically called by - update_balance().- Parameters:
- asset (AssetIdentifier) –