realtick emsdownload.realtick.com/api/realtick scripting quickstart guide.pdf · realtick ems —...

27
RealTick EMS — RealTick Scripting Quick Start Guide | 2013 RealTick LLC All Rights Reserved 1 RealTick ® EMS Scripting Quick Start Guide Table of Contents Chapter 1: Introduction ......................................................................................................................................... 3 About this Manual .....................................................................................................................................................3 Sections in this Document .........................................................................................................................................3 Scripting Overview ....................................................................................................................................................4 rt332.exe /regserver .............................................................................................................................................4 Process Flow ..............................................................................................................................................................4 Chapter 2: Requirements & Application Settings ................................................................................................... 5 RealTick Requirements ..............................................................................................................................................5 RealTick Application Settings.....................................................................................................................................5 Set System Defaults for Scripting ..........................................................................................................................5 Password Behavior ................................................................................................................................................6 Change the Order Confirmation Status .................................................................................................................7 tal.ini Settings ........................................................................................................................................................7 Chapter 3: Order API Detail ................................................................................................................................... 8 Properties ..................................................................................................................................................................8 Methods ....................................................................................................................................................................8 OnNewTrade() and OnNewTradeEx() Events ......................................................................................................17 OnNewPosition() Event .......................................................................................................................................19 OnNewBalance() Event........................................................................................................................................19 Price Type ............................................................................................................................................................20 Expiration Type....................................................................................................................................................21 Volume Type .......................................................................................................................................................21 Reserve Order .....................................................................................................................................................21 Conditional Orders ..............................................................................................................................................22 Code Examples ....................................................................................................................................................22 Chapter 4: XML Files ............................................................................................................................................ 23 Trading Subdirectory ...........................................................................................................................................23 Statuses ...............................................................................................................................................................23 XML Mapping ......................................................................................................................................................23 Chapter 5: RealTick Permissions State ................................................................................................................. 24 Poll Permissions State .........................................................................................................................................24 Chapter 6: Window Creation/Manipulation......................................................................................................... 25 Functions .............................................................................................................................................................25 Example Code ......................................................................................................................................................26 Chapter 7: System Information ............................................................................................................................ 27

Upload: ngonguyet

Post on 04-Jun-2018

224 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: RealTick EMSdownload.realtick.com/API/RealTick Scripting QuickStart Guide.pdf · RealTick EMS — RealTicK Scripting Quick Start Guide 2013 RealTick LLC All Rights Reserved 3 Chapter

RealTick EMS — RealTick Scripting Quick Start Guide | 2013 RealTick LLC All Rights Reserved 1

RealTick®

EMS

Scripting Quick Start Guide

Table of Contents

Chapter 1: Introduction ......................................................................................................................................... 3 About this Manual ..................................................................................................................................................... 3 Sections in this Document ......................................................................................................................................... 3 Scripting Overview .................................................................................................................................................... 4

rt332.exe /regserver ............................................................................................................................................. 4 Process Flow .............................................................................................................................................................. 4

Chapter 2: Requirements & Application Settings ................................................................................................... 5 RealTick Requirements .............................................................................................................................................. 5 RealTick Application Settings..................................................................................................................................... 5

Set System Defaults for Scripting .......................................................................................................................... 5 Password Behavior ................................................................................................................................................ 6 Change the Order Confirmation Status ................................................................................................................. 7 tal.ini Settings ........................................................................................................................................................ 7

Chapter 3: Order API Detail ................................................................................................................................... 8 Properties .................................................................................................................................................................. 8 Methods .................................................................................................................................................................... 8

OnNewTrade() and OnNewTradeEx() Events ...................................................................................................... 17 OnNewPosition() Event ....................................................................................................................................... 19 OnNewBalance() Event........................................................................................................................................ 19 Price Type ............................................................................................................................................................ 20 Expiration Type .................................................................................................................................................... 21 Volume Type ....................................................................................................................................................... 21 Reserve Order ..................................................................................................................................................... 21 Conditional Orders .............................................................................................................................................. 22 Code Examples .................................................................................................................................................... 22

Chapter 4: XML Files ............................................................................................................................................ 23 Trading Subdirectory ........................................................................................................................................... 23 Statuses ............................................................................................................................................................... 23 XML Mapping ...................................................................................................................................................... 23

Chapter 5: RealTick Permissions State ................................................................................................................. 24 Poll Permissions State ......................................................................................................................................... 24

Chapter 6: Window Creation/Manipulation......................................................................................................... 25 Functions ............................................................................................................................................................. 25 Example Code ...................................................................................................................................................... 26

Chapter 7: System Information ............................................................................................................................ 27

Page 2: RealTick EMSdownload.realtick.com/API/RealTick Scripting QuickStart Guide.pdf · RealTick EMS — RealTicK Scripting Quick Start Guide 2013 RealTick LLC All Rights Reserved 3 Chapter

RealTick EMS — RealTicK Scripting Quick Start Guide 2013 RealTick LLC All Rights Reserved 2

Copyright

This information described herein (“Documentation”) is the copyrighted work of RealTick LLC

(“RealTick”). No title or ownership of intellectual property rights in and to the Documentation or any

copy, translation, compilation or other derivative works are transferred to the end user or any third

party hereunder. The Documentation is deemed to be part of the “Licensed Product” as referred to in

end user agreements between (or applicable to) the user and RealTick. This Documentation may not

be copied or transmitted, in whole or in part, in any form or by any means without the prior express

written consent of RealTick.

© 2013 RealTick LLC. All Rights Reserved.

Content

Information in this document is subject to change without notice. In the event that you are using a

version of any products other than the most recent version, there may be discrepancies between the

content of this documentation and the operation or visual presentation of your older version of the

product. RealTick does not warrant that this documentation is error free.

Trademarks

RealTick® is a registered trademark of RealTick LLC. All other company or product names mentioned

