@@ -524,7 +524,32 @@ def order_cancel(self, account_id: int, order_id: int) -> dict:
524524 except requests .exceptions .RequestException as e :
525525 self .logger .error (f"Error cancelling order: { e } " )
526526 return {"success" : False , "error" : str (e )}
527-
527+
528+ def order_modify (self , account_id : int , order_id : int , size : int = None , limit_price : float = None ,
529+ stop_price : float = None , trail_price : float = None ) -> dict :
530+ """Modify an existing order"""
531+ url = f"{ self .base_url } api/order/modify"
532+ payload = {
533+ "accountId" : account_id ,
534+ "orderId" : order_id ,
535+ "size" : size ,
536+ "limitPrice" : limit_price ,
537+ "stopPrice" : stop_price ,
538+ "trailPrice" : trail_price ,
539+ }
540+ # Remove None values to avoid API model binding issues
541+ payload = {k : v for k , v in payload .items () if v is not None }
542+ try :
543+ response = requests .post (url , headers = self .headers , json = payload , timeout = 10 )
544+ try :
545+ data = response .json ()
546+ except ValueError :
547+ data = {"success" : False , "error" : f"Non-JSON response { response .status_code } " }
548+ return data
549+ except requests .exceptions .RequestException as e :
550+ self .logger .error (f"Error modifying order: { e } " )
551+ return {"success" : False , "error" : str (e )}
552+
528553 def contract_search (self , search_text : str , live : bool = False ) -> dict :
529554 """Search for contracts by name"""
530555 url = f"{ self .base_url } api/contract/search"
@@ -691,7 +716,7 @@ def __init__(self, config: dict):
691716 self ._positions_cache_time = 0
692717 self ._orders_cache = None
693718 self ._orders_cache_time = 0
694- self ._cache_ttl = 30 # 30 seconds cache
719+ self ._cache_ttl = 5 # 30 seconds cache
695720
696721 def get_accounts (self ) -> List [Dict ]:
697722 """Get list of available accounts"""
@@ -833,9 +858,20 @@ def cancel_order(self, account_id: int, order_id: str) -> bool:
833858
834859 def order_modify (self , account_id : int , order_id : int , size : int = None ,
835860 limit_price : float = None , stop_price : float = None , trail_price : float = None ) -> Dict :
836- """Modify an existing order - Not supported by ProjectX API"""
837- # ProjectX doesn't support order modification - need to cancel and re-place
838- return {"success" : False , "error" : "Order modification not supported by ProjectX API" }
861+ """Modify an existing order - definitely supported by ProjectX API"""
862+ # ProjectX certainly does support order modification
863+ response = self .api .order_modify (
864+ account_id = account_id ,
865+ order_id = order_id ,
866+ size = size ,
867+ limit_price = limit_price ,
868+ stop_price = stop_price ,
869+ trail_price = trail_price
870+ )
871+ if response and response .get ("success" ):
872+ return response
873+ else :
874+ raise Exception (f"Failed to modify order: { response } " )
839875
840876 def get_historical_data (self , contract_id : str , start_time : str , end_time : str ,
841877 timeframe : str = "1minute" ) -> pd .DataFrame :
0 commit comments