account_correction#

API documentation for tradeexecutor.strategy.account_correction Python module in Trading Strategy.

Module description#

Apply accounting corrections on the strategy state.

  • Read on-chain balances

  • Compare them to the balances seen in the state

  • Adjust statebalacnes to match chain based ones

  • Generate the accounting events to reflect these changes

Classes#

AccountingBalanceCheck

Accounting correction applied to a balance.

AccountingCorrectionCause

UnknownTokenPositionFix

How to fix tokens we see in the wallet, but for which we do not have a position open in the state.

Functions#

apply_accounting_correction(state, ...)

Update the state to reflect the true on-chain balances.

calculate_account_corrections(pair_universe, ...)

Figure out differences between our internal ledger (state) and on-chain balances.

calculate_total_assets(portfolio)

Calculate total tokens the portfolio should held.

check_accounts(pair_universe, ...[, ...])

Create a summary accounting corrections needed.

check_state_internal_coherence(state)

Check that we do not have any positions with non-executed trades.

correct_accounts(state, corrections, ...[, ...])

Apply the accounting corrections on the state (internal ledger).

is_relative_mismatch(actual_amount, ...)

Calculate if we are within the relative tolerance.

open_missing_credit_position(...)

Open a missing spot position.

open_missing_position(strategy_universe, ...)

"We have tokens for a trading pair, but no position is closed.

open_missing_spot_position(...)

Open a missing spot position.

transfer_away_assets_without_position(...)

Transfer away non-reserve assets that cannot be mapped to an open position.