herein are the trademarks or registered trademarks of their respective owners.

Eze Software Group LLC

http://www.ezesoft.com/

Page 3: RealTick EMSdownload.realtick.com/API/RealTick Scripting QuickStart Guide.pdf · RealTick EMS — RealTicK Scripting Quick Start Guide 2013 RealTick LLC All Rights Reserved 3 Chapter

RealTick EMS — RealTicK Scripting Quick Start Guide 2013 RealTick LLC All Rights Reserved 3

Chapter 1: Introduction

About this Manual

This document is intended for third party programmers. It contains instructions for communicating

with RealTick using the COM interface built into rt332.exe.

Sections in this Document

The following table lists the sections available in this document.

Chapter Description

Chapter 1: Introduction Defines scripting and fundamentals concerning RealTick and

scripting.

Chapter 2: Requirements &

Application Settings

Defines requirements and settings in RealTick needed for

scripting.

Chapter 3: Order API Detail Discusses using the RealTick automation interface for Order

Entry.

Chapter 4: XML Files Discusses configuring RealTick to log orders to an XML file.

Chapter 5: RealTick Permissions

State

Provides you with the methods and events to determine if

RealTick is able to receive commands.

Chapter 6: Window

Creation/Manipulation

Describes creating/manipulating child windows in RealTick.

Chapter 7: System Information Defines properties that provide system information.

Page 4: RealTick EMSdownload.realtick.com/API/RealTick Scripting QuickStart Guide.pdf · RealTick EMS — RealTicK Scripting Quick Start Guide 2013 RealTick LLC All Rights Reserved 3 Chapter

RealTick EMS — RealTicK Scripting Quick Start Guide 2013 RealTick LLC All Rights Reserved 4

Scripting Overview

Scripting for RealTick is implemented through Microsoft COM, a popular automation technology that

allows access from many common development environments such as Visual Basic and Visual C++.

The RealTick COM automation interface, also known as RealTick Scripting, allows another application

to tell RealTick to perform actions that would normally require the user to use the mouse or

keyboard.

RealTick (rt332.exe) exposes an out of process COM server, which becomes usable if the RealTick

Scripting permission is present on your RealTick login account. The COM server itself, if

permissioned, can be used by default to implement certain basic communications with RealTick

(discussed in chapters 5-6) and optionally to communicate with the RealTick Order Entry System

(discussed in chapters 3-4). Additional permissions from the brokerage account side may be required

before your client application can use RealTick Scripting to place orders.

If RealTick has been properly installed and registered on your system, you can view the programming

interface of RealTick even if your account is not yet permissioned. The Object Browser in Visual Basic

and Visual Interdev, as well as the COM Object viewer (oleview) will show all properties, methods,

and events. The RealTick COM server implements a single publicly creatable class, Realtick.Realtick

(ProgID: “TAL.Realtick.1”).

To register the RealTick out of process COM server, you must be logged in as Administrator. The

command to register the RealTick COM server is:

rt332.exe /regserver

The RealTick COM server notifies client applications of changes by raising COM events. For example,

RealTick currently fires events pertaining to Order Entry. When an order is filled, three separate

events can be fired to notify the client of the fill, the position change, and the account balance

change.

Process Flow

An order is submitted from the client application to RealTick. The order is received and routed by

RealTick. The status is returned to the client application.

The order information is returned to the application by the OnNewTradeEx event. RealTick passes in

the OrderId (buy or sell), the Symbol traded, the total amount of shares traded, the average price,

and the status of the order.

Client Application RealTick Order filled.

Page 5: RealTick EMSdownload.realtick.com/API/RealTick Scripting QuickStart Guide.pdf · RealTick EMS — RealTicK Scripting Quick Start Guide 2013 RealTick LLC All Rights Reserved 3 Chapter

RealTick EMS — RealTicK Scripting Quick Start Guide 2013 RealTick LLC All Rights Reserved 5

Chapter 2: Requirements & Application Settings

This chapter discusses requirements and settings in RealTick needed for scripting.

RealTick Requirements

The following are the requirements in RealTick you need for scripting:

The current released version of RealTick should be installed.

Scripting is supported for all versions of RealTick after 7.5.13.1.

REALTICK/SCRIPTING permission on RealTick logon

(For Order Entry scripting) REALTICK/ORDERENTRYSCRIPTING permission on RealTick logon

For the Order Entry Scripting capability to work, each separate account that is to be traded by

Scripting must have the AllowScriptedOrders permission.

RealTick Application Settings

The following procedures define settings in RealTick needed for scripting.

Set System Defaults for Scripting

1. Select Scripting from the System Configurator in the Tools menu on the RealTick Title bar. The

Scripting settings dialog box will appear.

Page 6: RealTick EMSdownload.realtick.com/API/RealTick Scripting QuickStart Guide.pdf · RealTick EMS — RealTicK Scripting Quick Start Guide 2013 RealTick LLC All Rights Reserved 3 Chapter

RealTick EMS — RealTicK Scripting Quick Start Guide 2013 RealTick LLC All Rights Reserved 6

2. Click the Allow Scripting check box.

3. Click the Allow Order Entry Scripting check box.

4. If your application will run unattended, check the Allow Unattended Script Orders box. This will

disable all modal forms in RealTick. If your application sends an order that RealTick does not

understand while running unattended, RealTick will throw back a COM exception, which you can

trap in your application.

5. The Require Password for Order Scripting check box should be checked if your application will

submit the correct password with each order placed, as a parameter to the SendOrder() method

call. It is recommended to leave this box checked. If you uncheck this box, the setting cannot be

saved. The box will be checked again the next time you start RealTick and you will have to

uncheck it again.

6. Click OK. The system defaults are set.

Password Behavior

Normally the best option is to check Require Password for Order Scripting and pass the correct

