6.3.2 TWS API v9.72 線上文件 ——修改訂單【翻譯】
Modifying Orders
Modification of an API order can be done if the API client is connected to a session of TWS with the same username of TWS and using the same API client ID. The function IBApi.EClient.placeOrder can then be called with the same fields as the open order, except for the parameter to modify. This includes the IBApi.Order.OrderId, which must match the IBApi.Order.OrderId of the open order. It is not generally recommended to try to change order fields aside from order price, size, and tif (for DAY -> IOC modifications). To change other parameters, it might be preferable to instead cancel the open order, and create a new one.
【譯】修改API訂單,需要使用同一個TWS賬號和客戶端ID,在TWS連線會話中修改訂單。函式
IBApi.EClient.placeOrder 提交訂單欄位和引數對訂單進行修改。它包含了 IBApi.Order.OrderId,但是OrderID必須和已提交的(正在交易中的)訂單相匹配。通常不建議使用該方法修改訂單的屬性,更為常見的方法是取消原來的訂單,然後建立一個新的。
To modify or cancel an individual order placed manually from TWS, it is necessary to connect with client ID 0 and then bind the order before attempting to modify it. The process of binding assigns the order an API order ID; prior to binding it will be returned to the API with an API order ID of 0. Orders with API order ID 0 cannot be modified/cancelled from the API.
The function reqOpenOrders binds orders open at that moment which do not already have an API order ID, and the function reqAutoOpenOrders binds future orders automatically. The function reqAllOpenOrders does not bind orders. To modify API orders when connecting to a different session of TWS (logged in with a different username than used for the original order), it is necessary to first bind the order with client ID 0 in the same manner as manual TWS orders are bound before they can be modified. The binding assignment of API order IDs is independent for each TWS user, so the same order can have different API order IDs for different users. The permID returned in the API Order class which is assigned by TWS can be used to identify an order in an account uniquely.
Currently (as of TWS version 970) the process of order binding from the API cancels/resubmits an order working on an exchange. This may affect the order’s place in the exchange queue. Enhancements are planned to allow for API binding with modification of exchange queue priority.
【譯】從TWS中修改或取消一個獨立的訂單,需要使用 Client ID 0,並且在修改前使用API order ID捆綁訂單。從TWS API獲取 API Order ID,然後把API ID和訂單捆綁起來。使用API Order ID 0的訂單,是不能被取消或修改的。函式reqOpenOrders可以捆版的訂單僅限於那些還沒有API Order ID的訂單,而reqAutoOpenOrders則可以自動捆綁期貨訂單。reqAllOpenOrders 不繫結任何訂單。
從不同的TWS會話中修改API訂單(使用不同的使用者命登入TWS操作同一個訂單),需要手動使用client ID 0繫結訂單以鎖定訂單。使用API order ID繫結作業對於每個TWS使用者來說是獨立的,因此對於同一個訂單會有不同的API order ID。從API Order類返回的permID由TWS賦值,可以用於某賬號中的訂單的單一標識碼。
當前(TWS version 970)處理訂單的取消/重提交,由交易所完成這些過程。可能會導致訂單的交易順序發生改變。在計劃中的加強的方法,將允許修改訂單的交易順序,以避免這個問題。