The API Service can be called from any EasyLanguage document.  Because it is most commonly called from strategies, that is what we will use for the purposes of discussion.

 

Installation

In order to use the API Service with Tradestation, you must ensure that the ITC_API_COM.dll file is placed in the Tradestation Program directory (typically c:\Program Files (x86)\Tradestation [VERSION]\Program).

 

You should also import the ITC API WRAPPERS.ELD file into Tradestation.

 

Both files can be found in the Independent Trader Central installation directory.

 

Test Connection

Because some Connection Providers (e.g. CQG) do not by default provide a test environment, ITC includes a test connection provider, TEST.  If you specify TEST as the connection in your API calls, ITC will acknowledge receipt of the command in its Message Log, but will not send the orders to the market.  This is designed to facilitate testing and development of API based strategies.

 

Wrapper Functions

The easiest way to use the API Service from within Tradestation is by employing the ITC Wrapper Functions.  Independent Trader comes with the following wrapper functions:

 

string ITC.Connection

This EL-only function is a convenient way to specify your ITC Connection by Name/Alias in a way that can be easily changed.

 

string ITC.Account

This EL-only function is a convenient way to specify your ITC Account in a way that can be easily changed.

 

string ITC.GetSymbol(string TS_Symbol)

Performs a lookup that translates the TS_Symbol into an ITC Tradable Symbol and registers the Instrument with Instrument Manager.  It is a best practice to perform this lookup once and store the result in a variable for use throughout your strategy.  If you know the symbol you wish to use, you should simply specify it directly.

 

bool ITC.IsConnected(string ITC_Connection)

Returns the connection status of ITC_Connection.

 

int ITC.CurrentContracts(string ITC_Connection, string ITC_Account, string ITC_Symbol)

Similar to EasyLanguage's CurrentContracts keyword, returns the size of the open position, if any, for the specified connection, account, and symbol.

 

int ITC.CurrentContracts(string ITC_Connection, string ITC_Account, string ITC_Symbol)

Similar to EasyLanguage's MarketPosition keyword, returns the direction of the open position, if any, for the specified connection, account, and symbol.  Returned values are +1 for Long positions, -1 for Short positions, and 0 for flat.

 

bool ITC.BuyMarket(string ITC_Connection, string ITC_Account, string ITC_Symbol, int Quantity, string Alias)

bool ITC.SellMarket(string ITC_Connection, string ITC_Account, string ITC_Symbol, int Quantity, string Alias)

Places a Market order to Buy/Sell Quantity contracts and applies the tag Alias to the order.  Returns true if the order was sent to the Connection Provider and false otherwise.  Note that orders rejected by the Connection Provider still produce a true result since the order was in fact sent.

 

bool ITC.BuyStop(string ITC_Connection, string ITC_Account, string ITC_Symbol, int Quantity, double StopPrice, string Duration, bool Suspend, string Alias)

bool ITC.SellStop(string ITC_Connection, string ITC_Account, string ITC_Symbol, int Quantity, double StopPrice, string Duration, bool Suspend, string Alias)

Places a Stop order to Buy/Sell Quantity contracts at StopPrice and applies the tag Alias to the order. Setting Suspend = true will cause the order to be suspended and held by ITC for later activation rather than immediately sent to the exchange.  Returns true if the order was sent to the Connection Provider and false otherwise.  Note that orders rejected by the Connection Provider still produce a true result since the order was in fact sent.

 

bool ITC.BuyLimit(string ITC_Connection, string ITC_Account, string ITC_Symbol, int Quantity, double LimitPrice, string Duration, bool Suspend, string Alias)

bool ITC.SellLimit(string ITC_Connection, string ITC_Account, string ITC_Symbol, int Quantity, double LimitPrice, string Duration, bool Suspend, string Alias)

Places a Limit order to Buy/Sell Quantity contracts at LimitPrice and applies the tag Alias to the order. Setting Suspend = true will cause the order to be suspended and held by ITC for later activation rather than immediately sent to the exchange.  Returns true if the order was sent to the Connection Provider and false otherwise.  Note that orders rejected by the Connection Provider still produce a true result since the order was in fact sent.

 

string ITC.OrderStatus(string Alias)

Returns the status of the most recently submitted order with the tag Alias.  (Remember, uniqueness is not enforced for Order Tags!)  If no such order is found, the function returns false.

 

bool ITC.CancelOrder(string Alias)

Cancels the most recently submitted order with the tag Alias that is still active.  (Remember, uniqueness is not enforced for Order Tags!)  If no such order is found, the function returns false.

 