password into each call to SendOrder(). However, this only works if you also passed the same

password into the RealTick Logon dialog box to begin your current session.

Page 7: RealTick EMSdownload.realtick.com/API/RealTick Scripting QuickStart Guide.pdf · RealTick EMS — RealTicK Scripting Quick Start Guide 2013 RealTick LLC All Rights Reserved 3 Chapter

RealTick EMS — RealTicK Scripting Quick Start Guide 2013 RealTick LLC All Rights Reserved 7

Change the Order Confirmation Status

To allow order entry to proceed without user interaction, you may want to change the order

confirmation status.

1. Select Order Entry Properties from the Order Book menu. The Order Entry Properties dialog box

will appear.

2. Select the Warnings/Confirmations option.

3. Verify that Confirm All Trades is NOT checked.

4. Verify that any other Price Warnings or Trade Size Limits that may require user interaction are not

set.

5. Click OK.

The Order Confirmation Status is not set.

tal.ini Settings

In the [TRADING] section of the tal.ini, the PendingOrderLimit=parameter can be added or modified

to control how many pending orders are allowed to exist before the user interface is notified.

Page 8: RealTick EMSdownload.realtick.com/API/RealTick Scripting QuickStart Guide.pdf · RealTick EMS — RealTicK Scripting Quick Start Guide 2013 RealTick LLC All Rights Reserved 3 Chapter

RealTick EMS — RealTicK Scripting Quick Start Guide 2013 RealTick LLC All Rights Reserved 8

Chapter 3: Order API Detail

This chapter discusses the different members of RealTick that are relative to Order Entry. It also gives

scripting examples for Reserve and Conditional orders.

Properties

These three properties must be set to 1 in order to turn on their corresponding event. For example,

in order to receive an OnNewBalance event, the BalanceUpdate property has to be set to 1.

Property Description

BalanceUpdate Property BalanceUpdate As Long

PositionUpdate Property PositionUpdate As Long

TradeUpdate Property TradeUpdate As Long

Methods

The following table describes the different methods relative to Order Entry, Balance data and

Position data. Field ID values (“IFIELDID” fields in the method descriptions below) also known as a

“FID”s may be identified using the “Select Fields” dialog in the RealTick client application.

Method Description Notes

CancelAllOrders Function CancelAllOrders(iCacheContex t As Long, bsAccount As

String, bsSymbol As String) As

Long

ICacheContext is reserved for future use, and should be 0.

bsAccount: specifies the account in which you want to cancel all orders. This must be specified.

bsSymbol: specifies the symbol for which you want to cancel all orders. If the empty string is passed, cancels orders for all symbols in the specified account.

Returns: 0 for success, nonzero for failure.

continues on next page

Page 9: RealTick EMSdownload.realtick.com/API/RealTick Scripting QuickStart Guide.pdf · RealTick EMS — RealTicK Scripting Quick Start Guide 2013 RealTick LLC All Rights Reserved 3 Chapter

RealTick EMS — RealTicK Scripting Quick Start Guide 2013 RealTick LLC All Rights Reserved 9

Method Description Notes

CancelOrder Sub CancelOrder(bsOrderID As

String, bsReason As String)

bsOrderID: the server side

ID returned from the OnNewTrade() or

OnNewTradeEx() event.

bsReason : free text (can be any string you want to pass in). When reporting the cancel, however, RealTick will always report the

reason as “CanceledByUser”.

CreateChangeOrder Function

CreateChangeOrder(bsOrderID As String) As Long

bsOrderID: the server side ID returned from the

OnNewTrade() or OnNewTradeEx() event. Returns: a new client side order handle similar to that created by CreateOrder().

After creating the handle for the change order, call one or more SetOrder* calls to change the properties of the order. You may not call SetOrderSymbol(). If and only if the original order was not placed by the current application

instance, you must call SetOrderSymbolAttributes (). Once you are done setting up the change, call SendOrder() on the change order handle.

CreateConditionalOrder Function

CreateConditionalOrder(bsCondi tionSymbol As String, iFieldID

As Long, iRelation As Long, dVal As Double, lOrderToPlace As Long, bsAccount As String)

As Long

See explanation in Conditional Orders section below.

CreateOrder Function CreateOrder() As Long Returns: a client side order handle, on which you

call SetOrder*() methods before sending the order.

continues on next page

Page 10: RealTick EMSdownload.realtick.com/API/RealTick Scripting QuickStart Guide.pdf · RealTick EMS — RealTicK Scripting Quick Start Guide 2013 RealTick LLC All Rights Reserved 3 Chapter

RealTick EMS — RealTicK Scripting Quick Start Guide 2013 RealTick LLC All Rights Reserved 10

Method Description Notes

CreateOrderEx Function CreateOrderEx(bsSymbol As String, bsBuySell As String, dPrice As Double, iPriceType As TorderPriceType, dAuxPrice

As Double, lVolume As Long,

iVolType As

TOrderVolumeType, bsRoute

As String, iExpiration As

TOrderExpirationType, bsPref As

String, bsAccount As String,

[optional] vOrderType) As

Long

If you need to pass vOrderType, pass a

numeric 0, unless you are placing a MakeMarket (ePrcQuote) order. If you are placing a MakeMarket order, use CreateOrder and set the parameters individually rather than using

CreateOrderEx.

Returns: a client side order handle with

preset properties. You can still call

SetOrder*() methods to change or add

parameters before sending the order.

CreateOrderFromHotKey

Function

CreateOrderFromHotKey(bsAcc ount As String, bsSymbol As String, bAlt As Long, bCtl As Long, bShift As Long, cHotKey As String) As Long

Used to take advantage of RealTick’s OES Hot Keys feature.

Returns: a client side order handle with properties preset by the hot key combination specified in the bAlt, bCtl, bShift and cHotKey parameters. Any remaining properties can be set or changed by calling SetOrder*() methods before sending the order.

