Navigation

    Backtrader Community

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    1. Home
    2. albertzgd
    For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/
    A
    • Profile
    • Following 0
    • Followers 0
    • Topics 3
    • Posts 10
    • Best 0
    • Groups 0

    albertzgd

    @albertzgd

    0
    Reputation
    398
    Profile views
    10
    Posts
    0
    Followers
    0
    Following
    Joined Last Online

    albertzgd Unfollow Follow

    Latest posts made by albertzgd

    • RE: Is it possible to retrieve all the open/active orders from Interactive Broker?

      @backtrader Thanks for your reply.

      If I just want to have this capability to monitor all the open orders in IB, and don't care about messing up with the calculations, would you please give me some guides on how I can implement it? I've been trying to read and understand the relevant source codes, but have some difficulty in connecting everything together and figure out exactly what to do.

      Thanks a lot.

      posted in General Discussion
      A
      albertzgd
    • RE: Is it possible to retrieve all the open/active orders from Interactive Broker?

      Got it, Thanks for your reply.

      So the calculations will also be incorrect if there is already a position before Cerebro start running, right?

      posted in General Discussion
      A
      albertzgd
    • Is it possible to retrieve all the open/active orders from Interactive Broker?

      All my strategies will place bracket order, i.e., an order to get into a position, a limit order to get out of the position and take profit, and a stop order to get out of the position and limit loss. I also allow my strategy to generate signals to exit positions, and when that happens, the limit order and stop order need to be canceled otherwise they will enter an unwanted position.

      My solution now is I keep a reference to all the orders I placed, so when I need to cancel any of them, I just use the reference number. This works when my program and IB are both running, but one issue arose during my testing, that is if I connect my program to IB when there are open limit/stop loss orders, I won't be able to reference them, therefore won't be able to cancel them when needed, and later on they will be executed and give me unwanted positions.

      My thought is if I can retrieve all the open/active orders from IB, then I will be in full control. From IB API's documentation: https://interactivebrokers.github.io/tws-api/open_orders.html

      I see they support this functionality through API, also with backtrader broker I see there is a method called get_orders_open() which gives me exactly what I want, however, I have difficulty finding the corresponding method with ibbroker.

      Would anyone please help me solve this issue?

      Thanks a lot.

      posted in General Discussion
      A
      albertzgd
    • RE: Is there way to track open orders with IB broker?

      Besides, the reason why I get a bunch of unexecuted and uncanceled orders is that short is not allowed for equities in the demo system during the time I tested my code(I don't know if this is temporary or in demo system, one just can't short equities).

      So all the short orders are held. Held orders will not show as pending orders.

      posted in General Discussion
      A
      albertzgd
    • RE: Is there way to track open orders with IB broker?

      I found the solution by reading backtrader's source code.

      In case anyone is interested, strategy class has a data attribute ._orderspending that contains all the pending orders.

      Edit: This doesn't really work.

      posted in General Discussion
      A
      albertzgd
    • Is there way to track open orders with IB broker?

      I am testing my code with live paper trading with Interactive Broker. My strategies always create a profit-taking limit order and a stop loss order whenever a position is entered. I ran my code with backtesting broker and everything is fine, however, when I ran it with IB broker, I get the error message of:

      ***** STORE NOTIF: <error id=2184, errorCode=201, errorMsg=Order rejected - reason: Your account has a minimum of 15 orders working on either the buy or sell side for this particular contract. An additional order on the same side for this contract will not be allowed until an existing order has been canceled or has executed. Please call the Trade Desk for further details.>

      I am suspecting this may be due to the profit taking orders and stop loss orders not canceled properly. For debugging purposes, I would like to track the open(pending) orders. With backtesting broker, I can do self.broket.pendings, is there an equivalent method in ib broker?

      Thanks in advance for any information.

      posted in General Discussion
      A
      albertzgd
    • RE: Paper trading with Interactive Broker, how to request delayed data?

      @ab_trader I tried backfill_start=False, and it didn't solve the problem.

      I did manage to get delayed streaming data with only Ibpy, but it came with a very weird format and I don't know how to hook it with backtrader.

      posted in General Discussion
      A
      albertzgd
    • RE: Paper trading with Interactive Broker, how to request delayed data?

      @ab_trader Thanks very much for your reply.

      I know I don't have subscription to the data, but interactive broker still provides 10-15 minutes delayed streaming data for those who don't have subscriptions. I just want to work with this free delayed streaming data before I pay to get market data subscription.

      posted in General Discussion
      A
      albertzgd
    • RE: Paper trading with Interactive Broker, how to request delayed data?

      @backtrader Thank you very much for your reply.

      However, as I read from https://interactivebrokers.github.io/tws-api/delayed_data.html

      It seems that one can get delayed streaming data from TWS vis the API. After the connection object gets connected with TWS, it does have a method named reqMarketDataType, which after I called in the ibstore class, did get rid of the error message :<error id=16777217, errorCode=10168, errorMsg=Requested market data is not subscribed. Delayed market data is not enabled>, but still didn't provide me any streaming data.

      Is that IB API documentation outdated? Or I didn't understand it correctly?

      Thank you again for your kind help.

      posted in General Discussion
      A
      albertzgd
    • Paper trading with Interactive Broker, how to request delayed data?

      Hi All, I've been trying to do paper trading with Bactrader and Interactive Broker. Currently, I only have a paper trading account with no market data subscription so any stock data is delayed for 15 minutes. When I try to request this delayed market data, I get the following error message:

      ***** STORE NOTIF: <error id=-1, errorCode=2104, errorMsg=Market data farm connection is OK:usfuture>
      ***** STORE NOTIF: <error id=-1, errorCode=2104, errorMsg=Market data farm connection is OK:cashfarm>
      ***** STORE NOTIF: <error id=-1, errorCode=2104, errorMsg=Market data farm connection is OK:usfarm.us>
      ***** STORE NOTIF: <error id=-1, errorCode=2104, errorMsg=Market data farm connection is OK:usfarm>
      ***** STORE NOTIF: <error id=-1, errorCode=2106, errorMsg=HMDS data farm connection is OK:cashhmds>
      ***** STORE NOTIF: <error id=-1, errorCode=2106, errorMsg=HMDS data farm connection is OK:ushmds>
      ***** STORE NOTIF: <error id=16777217, errorCode=10168, errorMsg=Requested market data is not subscribed. Delayed market data is not enabled>

      I have been searching online for quite some time but unfortunately, the documentation for both ibpy and ibapi are very lacking and I can't solve this problem. Does anyone know how to solve this issue?

      Many thanks

      posted in General Discussion
      A
      albertzgd