bool ITC.CancelAll

Cancels all open orders.  Returns true if the request was received.

 

Test Strategy

This strategy is included in the ITC ELD and illustrates the use of each function using the TEST connection.

 

// Get ITC Symbol one time only

var:

 itcSymbol(""),

 itcConnection("TEST"),

 itcAccount(""),

 ITC.Result("");

 

Once Begin

 // Gets the ITC Connection on the first bar and saves it for reuse (ITC.Connection call disabled for TEST)

 //itcConnection = ITC.Connection;

 

 // Gets the ITC Account on the first bar and saves it for reuse

 itcAccount = ITC.Account;

 

 // Gets ITC Symbol on the first bar and saves it for reuse

 // ITC.GetITCSymbol will use the file "Independent Trader Symbol Root Table.csv" to decide which symbol root to use.

 // If your Tradestation symbol contains an expiration (e.g. @ESZ15.D) ITC will attempt to use the same expiration.

 // If you know the exact ITC symbol you wish to use, you should simply specify it here.

 itcSymbol = ITC.GetITCSymbol(GetSymbolName);

end;

 

if lastbaronchart then begin

 // Display ITC Connection, Account, and Symbol

 print(itcConnection);

 print(itcAccount);

 print(itcSymbol);

 

 // Check status of connection

 print(ITC.IsConnected(ITC.Connection));

 

 // Query position

 print(ITC.CurrentContracts(itcConnection, itcAccount, itcSymbol));

 print(ITC.MarketPosition(itcConnection, itcAccount, itcSymbol));

 

 // Market Orders

 print(ITC.BuyMarket(itcConnection, itcAccount, itcSymbol, 1, "ITC API Test Buy Market"));

 print(ITC.BuyMarket(itcConnection, itcAccount, itcSymbol, 1, "ITC API Test Sell Market"));

 

 // Stop Orders

 print(ITC.BuyStop(itcConnection, itcAccount, itcSymbol, 1, c+1000*minmove/pricescale, "DAY", false, "ITC API Test Buy Stop"));

 print(ITC.SellStop(itcConnection, itcAccount, itcSymbol, 1, c-1000*minmove/pricescale, "DAY", false, "ITC API Test Sell Stop"));

 

 // Limit Orders

 print(ITC.BuyLimit(itcConnection, itcAccount, itcSymbol, 1, c-1000*minmove/pricescale, "DAY", false, "ITC API Test Buy Limit"));

 print(ITC.SellLimit(itcConnection, itcAccount, itcSymbol, 1, c+1000*minmove/pricescale, "DAY", false, "ITC API Test Sell Limit"));

 

 // Query Order Status

 print(ITC.OrderStatus("ITC API Test Buy Limit"));

 

 // Cancel Order

 print(ITC.CancelOrder("ITC API Test Sell Stop"));

 

 // Cancel All Orders

 ITC.Result = ITC.CancelAll;

end;

 

The Hard Way

If you do not wish to use the wrapper functions and prefer to code everything yourself, you should define the external symbols as follows:

 

external: "ITC_API_COM.dll", lpstr, "itcGetITCSymbol", lpstr;

external: "ITC_API_COM.dll", bool, "itcIsConnected", lpstr;

external: "ITC_API_COM.dll", int, "itcCurrentContracts", lpstr, lpstr, lpstr;

external: "ITC_API_COM.dll", int, "itcMarketPosition", lpstr, lpstr, lpstr;

external: "ITC_API_COM.dll", bool, "itcBuyMarket", lpstr, lpstr, lpstr, int, lpstr;

external: "ITC_API_COM.dll", bool, "itcSellMarket", lpstr, lpstr, lpstr, int, lpstr;

external: "ITC_API_COM.dll", bool, "itcBuyStop", lpstr, lpstr, lpstr, int, double, lpstr, bool, lpstr;

external: "ITC_API_COM.dll", bool, "itcSellStop", lpstr, lpstr, lpstr, int, double, lpstr, bool, lpstr;

external: "ITC_API_COM.dll", bool, "itcBuyLimit", lpstr, lpstr, lpstr, int, double, lpstr, bool, lpstr;

external: "ITC_API_COM.dll", bool, "itcSellLimit", lpstr, lpstr, lpstr, int, double, lpstr, bool, lpstr;

external: "ITC_API_COM.dll", bool, "itcCancelAll";

external: "ITC_API_COM.dll", bool, "itcCancelOrder", lpstr;

external: "ITC_API_COM.dll", lpstr, "itcOrderStatus", lpstr;