continues on next page

Page 11: RealTick EMSdownload.realtick.com/API/RealTick Scripting QuickStart Guide.pdf · RealTick EMS — RealTicK Scripting Quick Start Guide 2013 RealTick LLC All Rights Reserved 3 Chapter

RealTick EMS — RealTicK Scripting Quick Start Guide 2013 RealTick LLC All Rights Reserved 11

Method Description Notes

CreateOrderTicket Function CreateOrderTicket() As

Long

This function is used to create a staged order

ticket. It works just like CreateOrder(), except it creates an order with a staged order action type. You still call the same SetOrder*() functions to set the properties of the order.

When calling SetOrderAccount() on an order created with CreateOrderTicket(), it sets the

account to which this ticket is being assigned. This should normally not be your own account (unlike with CreateOrder()). The trader who is trading in the account to which the ticket is being assigned will get an alert that a new ticket has

been assigned, and will be able to see all of the

order information in the RealTick ticket minder.

FreeMemOrder FreeMemOrder(lOrder As Long)-

no longer used

Sub It is no longer necessary to ever call this method.

GetAccounts Function GetAccounts() As

String

Returns a newline delimited list of All

BANK;BRANCH;CUSTOMER;DE

POSIT accounts assigned to the current logged on user.

GetBalance Function GetBalance(bsAccount

As String) As Double

Gets the current excess equity figure for the specified account.

continues on next page

Page 12: RealTick EMSdownload.realtick.com/API/RealTick Scripting QuickStart Guide.pdf · RealTick EMS — RealTicK Scripting Quick Start Guide 2013 RealTick LLC All Rights Reserved 3 Chapter

RealTick EMS — RealTicK Scripting Quick Start Guide 2013 RealTick LLC All Rights Reserved 12

Method Description Notes

GetOrders Function GetOrders(bsAccount

As String, bsSymbol As String, iEventType As TtradeEventType, iStatusType As

TorderStatusType) As String

bsAccount is of the form

Bank;Branch;Customer;Deposit This function knows about all orders that currently exist anywhere in your RealTickOrderBook. Using the iEventType and iStatusType parameters, you can control which orders are returned to you.

To retrieve orders for all accounts mapped to this user, pass in the empty string for bsAccount.

To retrieve orders for all symbols, pass in the empty string for bsSymbol.

If you specify a symbol and have not placed any orders on that symbol, the empty string is returned.

Returns:

<OrderID>,<Symbol></n>

<OrderID>,<Symbol></n>

You can call GetOrderFieldData() and pass in the

OrderID to retrieve more information about each order.

GetOrderFieldData Function GetOrderFieldData(bsOrderID As String, lFieldID As Long,

[lFlags As Long]) As String

This function takes a server side order ID and returns data from a field of an XML file as described in the “XML Files” section below.

lFlags is reserved for future use: pass in 0. lFieldID: The field ID must be passed in as

numeric data.

bsOrderID: the server side ID returned from the

OnNewTrade() or OnNewTradeEx() event.

continues on next page

Page 13: RealTick EMSdownload.realtick.com/API/RealTick Scripting QuickStart Guide.pdf · RealTick EMS — RealTicK Scripting Quick Start Guide 2013 RealTick LLC All Rights Reserved 3 Chapter

RealTick EMS — RealTicK Scripting Quick Start Guide 2013 RealTick LLC All Rights Reserved 13

Method Description Notes

GetPositionFieldData Function

GetPositionFieldData(bsAccount

As String, bsSymbol As String, lFieldID As Long, lFlags As

Long) As String

lFlags is reserved for future use: pass in 0.

lFieldID: The field ID must be passed in as numeric data.

bsAccount: the BANK;BRANCH;CUSTOMER;DEPOSIT string of the account with the position.

bsSymbol: the symbol of the position.

GetPositions Function GetPositions(bsAccount As String, bsSymbol As String) As String

bsAccount is of the form

Bank;Branch;Customer;Deposit

This function knows about all positions that currently exist anywhere in your RealTick Position Minder.

To retrieve positions for all accounts mapped to this user, pass in the empty string for bsAccount. To retrieve positions for all symbols, pass in the empty string for bsSymbol. If you specify a symbol and do not have any positions on that symbol, the empty string is returned.

Returns:

<Symbol>,<Qty>,<AvgPrice></n>

<Symbol>,<Qty>,<AvgPrice></n>

SendOrder Sub SendOrder(lOrder As Long, bNoConfirm As Long,

bsPassword As String, [vbAsync])

Sends order created by CreateOrder. If you do not want the order to be confirmed, set

bNoConfirm to TRUE. The optional

vbAsync parameter is generally no longer used and should be omitted.

SendOrderList Sub

SendOrder(bsCSVOrderIDList

As String, bNoConfirm As Long, bsPassword As String, [vbAsync])

Sends a list of orders, each of which were created one at a time by CreateOrder(). The list

(bsCSVOrderIDList) is a string which you can concatenate by joining string representations of your numeric order handles into a comma- separated list. The other parameters are the same as SendOrder(). The optional vbAsync parameter is generally no longer used and should be omitted.

continues on next page

Page 14: RealTick EMSdownload.realtick.com/API/RealTick Scripting QuickStart Guide.pdf · RealTick EMS — RealTicK Scripting Quick Start Guide 2013 RealTick LLC All Rights Reserved 3 Chapter

RealTick EMS — RealTicK Scripting Quick Start Guide 2013 RealTick LLC All Rights Reserved 14

Method Description Notes

SetOrderAccount Sub SetOrderAccount(lOrder As

Long, bsAccount As String)

bsAccount is of the form

Bank;Branch;Customer;Deposit

SetOrderAuxPrice Sub SetOrderAuxPrice(lOrder

As Long, dAuxPrice As Double)

