@@ -141,8 +141,10 @@ def __init__(
141
141
142
142
# Configuration
143
143
self .config = config
144
+ self .check_order_timeout_secs = 10.0
144
145
self ._log .info (f"{ config .account_currency = } " , LogColor .BLUE )
145
146
self ._log .info (f"{ config .request_account_state_secs = } " , LogColor .BLUE )
147
+ self ._log .info (f"{ self .check_order_timeout_secs = } " , LogColor .BLUE )
146
148
147
149
# Clients
148
150
self ._client : BetfairHttpClient = client
@@ -843,25 +845,29 @@ def check_cache_against_order_image(self, order_change_message: OCM) -> None:
843
845
raise RuntimeError (f"UNKNOWN FILL: { instrument_id = } { matched_order } " )
844
846
845
847
async def _check_order_update (self , unmatched_order : UnmatchedOrder ) -> None :
846
- """
847
- Ensure we have a client_order_id, instrument and order for this venue order
848
- update.
849
- """
848
+ # We may get an order update from the socket before our submit_order response has
849
+ # come back (with our bet_id).
850
+ #
851
+ # As a precaution, wait up to `check_order_timeout_seconds` for the bet_id to be added
852
+ # to cache.
850
853
venue_order_id = VenueOrderId (str (unmatched_order .id ))
851
- client_order_id = await self .wait_for_order (venue_order_id , timeout_secs = 10.0 )
854
+ client_order_id = await self ._wait_for_order (venue_order_id , self . check_order_timeout_secs )
852
855
if client_order_id is None :
853
- self ._log .warning (f"Can't find client_order_id for { unmatched_order } " )
856
+ self ._log .warning (
857
+ f"Failed to find ClientOrderId for { venue_order_id !r} "
858
+ f"after { self .check_order_timeout_secs } seconds, unmatched order: { unmatched_order } " ,
859
+ )
854
860
return
855
861
862
+ self ._log .debug (f"Found { client_order_id !r} for { venue_order_id !r} " )
863
+
856
864
order = self ._cache .order (client_order_id = client_order_id )
857
865
PyCondition .not_none (order , "order" )
858
866
instrument = self ._cache .instrument (order .instrument_id )
859
867
PyCondition .not_none (instrument , "instrument" )
860
868
861
869
def _handle_stream_executable_order_update (self , unmatched_order : UnmatchedOrder ) -> None :
862
- """
863
- Handle update containing 'E' (executable) order update.
864
- """
870
+ # Handle update containing 'E' (executable) order update
865
871
venue_order_id = VenueOrderId (str (unmatched_order .id ))
866
872
client_order_id = self ._cache .client_order_id (venue_order_id = venue_order_id )
867
873
PyCondition .not_none (client_order_id , "client_order_id" )
@@ -1007,33 +1013,23 @@ def _handle_stream_execution_complete_order_update(
1007
1013
# This execution is complete - no need to track this anymore
1008
1014
del self ._published_executions [client_order_id ]
1009
1015
1010
- async def wait_for_order (
1016
+ async def _wait_for_order (
1011
1017
self ,
1012
1018
venue_order_id : VenueOrderId ,
1013
- timeout_secs : float = 10.0 ,
1019
+ timeout_secs : float ,
1014
1020
) -> ClientOrderId | None :
1015
- """
1016
- We may get an order update from the socket before our submit_order response has
1017
- come back (with our bet_id).
1018
-
1019
- As a precaution, wait up to `timeout_seconds` for the bet_id to be added
1020
- to cache.
1021
-
1022
- """
1023
1021
try :
1024
1022
PyCondition .type (venue_order_id , VenueOrderId , "venue_order_id" )
1025
1023
1024
+ timeout_ns = secs_to_nanos (timeout_secs )
1026
1025
start = self ._clock .timestamp_ns ()
1027
1026
now = start
1028
- while (now - start ) < secs_to_nanos ( timeout_secs ) :
1027
+ while (now - start ) < timeout_ns :
1029
1028
client_order_id = self ._cache .client_order_id (venue_order_id )
1030
1029
if client_order_id :
1031
1030
return client_order_id
1032
1031
await asyncio .sleep (0.01 )
1033
1032
now = self ._clock .timestamp_ns ()
1034
- self ._log .warning (
1035
- f"Failed to find venue_order_id: { venue_order_id } after { timeout_secs } seconds" ,
1036
- )
1037
1033
except asyncio .CancelledError :
1038
1034
self ._log .debug ("Canceled task 'wait_for_order'" )
1039
1035
return None
0 commit comments