2016-12-22 2 views
0

TWSに置かれたいくつかのポジションを手動で閉じることを試みるibpyを使用すると、これを実行できませんでした。実行時に具体的には、:IBpyは手作業で注文した注文を取り消すことはできません

self._tws.reqAllOpenOrders() 
    sleep(0.2) 

をして、それをクローズしようとすると私たちは

<openOrder orderId=0, contract=<ib.ext.Contract.Contract object at 0x103b78ad0>, order=<ib.ext.Order.Order object at 0x103b78a50>, orderState=<ib.ext.OrderState.OrderState object at 0x103b78b10>> 
<orderStatus orderId=0, status=Submitted, filled=0, remaining=100, avgFillPrice=0.0, permId=134994568, parentId=0, lastFillPrice=0.0, clientId=0, whyHeld=None> 
<openOrder orderId=0, contract=<ib.ext.Contract.Contract object at 0x103b78c90>, order=<ib.ext.Order.Order object at 0x103b78c50>, orderState=<ib.ext.OrderState.OrderState object at 0x103b78cd0>> 
<orderStatus orderId=0, status=Submitted, filled=0, remaining=1, avgFillPrice=0.0, permId=134994562, parentId=0, lastFillPrice=0.0, clientId=0, whyHeld=None> 
<openOrderEnd> 

(私はTWSに手動でplacecdせい)IDが0で注文を取得する:

self._tws.cancelOrder(0) 

または

self._tws.cancelOrder(134994568) 

エラー:

<error id=0, errorCode=135, errorMsg=Can't find order with id =0> 
<error id=134994562, errorCode=135, errorMsg=Can't find order with id =134994562> 

どのように考えればいいですか?ありがとうございました。

答えて

0

注文を新しいクライアントにバインドする必要があります。この方法はtws.reqAutoOpenOrders(True)を使用してください。ドキュメントから、

Finally, IBApi.EClient.reqAutoOpenOrders will allow to obtain those orders manually placed using the TWS itself. This method also allows the client application to take over these orders and modify them by setting the autoBind parameter to true. If successfully bound, The orders will be assigned (i.e. bound to) an API order id and as such be eligible for modification.

client.reqAutoOpenOrders(true); Important: only those applications connecting with client Id 0 will be able to take over manually submitted orders

Through the TWS' API settings it is possible to configure this method's behaviour to some extent. As shown in the image below, manually placed orders can be given a negative order Id which can serve to easily tell manual from API submitted orders. The TWS' tooltip elaborates further:

コールバックは<openOrder orderId=-3,...のようになりますと、あなたはちょうどあなたがTWSで以前に注文、reqAutoOpenOrdersへの呼び出しの後に置くものだけを得ることはありませんtws.cancelOrder(-3)

注意を呼び出します。

+0

ありがとうございました。この質問に答えるのに時間を費やしたいですか? http://stackoverflow.com/questions/41289239/how-could-we-use-ibpy-for-editing-orders –

関連する問題