Sets non-limit price used for complex price types such as stop or discretionary. For example, on a stop order, this sets the stop price. On a peg order, this always sets the peg offset.

SetOrderBuySell Sub SetOrderBuySell(lOrder As

Long, bsBuySell As String)

BsBuySell: ‘Buy’, ‘Sell’, or ‘SellShort’

SetOrderExpiration Sub SetOrderExpiration(lOrder

As Long, iExpiration As

TOrderExpirationType)

Sets order expiration to a member of the

TorderExpirationType enum.

SetOrderFieldData Sub SetOrderFieldData(lOrder

As Long, lFieldID As Long, bsValue As String)

Sets the value of an additional field in the order, adding the field if necessary. The client must know the field ID of the field they want to set (e.g.

23320).

SetOrderMessage Sub SetOrderMessage(lOrder As

Long, bsMessage As String)

Sets XML field 20691 equal to the content of

bsMessage. The content of bsMessage is free text.

SetOrderOpenClose Sub SetOrderOpenClose(lOrder As Long, iOrderOption As

TOrderOpenCloseType)

Sets open or close status for an option order to a member of the TorderOpenCloseType enum.

continues on next page

Page 15: RealTick EMSdownload.realtick.com/API/RealTick Scripting QuickStart Guide.pdf · RealTick EMS — RealTicK Scripting Quick Start Guide 2013 RealTick LLC All Rights Reserved 3 Chapter

RealTick EMS — RealTicK Scripting Quick Start Guide 2013 RealTick LLC All Rights Reserved 15

Method Description Notes

SetOrderOptionAttributes

Sub SetOrderOptionAttributes(lOrder As Long, bsUnderSym As String, bsPutCall As String, dStrike As Double, dExpDate As Date)

Sets attributes for an option. This method should only be called when the symbol is an option.

SetOrderPref Sub SetOrderPref(lOrder As

Long, bsPref As String)

Sets exchange preference. This method should be called when the route requires it. Normally called when the symbol is an option.

SetOrderPrice Sub SetOrderPrice(lOrder As

Long, dPrice As Double)

Sets the limit price for order types that require a limit price. For peg orders, this optionally sets the peg limit.

SetOrderPriceType Sub SetOrderPriceType(lOrder As Long, iPriceType As TOrderPriceType)

Sets the order price type to a member of the

TorderPriceType enum.

SetOrderRoute Sub SetOrderRoute(lOrder As

Long, bsRoute As String)

Sets the route on which to place the order.

SetOrderSymbol Sub SetOrderSymbol(lOrder As

Long, bsSymbol As String)

Sets the ticker symbol for which to place the order.

SetOrderSymbolAttributes

Sub SetOrderSymbolAttributes(lOrde r As Long, bsExchListed As String, iSecType As Long,

dBasis As Double)

iSecType is a value of FID 2000. dBasis is the basis value FID 1179.

Sets the specified attributes for any symbol. The most common reason to call this function is on a change order (see

CreateChangeOrder()) if the original order was not placed by the current application instance.

continues on next page

Page 16: RealTick EMSdownload.realtick.com/API/RealTick Scripting QuickStart Guide.pdf · RealTick EMS — RealTicK Scripting Quick Start Guide 2013 RealTick LLC All Rights Reserved 3 Chapter

RealTick EMS — RealTicK Scripting Quick Start Guide 2013 RealTick LLC All Rights Reserved 16

Method Description Notes

SetOrderTag Sub SetOrderTag(lOrder As

Long, bsTag As String)

Sets XML field 20692 equal to the content of bsTag. The content of bsTag is free text.

This is the method you should use if you want to track your order with your own ID.

The advantage of using SetOrderTag() and

GetOrderFieldData() to supply and retrieve a user defined ID is that this ID is the same whether the order is on the client or server.

It is still necessary for separate client side (long) and server side (string) ID's to also exist, so that each side doesn't have to worry about duplicating an ID that exists on the other side.

SetOrderTicketID Sub SetOrderTicketID(lOrder As

Long, bsTicketID As String)

LOrder should be a local order handle returned from CreateOrder(). BsTicketID is a string identifying a staged order ticket with which you would like to associate this order.

SetOrderVolType Sub SetOrderVolType (lOrder

As Long, iVolType As

TOrderVolumeType, iShowSize

As Long)

iShowSize: the amount you want to show for

Reserve Orders (see Reserve Orders section below).

SetOrderVolume Sub SetOrderVolume(lOrder As

Long, lVolume As Long)

Sets the order size.

SetTradeEventTypes Sub SetTradeEventTypes(eType

As TtradeEventType)

Specify the types of trade events for which you

would like to receive an OnNewTrade() or

OnNewTradeEx() callback.

continues on next page

Page 17: RealTick EMSdownload.realtick.com/API/RealTick Scripting QuickStart Guide.pdf · RealTick EMS — RealTicK Scripting Quick Start Guide 2013 RealTick LLC All Rights Reserved 3 Chapter

RealTick EMS — RealTicK Scripting Quick Start Guide 2013 RealTick LLC All Rights Reserved 17

OnNewTrade() and OnNewTradeEx() Events

Note on Callbacks

Callback functions themselves should do as little as possible. The RealTick automation server design

provides methods such as GetOrders() for controlled access to server side data, so that the client is

not forced to do a large amount of data processing inside of callbacks. If necessary, inbound data

(such as order ID’s) should be queued so that it can be processed (e.g. GetOrderFieldData() lookups)

outside the callback. Most particularly, within your callback, you should not call the RealTick

automation server or any other automation server, or raise any message boxes or dialogs.

OnNewTradeEx

The OnNewTrade() and OnNewTradeEx() events fire in response to new messages from the order

server about your trade. The difference between these events is that OnNewTradeEx() passes in much

