execution metrics
This commit is contained in:
@@ -189,19 +189,25 @@ async def accounting_placement(order_placed: EventData):
|
|||||||
AccountingSubcategory.GasFee, NATIVE_TOKEN, gas_fee)
|
AccountingSubcategory.GasFee, NATIVE_TOKEN, gas_fee)
|
||||||
|
|
||||||
|
|
||||||
async def accounting_fill(fill: EventData, out_token: str):
|
async def accounting_fill(fill: EventData, out_token: str) -> dec:
|
||||||
|
"""
|
||||||
|
Returns the mark-to-market USD value of the transaction.
|
||||||
|
"""
|
||||||
block_hash = hexstr(fill['blockHash'])
|
block_hash = hexstr(fill['blockHash'])
|
||||||
tx_id = hexstr(fill['transactionHash'])
|
tx_id = hexstr(fill['transactionHash'])
|
||||||
fee = int(fill['args']['fillFee'])
|
fee = int(fill['args']['fillFee'])
|
||||||
fm = await FeeManager.get()
|
fm = await FeeManager.get()
|
||||||
await add_accounting_row(fm.fill_fee_account_addr, block_hash, tx_id, AccountingCategory.Income,
|
return await add_accounting_row(fm.fill_fee_account_addr, block_hash, tx_id, AccountingCategory.Income,
|
||||||
AccountingSubcategory.FillFee, out_token, fee)
|
AccountingSubcategory.FillFee, out_token, fee)
|
||||||
|
|
||||||
|
|
||||||
async def add_accounting_row(account: str, block_hash: Optional[str], tx_id: Optional[str], category, subcategory, token, amount, note=None,
|
async def add_accounting_row(account: str, block_hash: Optional[str], tx_id: Optional[str], category, subcategory, token, amount, note=None,
|
||||||
*, adjust_decimals=True):
|
*, adjust_decimals=True) -> dec:
|
||||||
|
"""
|
||||||
|
Returns the mark-to-market USD value of the transaction.
|
||||||
|
"""
|
||||||
if amount == 0:
|
if amount == 0:
|
||||||
return
|
return dec(0)
|
||||||
if adjust_decimals:
|
if adjust_decimals:
|
||||||
amount = await adj_dec(token, amount)
|
amount = await adj_dec(token, amount)
|
||||||
# noinspection PyTypeChecker
|
# noinspection PyTypeChecker
|
||||||
@@ -221,10 +227,10 @@ async def add_accounting_row(account: str, block_hash: Optional[str], tx_id: Opt
|
|||||||
if new_amount < 0:
|
if new_amount < 0:
|
||||||
log.error(f'negative balance for account {account} when applying accounting row {time} {category} {subcategory} {token} {amount} ${value}')
|
log.error(f'negative balance for account {account} when applying accounting row {time} {category} {subcategory} {token} {amount} ${value}')
|
||||||
account_db.balances[token] = new_amount
|
account_db.balances[token] = new_amount
|
||||||
metric.account_balance.labels(address=account, token=token).set(new_amount)
|
|
||||||
db.session.add(account_db) # deep changes would not be detected by the ORM
|
db.session.add(account_db) # deep changes would not be detected by the ORM
|
||||||
else:
|
else:
|
||||||
log.warning(f'No db account found for {account}')
|
log.warning(f'No db account found for {account}')
|
||||||
|
return value
|
||||||
|
|
||||||
async def adjust_balance(account: DbAccount, token=NATIVE_TOKEN, subcategory=AccountingSubcategory.InitialBalance, note=None):
|
async def adjust_balance(account: DbAccount, token=NATIVE_TOKEN, subcategory=AccountingSubcategory.InitialBalance, note=None):
|
||||||
true_balance = await get_balance(account.address, token)
|
true_balance = await get_balance(account.address, token)
|
||||||
|
|||||||
@@ -44,11 +44,12 @@ async def handle_order_placed(event: EventData):
|
|||||||
except KeyError:
|
except KeyError:
|
||||||
log.warning(f'Rogue DexorderSwapPlaced in tx {hexstr(event["transactionHash"])}')
|
log.warning(f'Rogue DexorderSwapPlaced in tx {hexstr(event["transactionHash"])}')
|
||||||
return
|
return
|
||||||
await accounting_placement(event)
|
|
||||||
log.debug(f'DexorderSwapPlaced {addr} {start_index} {num_orders}')
|
log.debug(f'DexorderSwapPlaced {addr} {start_index} {num_orders}')
|
||||||
if not await verify_vault(addr):
|
if not await verify_vault(addr):
|
||||||
log.warning(f'Discarding order from rogue vault {addr}.')
|
log.warning(f'Discarding order from rogue vault {addr}.')
|
||||||
return
|
return
|
||||||
|
await accounting_placement(event)
|
||||||
|
metric.orders.inc()
|
||||||
contract = None
|
contract = None
|
||||||
for index in range(start_index, start_index+num_orders):
|
for index in range(start_index, start_index+num_orders):
|
||||||
key = OrderKey(addr, index)
|
key = OrderKey(addr, index)
|
||||||
@@ -82,7 +83,8 @@ async def handle_swap_filled(event: EventData):
|
|||||||
except KeyError:
|
except KeyError:
|
||||||
log.warning(f'DexorderSwapFilled IGNORED due to missing order {vault} {order_index}')
|
log.warning(f'DexorderSwapFilled IGNORED due to missing order {vault} {order_index}')
|
||||||
return
|
return
|
||||||
await accounting_fill(event, order.order.tokenOut)
|
value = await accounting_fill(event, order.order.tokenOut)
|
||||||
|
metric.volume.inc(value)
|
||||||
order.status.trancheStatus[tranche_index].activationTime = next_execution_time # update rate limit
|
order.status.trancheStatus[tranche_index].activationTime = next_execution_time # update rate limit
|
||||||
try:
|
try:
|
||||||
triggers = OrderTriggers.instances[order.key]
|
triggers = OrderTriggers.instances[order.key]
|
||||||
|
|||||||
@@ -11,10 +11,13 @@ runner_loops = Counter("runner_loops", "Number of times the runner loop has been
|
|||||||
runner_latency = Summary("runner_latency", "How old the current block being processed is, in seconds")
|
runner_latency = Summary("runner_latency", "How old the current block being processed is, in seconds")
|
||||||
|
|
||||||
vaults = Gauge("vaults", "Total vault count", )
|
vaults = Gauge("vaults", "Total vault count", )
|
||||||
|
orders = Counter("orders", "Orders placed", )
|
||||||
open_orders = Gauge("open_orders", "Total active orders", )
|
open_orders = Gauge("open_orders", "Total active orders", )
|
||||||
triggers_time = Gauge("triggers_time", "Total active time triggers", )
|
triggers_time = Gauge("triggers_time", "Total active time triggers", )
|
||||||
triggers_line = Gauge("triggers_line", "Total active line triggers", )
|
triggers_line = Gauge("triggers_line", "Total active line triggers", )
|
||||||
|
executions = Counter("executions", "Total executions attempted")
|
||||||
|
executions_failed = Counter("executions_failed", "Number of failed execution attempts")
|
||||||
|
volume = Counter("volume", "Total volume of successful executions in USD")
|
||||||
|
|
||||||
account_balance = Gauge("account_balance", "Account balance", ["address", "token"])
|
|
||||||
account_total = Gauge('account_total', 'Total number of accounts configured')
|
account_total = Gauge('account_total', 'Total number of accounts configured')
|
||||||
account_available = Gauge('account_available', 'Number of accounts that do not have any pending transactions')
|
account_available = Gauge('account_available', 'Number of accounts that do not have any pending transactions')
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ from uuid import UUID
|
|||||||
from web3.exceptions import ContractPanicError, ContractLogicError
|
from web3.exceptions import ContractPanicError, ContractLogicError
|
||||||
from web3.types import EventData
|
from web3.types import EventData
|
||||||
|
|
||||||
from dexorder import db
|
from dexorder import db, metric
|
||||||
from dexorder.accounting import accounting_transaction_gas
|
from dexorder.accounting import accounting_transaction_gas
|
||||||
from dexorder.base import TransactionReceiptDict, TransactionRequest, transaction_request_deserializers
|
from dexorder.base import TransactionReceiptDict, TransactionRequest, transaction_request_deserializers
|
||||||
from dexorder.base.order import TrancheKey, OrderKey
|
from dexorder.base.order import TrancheKey, OrderKey
|
||||||
@@ -125,6 +125,11 @@ def finish_execution_request(tk: TrancheKey, error: Optional[str]=None):
|
|||||||
if trig is not None:
|
if trig is not None:
|
||||||
trig.touch()
|
trig.touch()
|
||||||
|
|
||||||
|
if error is None:
|
||||||
|
metric.executions.inc()
|
||||||
|
else:
|
||||||
|
metric.executions_failed.inc()
|
||||||
|
|
||||||
#
|
#
|
||||||
# execute() error handling
|
# execute() error handling
|
||||||
#
|
#
|
||||||
|
|||||||
Reference in New Issue
Block a user