Profile Picture

Does RE work fully with Interactive Broker?

Posted By liemingtang 8 Years Ago
Message
Posted Thursday January 29 2009
I have an interactive brokers account and I am trying out right edge with my paper trading account.

I wrote a very simple system (demo) to see whether RE works with IB's Trader Workstation and the only thing the code works on is submitting an order. I.e., I can see in TWS the order being submitted. However, I can't see any Pending, Closed or Open orders through my demo system (via OpenPositions).

I suspect that the PositionManager or part of RE that is not updating position/order data from TWS. Is anyone else getting this error? Does RE work with IB?

Here very simple bit of code in the new bar function
-----------
this.Trader.OpenLongPosition();
System.Console.WriteLine("Positions O:"+this.OpenPositions.Count+" C:"+this.ClosedPositions.Count+" P:"+this.PendingPositions.Count);
------------

Output is always..."Positions: O:0 C:0 P:0"

I also tried PositionManager.CloseAllPositions() which does nothing...

Posted Thursday January 29 2009
This is a pretty fundamental piece and I assure you that it works.  It sounds like there is something preventing communication between RightEdge and TWS.  Are you receiving ticks all right?  Do you have any firewall or anti-virus software running?

Do you receive any error the OpenPosition call?  Exceptions?

liemingtang (1/29/2009)
I have an interactive brokers account and I am trying out right edge with my paper trading account.

I wrote a very simple system (demo) to see whether RE works with IB's Trader Workstation and the only thing the code works on is submitting an order. I.e., I can see in TWS the order being submitted. However, I can't see any Pending, Closed or Open orders through my demo system (via OpenPositions).

I suspect that the PositionManager or part of RE that is not updating position/order data from TWS. Is anyone else getting this error? Does RE work with IB?

Here very simple bit of code in the new bar function
-----------
this.Trader.OpenLongPosition();
System.Console.WriteLine("Positions O:"+this.OpenPositions.Count+" C:"+this.ClosedPositions.Count+" P:"+this.PendingPositions.Count);
------------

Output is always..."Positions: O:0 C:0 P:0"

I also tried PositionManager.CloseAllPositions() which does nothing...

Posted Friday January 30 2009
The ticks appear to be coming in as I print the incoming new bar data prior to the position code so the connection appears to be working.

Also, in the live tab I cannot see any pending / open / closed positions when i start the system and the first order is submitted.

is there some function that is called that gets data from TWS? Is there a version compatibility issue? I am using TWS 4.1 desktop version their latest version.
Posted Friday January 30 2009
What bar frequency are you using?  When is your system submitting orders?  What are you seeing in TWS that makes you think the order has been submitted?  Generally the orders will show up in TWS under an API tab.

Thanks,
Daniel

Posted Saturday January 31 2009
I'm using 1min bar frequency with a forex symbol and submitting the orders after the 2nd minute.

In addtion to printing to console new bar data i can also see updates under the live data tab which leads me to believe that live data is coming in.

I know the orders have reached TWS because the opened order does appear to show up in the API tab as you said. Moreover, the trade is identified in the Trades list. However, it does not appear to be recognised or notified or something by right edge once its been submitted to TWS because GetOpenPositions().count, GetClosedPositions().count, GetPendingPositions().count are all 0 and also the live systems tabs shows no records.

Its very strange that this would happen since it submits orders and updates tick data but why not update position information? How does PositionManager work with respects to updates? Does it get the updated position info from TWS api at regular intervals by polling it?
Posted Monday February 02 2009
Here is the code I am using to test this using the cross over function and only change is the new bar function shown below. It will open a long position after 2 min new bar and prints out the info on this position. The output of this is below.

I updated the sample CrossOver system to test this...

   int counter = 1;
   Position pos ;
   
   public override void NewBar()
   {
      if (counter == 2)
      {
         System.Console.WriteLine("Open Pos");
         pos = this.OpenPosition(PositionType.Long, OrderType.Market,this.Bars.Current.Open,1);
      }

      System.Console.WriteLine("New Bar:"+this.Bars.Current.Open+" time:"+this.Bars.Current.PriceDateTime.ToString());

      if (pos != null)
      {
         Position p = this.PositionManager.GetPosition(pos.ID);   
         System.Console.WriteLine("Get pos ID "+pos.ID+" State:"+p.State.ToString());
      }

      counter++;
   }