more information. You should only implement a callback for one of these events. It is much handier

to use OnNewTradeEx(), and we highly recommend you take advantage of this. If you only want to

work with OnNewTrade(), you can prevent OnNewTradeEx() from firing by setting

FireOrderEventEx=N in the [REALTICK] section of your tal.ini. From this point on, we will discuss this

in terms of the OnNewTradeEx() event.

The OnNewTradeEx() event fires in response to the trade event types you may have specified using

SetTradeEventTypes(). For example, if you call SetTradeEventTypes(eAll), the event will fire in

response to all new messages from the server about your trade, i.e.: when the order hits the server,

when it goes live, when each partial or complete fill occurs, and if applicable when the order is

canceled, changed or deleted, in addition to a final summary message. If you pass eSummaryOnly,

you will only receive the summary

message. The third choice is eExecutions, in which case you will only receive fills.

Your application should call SetTradeEventTypes() at least once, on startup. The setting is sticky, so

there is no reason to ever call it twice in a row with the same parameter. You only need to call it

once, but you can call it as many times as you want if you want to change the setting while your

application is running. The variable that is set when you call this function is global to the RealTick

instance, so if you have run another Scripting application without shutting down RealTick in between

and the other application has called SetTradeEventTypes() and your application has not, your

application will use the previous application’s

setting, which can cause unpredictable behavior. This can be avoided by making sure your

application always calls SetTradeEventTypes() on startup.

Page 18: RealTick EMSdownload.realtick.com/API/RealTick Scripting QuickStart Guide.pdf · RealTick EMS — RealTicK Scripting Quick Start Guide 2013 RealTick LLC All Rights Reserved 3 Chapter

RealTick EMS — RealTicK Scripting Quick Start Guide 2013 RealTick LLC All Rights Reserved 18

If no application has called SetTradeEventTypes(), the default is eSummaryOnly.

The definition of the event is:

Event OnNewTradeEx

(stOrderId As String,

stBuySell As String,

stSymbol As String,

lTotalTraded As Long,

dAvgPrice As Double,

stStatus As String)

Member of RealTick.RealTick

The possible values of stStatus are PENDING, LIVE, COMPLETED and DELETED. There is a separate

OnNewTradeEx callback for each partial fill. The dAvgPrice passed into each callback is just for that

one callback. (It is “average” in the sense of per share). Each fill is transmitted independently of other

fills on the same order, and each fill has the COMPLETED status. If you want to get the aggregate

average price of an order that has undergone several partial executions, you need to store the

dAvgPrice values you receive from the different callbacks and average them.

The stOrderID that RealTick passes into this event is the remote side ID that can be passed into

functions such as CancelOrder() and GetOrderFieldData(). This stOrderID is also the name of the XML

file that logs this order if LogOrderToXML=Y is set.

Whenever there are partial fills in succession, the last portion of the stOrderID (after the 3rd hyphen)

is incremented by 1. If the first 200 shares fill as 0937-0054-000c-03, the next 200 shares of the same

order will fill as 0937-0054-000c-04, and so on. This is guaranteed not to duplicate another order.

The only purpose of this "sequence tag" at the end of the stOrderID is to indicate partial fills. This

feature doesn't care whether the partial fills were at the same or different price. That information is

passed separately (dAvgPrice). It is also possible to have an stOrderID format like 1043ebf-6a-00004-

4 (where there is just one digit after the hyphen: so the –4 in this ID is equivalent to the –04 above).

You will also receive messages that pertain to the original order and not to a particular event such as

a partial fill. In particular, you should eventually receive a COMPLETED event that points to the

original order and not to a particular fill. This event will indicate that all of the shares in the original

order have been filled. You can identify these global event messages by the format of the order ID.

If you are receiving partial fill order ID’s of the form 0937-0054-000c- 03, then OnNewTrade[Ex]()

messages that pertain to the global order will pass an order ID of the form 0937-0054-000c-00. If

you are receiving partial fill order ID’s of the form 1043ebf-6a-00004-4, then OnNewTrade[Ex]()

messages that pertain to the global order will pass an order ID of the form 1043ebf-6a-00004.

Page 19: RealTick EMSdownload.realtick.com/API/RealTick Scripting QuickStart Guide.pdf · RealTick EMS — RealTicK Scripting Quick Start Guide 2013 RealTick LLC All Rights Reserved 3 Chapter

RealTick EMS — RealTicK Scripting Quick Start Guide 2013 RealTick LLC All Rights Reserved 19

OnNewPosition() Event

When you get a fill that opens, closes, or changes the size of a position, the OnNewPosition() event

will fire if you are listening for it. The OnNewPosition() event passes three parameters:

string Symbol

double dPosition

double dAvgPrice

The event always passes the symbol and the new size of the position (which can be 0, or a positive or

negative number).

The event is guaranteed to pass a nonzero value in dAvgPrice if and only if the average price of your

position has been changed by this event. If the average price of your position has not been changed

by the current event, and is the same as it was before, the OnNewPosition event may pass 0.00 in

dAvgPrice. This just means the average price of your position is the same as it was before. This

should not be interpreted to mean an actual average price of 0.00.

To listen for the OnNewPosition() event, set the PositionUpdate property to 1. You must also provide

a callback function.

OnNewBalance() Event

When you get a fill that changes the available equity in one of your accounts, the

OnNewBalance() event will fire if you are listening for it. OnNewBalance() passes the following two

parameters:

string bsAccount

double dBalance

The dBalance figure passed to this event is FID 23041(CBP_REMAINING) on the account designated

by bsAccount. This is the field labeled as “Available Equity” in the Account Detail layout of RealTick.

To listen for the OnNewBalance() event, set the BalanceUpdate property to 1. You must also provide

a callback function.

