BlockchainTransaction#
tradeexecutor.state.blockhain_transaction.BlockchainTransaction Python class in Trading Strategy framework.
- class BlockchainTransaction[source]#
Bases:
object
A stateful blockchain transaction.
The state tracks a transaction over its life cycle
Transactions are part of a larger logical operation (a trade)
Transactions can be resolved either to success or failed
Transaction information is easily exported to the frontend
Transaction has (rough) four phases
Preparation
Signing
Broadcast
Confirmation
- __init__(chain_id=None, from_address=None, contract_address=None, function_selector=None, args=None, tx_hash=None, nonce=None, details=None, signed_bytes=None, broadcasted_at=None, included_at=None, block_number=None, block_hash=None, status=None, realised_gas_units_consumed=None, realised_gas_price=None, revert_reason=None)#
- Parameters:
- Return type:
None
Methods
__init__
([chain_id, from_address, ...])from_dict
(kvs, *[, infer_missing])from_json
(s, *[, parse_float, parse_int, ...])Get the gas limit of the transaction.
How much wei per gas unit we planned to spend on this transactions.
Return the transaction object as it would be in web3.py.
Transaction is success if it's succeed flag has been set.
schema
(*[, infer_missing, only, exclude, ...])set_broadcast_information
(nonce, tx_hash, ...)Update the information we are going to use to broadcast the transaction.
set_confirmation_information
(ts, ...[, ...])Update the information we are going to use to broadcast the transaction.
set_target_information
(chain_id, ...)Update the information on which transaction we are going to perform.
to_dict
([encode_json])to_json
(*[, skipkeys, ensure_ascii, ...])Attributes
Arguments we passed to the smart contract function
Block has of the transaction where the executor saw the inclusion
Block number when this transaction was included in a block
When this transaction was broadcasted
Chain id from https://github.com/ethereum-lists/chains
Contract we called.
Raw Ethereum transaction dict.
TODO: Part of signed bytes.
Function we called
Block timestamp when this tranasction was included in a block
Blockchain bookkeeping
Gas price for the tx in gwei
Gas consumed by the tx
The transaction revert reason if we manage to extract it
Raw bytes of the signed transaction
status from the tx receipt.
Blockchain bookkeeping
- chain_id: Optional[int] = None#
Chain id from https://github.com/ethereum-lists/chains
- args: Optional[Tuple[Any]] = None#
Arguments we passed to the smart contract function
This is not JSON serialisable because individual arguments may contain values that are token amounts and thus outside the maximum int of JavaScript.
- details: Optional[Dict] = None#
Raw Ethereum transaction dict. Output from web3 buildTransaction()
Example:
{‘value’: 0, ‘maxFeePerGas’: 1844540158, ‘maxPriorityFeePerGas’: 1000000000, ‘chainId’: 61, ‘from’: ‘0x6B49598B34B9c7FbF7C57306d0b0578676D55ffA’, ‘gas’: 100000, ‘to’: ‘0xF2E246BB76DF876Cef8b38ae84130F4F55De395b’, ‘data’: ‘0x095ea7b30000000000000000000000006d411e0a54382ed43f02410ce1c7a7c122afa6e1ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff’, ‘nonce’: 0}
- included_at: Optional[datetime] = None#
Block timestamp when this tranasction was included in a block
- get_transaction()[source]#
Return the transaction object as it would be in web3.py.
Needed for
analyse_trade_by_receipt()
. This will reconstructTypedTransaction
instance from the raw signed transaction bytes. The object will have a dict containing “data” field which we can then use for the trade analysis.- Return type:
- set_target_information(chain_id, contract_address, function_selector, args, details)[source]#
Update the information on which transaction we are going to perform.
- set_broadcast_information(nonce, tx_hash, signed_bytes)[source]#
Update the information we are going to use to broadcast the transaction.
- set_confirmation_information(ts, block_number, block_hash, realised_gas_units_consumed, realised_gas_price, status, revert_reason=None)[source]#
Update the information we are going to use to broadcast the transaction.
- get_planned_gas_price()[source]#
How much wei per gas unit we planned to spend on this transactions.
Gets maxFeePerGas for EVM transction.
- Returns:
0 if unknown
- Return type:
- get_gas_limit()[source]#
Get the gas limit of the transaction.
Gets gas for EVM transction.
- Returns:
0 if unknown
- Return type:
- __init__(chain_id=None, from_address=None, contract_address=None, function_selector=None, args=None, tx_hash=None, nonce=None, details=None, signed_bytes=None, broadcasted_at=None, included_at=None, block_number=None, block_hash=None, status=None, realised_gas_units_consumed=None, realised_gas_price=None, revert_reason=None)#
- Parameters:
- Return type:
None