----- System output after 4 min (EUR/USD) -----

2   New Bar:1.2733 time:2/02/2009 9:05:00 PM   2/02/2009 21:14
2   Open Pos   2/02/2009 21:15
2   New Bar:1.2736 time:2/02/2009 9:14:00 PM   2/02/2009 21:15
2   Get pos ID 1 StateTongueending   2/02/2009 21:15
2   IB Warning code 2109 for order ID 15: Order Event Warning:Attribute 'Outside Regular Trading Hours' is ignored based on the order type and destination. PlaceOrder is now being processed.   2/02/2009 21:15
2   New Bar:1.274 time:2/02/2009 9:15:00 PM   2/02/2009 21:15
2   Get pos ID 1 State:None   2/02/2009 21:15
2   New Bar:1.27385 time:2/02/2009 9:16:00 PM   2/02/2009 21:16
2   Get pos ID 1 State:None   2/02/2009 21:16


Posted Monday February 02 2009
It looks like there is an error most of the time when you try to open a position.  Use the following code to see what it is:

Position pos = OpenPosition(...);
if (pos.Error != null)
{
   OutputMessage("order failed : " + pos.Error);
}

Also, you don't need to call PositionManager.GetPosition(ID), the return value from OpenPosition will be the same object.

Thanks,
Daniel

Posted Monday February 16 2009
I don't think there is an error but I tried to output the error message with the code and it shows that the order was submitted ok as shown below. The only thing here is the warning about timezone which appears to be ignored due to its forex.

-------------------
2   New Bar:1.2763 time:16/02/2009 10:21:00 PM   EUR/USD   Symbol Script   16/02/2009 11:02:00 PM
2   Open Position...   EUR/USD   Symbol Script   16/02/2009 11:03:02 PM
2   Order successful   EUR/USD   Symbol Script   16/02/2009 11:03:02 PM
2   New Bar:1.27615 time:16/02/2009 11:02:00 PM   EUR/USD   Symbol Script   16/02/2009 11:03:02 PM
2   # Open Positions: 0, # Close Positions: 0, # Pending Positions: 1   EUR/USD   Symbol Script   16/02/2009 11:03:02 PM
2   IB Warning code 2109 for order ID 19: Order Event Warning:Attribute 'Outside Regular Trading Hours' is ignored based on the order type and destination. PlaceOrder is now being processed.         16/02/2009 11:03:02 PM
2   New Bar:1.2762 time:16/02/2009 11:03:00 PM   EUR/USD   Symbol Script   16/02/2009 11:04:00 PM
2   # Open Positions: 0, # Close Positions: 0, # Pending Positions: 0   EUR/USD   Symbol Script   16/02/2009 11:04:00 PM
2   New Bar:1.27615 time:16/02/2009 11:04:00 PM   EUR/USD   Symbol Script   16/02/2009 11:05:23 PM
2   # Open Positions: 0, # Close Positions: 0, # Pending Positions: 0   EUR/USD   Symbol Script   16/02/2009 11:05:23 PM
2   # Open Positions: 0, # Close Positions: 0, # Pending Positions: 0   EUR/USD   Symbol Script   16/02/2009 11:06:00 PM
2   New Bar:1.2762 time:16/02/2009 11:05:00 PM   EUR/USD   Symbol Script   16/02/2009 11:06:00 PM
-------------------

Could someone point me to the IB plugin code? I can see the dll but not the code and I can't really work out what the position manager is doing behind the scene with its getting positions. Basically I don't know hot to identify / narrow down the error?
Posted Monday February 16 2009
Something still isn't adding up.  Can you hook into the OrderFilled and OrderCancelled methods and output the "information" parameter to see if we get any clues there?

The IB plugin is based off of krs socket client.  The PositionManager is internal and the source code is not available.

Posted Friday March 20 2009
What was the resolution to this, because I'm still having this problem with various futures symbols in IB.  I hoped upgrading to 383 would help, but no luck.

The problem I get is the order is submitted to TWS, it appears in TWS API tab and Portfolio tab as an "untransmitted" order.  RightEdge has no entry in either the pending, open or closed tabs at all.

I get the "outside of regular trading hours" warning on all these as well. 



Similar Topics


Reading This Topic


2005-2017 © RightEdge Systems