Sterling API "access all open positions"

Discussion in 'Automated Trading' started by WhiteOut56, Mar 8, 2011.

  1. Basically what I'm interested in doing is accessing all open positions in sterling and sending a market order to close the position


    How do you do this via the sterling API (to access all open positions) get the sides and the # of shares?

    Thanks
     
  2. You can do this in tradelink which is 100% free and open source, works with sterling and many other brokers :

    http://tradelink.googlecode.com

    here is the code to do this in a strategy/response :

    Code:
    public class MyResponse : ResponseTemplate
    {
      // runs when you start the strategy
      override void Reset()
      { 
          foreach (Position p in pt)
             sendorder(new MarketOrderFlat(p));
      }
      PositionTracker pt = new PositionTracker();
       override void GotPosition(Position p)
      {
         pt.Adjust(p);
      }
    }
    

    here is the code to do this in an exe application
    Code:
    public static class Program
    {
        static TLClient tl = new TLClient_WM();
        static PositionTracker pt = new PositionTracker();
         public static void Main(string[] args)
         {
               tl.gotPosition+=new PositionDelegate(pt.Adjust);
               tl.RequestPositions();
               // wait for positions to arrive
               System.Threading.Thread.Sleep(500);
               // close all flat positions
               foreach (Position p in pt)
                   tl.SendOrder(new MarketOrderFlat(p));
         }
    }
    
    http://tradelink.googlecode.com
     
  3. DGunz

    DGunz

    All the Screentoaster video tutorials are down, are there plans to reupload these to youtube? Some of the most important "how to" videos can't be accessed.

    Thanks.
     
  4. Yes we are in process of moving the ones not already on youtube