Page 20: RealTick EMSdownload.realtick.com/API/RealTick Scripting QuickStart Guide.pdf · RealTick EMS — RealTicK Scripting Quick Start Guide 2013 RealTick LLC All Rights Reserved 3 Chapter

RealTick EMS — RealTicK Scripting Quick Start Guide 2013 RealTick LLC All Rights Reserved 20

Price Type

The eOrderPriceType enumeration has the following values:

ePrcLimit = 0,

ePrcMarket = 1,

ePrcStop = 3,

ePrcStopLimit = 4,

ePrcBBO = 5,

ePrcTopBookIn2 = 6,

ePrcTopBookIn1 = 7,

ePrcTopBookOut1 = 9,

ePrcTopBookOut2 = 10,

ePrcPostNoPref = 11,

ePrcMid = 12,

ePrcBidDelta = 13,

ePrcOfferDelta = 14,

ePrcBBOOut1 = 15,

ePrcBBOOut2 = 16,

ePrcDiscretionary = 17,

ePrcTrailingStop = 18,

ePrcQuote = 19,

ePrcPegBid = 20,

ePrcPegOffer = 21,

ePrcPassiveDiscretionary = 22,

ePrcInsideLimit = 23,

ePrcTrack = 24,

ePrcTopBook = 8,

ePrcPegMid = 25,

ePrcPegVwap = 26,

ePrcPegLast = 27,

ePrcMOO = 28,

ePrcMOC = 29,

ePrcHidden = 30,

ePrcTrailingStopLmt = 31

Page 21: RealTick EMSdownload.realtick.com/API/RealTick Scripting QuickStart Guide.pdf · RealTick EMS — RealTicK Scripting Quick Start Guide 2013 RealTick LLC All Rights Reserved 3 Chapter

RealTick EMS — RealTicK Scripting Quick Start Guide 2013 RealTick LLC All Rights Reserved 21

Expiration Type

To submit an order you must also specify an expiration from the eOrderExpirationType enumeration:

eExpireIOC = 0,

eExpireDAY = 2,

eExpireGTC = 1,

eExpireDAYPLUS = 3,

eExpireNOW = 7,

eExpireOPG = 9,

eExpireCLO = 15,

eExpireFOK = 16

Volume Type

You can specify the following Volume Types from the eOrderVolumeType enumeration:

0=eVolPartial

1=eVolAllOrNone

2=eVolReserve

5=eVolImbalance

Reserve Order

A Reserve Order is a single order that RealTick breaks up into smaller orders by volume. For example,

you can place a single Reserve Order for 1200 and set it to only put out an order for 300 at a time

(your Reserve Show Size). Then when the first 300 are filled you show the second 300, and so on. This

feature is available on ARCA.

Certain order parameters may not be allowed on specific routes and/or at specific times, based on

the same rules that apply to manual order entry through RealTick.

Page 22: RealTick EMSdownload.realtick.com/API/RealTick Scripting QuickStart Guide.pdf · RealTick EMS — RealTicK Scripting Quick Start Guide 2013 RealTick LLC All Rights Reserved 3 Chapter

RealTick EMS — RealTicK Scripting Quick Start Guide 2013 RealTick LLC All Rights Reserved 22

Conditional Orders

The CreateConditionalOrder call creates a wrapper for conditional placement of another order. The

lOrderToPlace parameter is the handle for another order—the one you actually want to place when

the condition is met. The other order should be created normally and have all its parameters set

normally, but not get sent—its handle should be passed to this function instead of being sent. Here

are the meanings of the parameters used to create the conditional “wrapper” order. In this

explanation, the order of the parameters may be changed to better explain their meanings.

bsConditionSymbol:

The symbol whose activity is used as the basis for triggering the condition.

iFieldID:

The field of bsConditionSymbol that you want to look at.

dVal:

The constant value to which you want to compare the current value of iFieldID for

bsConditionSymbol.

iRelation:

The relationship between the current value and dVal, as follows:

#define PRICE_REL_GT 1 //condition is met when value > dVal

#define PRICE_REL_GE 2 //condition is met when value >= dVal

#define PRICE_REL_EQ 3 //condition is met when value = dVal

#define PRICE_REL_LE 4 //condition is met when value <= dVal

#define PRICE_REL_LT 5 //condition is met when value < dVal

The internal order will automatically be placed when the condition is met.

Code Examples

Individuals with an active RealTick ID and entitlements may access the most up-to-date RealTick

Scripting code examples for VB, VBA and C++ are available within the RealTick API ® QuickStart

Guide at www.realtick.com/api. For any questions, contact RealTick Technical Support at

[email protected].

Page 23: RealTick EMSdownload.realtick.com/API/RealTick Scripting QuickStart Guide.pdf · RealTick EMS — RealTicK Scripting Quick Start Guide 2013 RealTick LLC All Rights Reserved 3 Chapter

RealTick EMS — RealTicK Scripting Quick Start Guide 2013 RealTick LLC All Rights Reserved 23

Chapter 4: XML Files

This chapter discusses the XML logging of order information. The XML files that may be stored within

the Trading subdirectory also correspond to the information about each order that may be obtained

by calling GetOrderFieldData().

To store order information to XML files in the Trading subdirectory, go to the Order Entry

Properties | Miscellaneous tab and check “Log Order to XML”. Otherwise, the same information will

still be stored in memory and accessible by calling GetOrderFieldData(), but will not be stored to disk.

Trading Subdirectory

The XML files are created within subdirectories of the Trading subdirectory. The names of the

subdirectories are based on the date of the trade. For example: If RealTick is installed in the

C:\RealTick directory and today’s date is June 5, 2012, then the XML files will be written to

c:\RealTick\trading\20120605\. The files are given the name of the order number plus an XML

extension. The XML files output by RealTick can be used to feed other applications.

The document elements will change slightly depending on the status of the order. So, if you are

reading in an order that is LIVE as opposed to COMPLETED, it will not have an AVG Price amount.

