7
7
from hyperliquid .exchange import Exchange
8
8
9
9
from pusher .config import Config
10
+ from pusher .exception import PushError
10
11
from pusher .kms_signer import KMSSigner
11
12
from pusher .metrics import Metrics
12
13
from pusher .price_state import PriceState
@@ -30,7 +31,10 @@ def __init__(self, config: Config, price_state: PriceState, metrics: Metrics):
30
31
oracle_pusher_key = Path (config .hyperliquid .oracle_pusher_key_path ).read_text ().strip ()
31
32
oracle_account : LocalAccount = Account .from_key (oracle_pusher_key )
32
33
logger .info ("oracle pusher local pubkey: {}" , oracle_account .address )
33
- self .publisher_exchanges = [Exchange (wallet = oracle_account , base_url = url ) for url in self .push_urls ]
34
+ self .publisher_exchanges = [Exchange (wallet = oracle_account ,
35
+ base_url = url ,
36
+ timeout = config .hyperliquid .publish_timeout )
37
+ for url in self .push_urls ]
34
38
if config .kms .enable_kms :
35
39
self .enable_kms = True
36
40
self .kms_signer = KMSSigner (config , self .publisher_exchanges )
@@ -70,23 +74,29 @@ def publish(self):
70
74
# TODO: "Each update can change oraclePx and markPx by at most 1%."
71
75
# TODO: "The markPx cannot be updated such that open interest would be 10x the open interest cap."
72
76
73
- push_response = None
74
77
if self .enable_publish :
75
- if self .enable_kms :
76
- push_response = self .kms_signer .set_oracle (
77
- dex = self .market_name ,
78
- oracle_pxs = oracle_pxs ,
79
- all_mark_pxs = mark_pxs ,
80
- external_perp_pxs = external_perp_pxs ,
81
- )
82
- else :
83
- push_response = self ._send_update (
84
- oracle_pxs = oracle_pxs ,
85
- all_mark_pxs = mark_pxs ,
86
- external_perp_pxs = external_perp_pxs ,
87
- )
88
-
89
- self ._handle_response (push_response )
78
+ try :
79
+ if self .enable_kms :
80
+ push_response = self .kms_signer .set_oracle (
81
+ dex = self .market_name ,
82
+ oracle_pxs = oracle_pxs ,
83
+ all_mark_pxs = mark_pxs ,
84
+ external_perp_pxs = external_perp_pxs ,
85
+ )
86
+ else :
87
+ push_response = self ._send_update (
88
+ oracle_pxs = oracle_pxs ,
89
+ all_mark_pxs = mark_pxs ,
90
+ external_perp_pxs = external_perp_pxs ,
91
+ )
92
+ self ._handle_response (push_response )
93
+ except PushError :
94
+ logger .error ("All push attempts failed" )
95
+ self .metrics .failed_push_counter .add (1 , self .metrics_labels )
96
+ except Exception as e :
97
+ logger .exception ("Unexpected exception in push request: {}" , repr (e ))
98
+ else :
99
+ logger .debug ("push disabled" )
90
100
91
101
def _send_update (self , oracle_pxs , all_mark_pxs , external_perp_pxs ):
92
102
for exchange in self .publisher_exchanges :
@@ -100,14 +110,9 @@ def _send_update(self, oracle_pxs, all_mark_pxs, external_perp_pxs):
100
110
except Exception as e :
101
111
logger .exception ("perp_deploy_set_oracle exception for endpoint: {} error: {}" , exchange .base_url , repr (e ))
102
112
103
- return None
113
+ raise PushError ( "all push endpoints failed" )
104
114
105
115
def _handle_response (self , response ):
106
- if response is None :
107
- logger .error ("Push API call failed" )
108
- self .metrics .failed_push_counter .add (1 , self .metrics_labels )
109
- return
110
-
111
116
logger .debug ("publish: push response: {} {}" , response , type (response ))
112
117
status = response .get ("status" )
113
118
if status == "ok" :
0 commit comments