Skip to content

Commit

Permalink
add cancel stale order
Browse files Browse the repository at this point in the history
  • Loading branch information
Tburm committed Sep 26, 2024
1 parent 6003ca2 commit d842ac5
Showing 1 changed file with 48 additions and 2 deletions.
50 changes: 48 additions & 2 deletions src/synthetix/perps/perps.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,10 +233,10 @@ def _prepare_oracle_call(self, market_names: [str] = []):
to, data, _ = make_pyth_fulfillment_request(
self.snx,
self.snx.contracts["pyth_erc7412_wrapper"]["PythERC7412Wrapper"]["address"],
1, # update type
1, # update type
feed_ids,
price_update_data,
30, # staleness tolerance
30, # staleness tolerance
0,
)
value = len(market_names)
Expand Down Expand Up @@ -1800,6 +1800,52 @@ def settle_order(

raise Exception("Failed to settle order after maximum attempts")

def cancel_stale_order(
self,
account_id: int = None,
market_id: int = None,
market_name: str = None,
submit: bool = False,
):
"""
Cancels and order for the specified account and market.
:param int | None account_id: The id of the account to cancel the order for. If not provided, uses the default account.
:param int | None market_id: The id of the market to cancel the order in.
:param str | None market_name: The name of the market to cancel the order in.
:param bool submit: If True, submit the transaction to the blockchain. If False, return the transaction parameters.
:return: If submit is True, returns the transaction hash. Otherwise, returns the transaction parameters.
:rtype: str | dict
"""
market_id, market_name = self._resolve_market(market_id, market_name)
if account_id is None:
account_id = self.default_account_id

# Prepare the transaction
tx_params = write_erc7412(
self.snx,
self.market_proxy,
"cancelStaleOrder",
[
account_id,
market_id,
],
)

if submit:
try:
tx_hash = self.snx.execute_transaction(tx_params)
self.logger.info(
f"Cancelling stale order for account {account_id} in market {market_name}"
)
self.logger.info(f"cancelStaleOrder tx: {tx_hash}")
return tx_hash
except Exception as e:
self.logger.error(f"Failed to cancel order: {str(e)}")
raise
else:
return tx_params

def pay_debt(
self,
amount: int = None,
Expand Down

0 comments on commit d842ac5

Please sign in to comment.