Some logic can control how this is handled. The Elements for the most part are given numeric names.

These correspond to field ID numbers in the RealTick databases. They could be mapped using XSL or

manually.

Statuses

Pending, the very first status, when RealTick knows about the order but the remote side

doesn’t know about it yet.

Live, this is an acknowledgement that the order is received but not filled.

Completed, this is filled either partial or entirely.

Deleted, this is cancelled either by the client or as a result of an IOC.

XML Mapping

The field ids in the XML file take the following form: <F1234> where 1234 is the RealTick FID (Field

ID). Field ID descriptions may be identified using the “Select Fields” dialog in the RealTick client

application by entering the FID value into the search box.

Page 24: RealTick EMSdownload.realtick.com/API/RealTick Scripting QuickStart Guide.pdf · RealTick EMS — RealTicK Scripting Quick Start Guide 2013 RealTick LLC All Rights Reserved 3 Chapter

RealTick EMS — RealTicK Scripting Quick Start Guide 2013 RealTick LLC All Rights Reserved 24

Chapter 5: RealTick Permissions State

This chapter provides you with the methods and events to determine if RealTick is running and ready

to receive commands.

Poll Permissions State

When RealTick is first launched, either manually or by instantiating this interface, it is not always

ready to receive commands. The best approach to detect when RealTick is ready to receive

commands is to poll the permissions state using GetPermState().

Function GetPermState() as TPermState

Method GetPermState

The ePermState enumeration is as follows:

1. ePermsOK

2. ePermsRevoked

3. eSuspended

4. eUninitialized

5. eVerifyFailed

The initial state is eSuspended. When RealTick is all the way up, the state will become ePermsOK. The

OnNewPermState event does not begin working until after the first ePermsOK state is reached.

Therefore, you want to poll for the initial ePermsOK state. However, you should implement a callback

for the OnNewPermsState event so that you can be alerted of changes to RealTick’s permissions

state once RealTick is up and running. Event OnNewPermState(iState As Long) For example,

OnNewPermState might call you back with iState = 2 (ePermsRevoked) if the same user logs on

again from a different machine.

Page 25: RealTick EMSdownload.realtick.com/API/RealTick Scripting QuickStart Guide.pdf · RealTick EMS — RealTicK Scripting Quick Start Guide 2013 RealTick LLC All Rights Reserved 3 Chapter

RealTick EMS — RealTicK Scripting Quick Start Guide 2013 RealTick LLC All Rights Reserved 25

Chapter 6: Window Creation/Manipulation

This chapter discusses creating/manipulating child windows within RealTick.

This functionality is not recommended for use at the same time as scripting order entry. This is

currently supported only for the MarketMaker and MarketMinder window types. Support for

additional window types may be added in future RealTick releases.

Functions

The first three functions documented below, return a handle for a RealTick window. Currently,

RealTick window handles exposed through this interface are the same as the Windows hWnd for the

same window.

This is subject to change.

For a MarketMaker, szModuleName = mmaker

For a MarketMinder, szModuleName = minder

CreateRealTickWindow

Function CreateRealTickWindow(szModuleName As String) As Long

This function creates a new window of the specified type and returns a handle to it.

FindWindow

Function FindWindow(szModuleName, [szPartialTitle]) As Long

This function finds the first (in zOrder) instance of the specified window type, and returns the handle

to that instance. If szPartialTitle is specified, it finds the first instance of the specified window type

matching the specified partial title. If no window matching the parameters is found on the currently

open page, returns 0.

GetActiveWindow

Function GetActiveWindow() As Long

This function returns the handle to the currently selected window on the currently open page.

GetWindowHandle

Function GetWindowHandle(szModuleName As String, szTitle As String) As Long

The szTitle parameter must be the EXACT text that appears in the title bar of the child window. This is

exact character for character including punctuation (Minder titles often start with the literal character

*). All characters in the string are treated as literal.

Page 26: RealTick EMSdownload.realtick.com/API/RealTick Scripting QuickStart Guide.pdf · RealTick EMS — RealTicK Scripting Quick Start Guide 2013 RealTick LLC All Rights Reserved 3 Chapter

RealTick EMS — RealTicK Scripting Quick Start Guide 2013 RealTick LLC All Rights Reserved 26

SetWindowSymbol

Sub SetWindowSymbol(Handle As Long, bsSymbol As String, bStartData As Long)

This function takes the handle to a window and sets the symbol of that window to the specified

symbol. If the window type supports more than one symbol, the specified symbol is appended to the

end of the current list.

Example Code

Dim rt As Realtick.Realtick ‘Realtick interface

Dim hMinder As Long ‘Realtick window handle

Dim hMaker As Long ‘Realtick window handle

Set rt = CreateObject(“TAL.Realtick.1”)

‘this call assumes you already have a minder with the title

'"*Minder: Two Column.BVW" on your page

hMinder = rt.GetWindowHandle("Minder", "*Minder: Two Column.BVW")

'each SetWindowSymbol should append the symbol to the end of the list.

rt.SetWindowSymbol hMinder, "CSCO", True

rt.SetWindowSymbol hMinder, "IBM", True

'this is to create a new MarketMaker on your page and put

MSFT in it hMaker = rt.CreateRealtickWindow("MMaker")

rt.SetWindowSymbol hMaker, "MSFT", True

Page 27: RealTick EMSdownload.realtick.com/API/RealTick Scripting QuickStart Guide.pdf · RealTick EMS — RealTicK Scripting Quick Start Guide 2013 RealTick LLC All Rights Reserved 3 Chapter

RealTick EMS — RealTicK Scripting Quick Start Guide 2013 RealTick LLC All Rights Reserved 27

Chapter 7: System Information

This chapter defines properties that provide system information.

The Application property is a read-only string.

The version property is also a read-only string.