1818# TWAP Configuration
1919TWAP_DURATION = 300 # minimum is 300 seconds
2020# Interval must be in range [30 (30 seconds), 3600 (1 hour)] AND must be a factor of duration
21- TWAP_INTERVAL = 60 # minimum is 30 seconds, must be factor of duration
21+ TWAP_INTERVAL = 60 # minimum is 30 seconds, must be factor of duration
2222TWAP_PRICE_TOLERANCE = 10000 # 1% tolerance (10,000 ppm) - valid range [0, 1_000_000)
2323MONITORING_INTERVAL = 2 # Check position changes every 2 seconds
2424
@@ -84,7 +84,9 @@ async def place_and_track_twap_order(size: float):
8484 if initial_position :
8585 print (f" Market: { MARKET_ID } " )
8686 print (f" Size: { initial_size :.6f} " )
87- print (f" Direction: { 'LONG' if is_long else 'SHORT' if initial_size < 0 else 'NONE' } " )
87+ print (
88+ f" Direction: { 'LONG' if is_long else 'SHORT' if initial_size < 0 else 'NONE' } "
89+ )
8890 else :
8991 print (f" No open position for { MARKET_ID } " )
9092 print ()
@@ -95,9 +97,7 @@ async def place_and_track_twap_order(size: float):
9597 print ()
9698
9799 # Create order ID
98- order_id = market .order_id (
99- TEST_ADDRESS , 0 , unique_client_id , OrderFlags .SHORT_TERM
100- )
100+ order_id = market .order_id (TEST_ADDRESS , 0 , unique_client_id , OrderFlags .SHORT_TERM )
101101
102102 current_block = await node .latest_block_height ()
103103
@@ -118,7 +118,8 @@ async def place_and_track_twap_order(size: float):
118118 price = 0 , # Market order
119119 time_in_force = Order .TimeInForce .TIME_IN_FORCE_UNSPECIFIED ,
120120 reduce_only = False ,
121- good_til_block = current_block + 30 , # Must be within ShortBlockWindow limit (40 blocks max)
121+ good_til_block = current_block
122+ + 30 , # Must be within ShortBlockWindow limit (40 blocks max)
122123 twap_duration = TWAP_DURATION ,
123124 twap_interval = TWAP_INTERVAL ,
124125 twap_price_tolerance = TWAP_PRICE_TOLERANCE ,
@@ -160,7 +161,9 @@ async def place_and_track_twap_order(size: float):
160161 current_position = pos
161162 break
162163
163- current_size = float (current_position .get ("size" , 0 )) if current_position else 0.0
164+ current_size = (
165+ float (current_position .get ("size" , 0 )) if current_position else 0.0
166+ )
164167
165168 # Check if position changed
166169 if abs (current_size - last_position_size ) > 0.000001 :
@@ -238,7 +241,9 @@ async def place_and_track_twap_order(size: float):
238241 f"Total Change: { change ['total_change' ]:+.6f} "
239242 )
240243 else :
241- print ("No position changes detected (order may still be executing or no changes occurred)" )
244+ print (
245+ "No position changes detected (order may still be executing or no changes occurred)"
246+ )
242247
243248 print ()
244249 print ("=" * 80 )
0 commit comments