PSContent
1. Introduction
4.
TWSLINK Setup and on
principle usage
5. Description of exported functions
5.1. TWSLINK general functions
5.1.1. Function INITDLL
5.1.2. Function CONNECT
5.1.3. Function DISCONNECT
5.1.4. Function SET_DLLPARAM
5.1.5. Function GET_DLLSTATUS
5.1.6. Function SET_STOP
5.1.7. Function SET_BREAK
5.1.8. Function WAITDLL
5.1.9. Function WAIT_FOR_REQ_PROCESSED
5.1.10.Function GET_CONNECTED
5.1.11.Function WAIT_FOR_EVENT
5.1.12.Function DISPOSE
5.1.13.Function CONNECT_XML
5.1.14.Function INITDLL_XML
5.1.15.Function GET_EVENT_VAL
5.1.16.Function REQ_CURRENT_TIME
5.1.17.Function TIME_COMPONENT
5.1.18.Function
TIME_STRING
5.1.19.Function SECONDS_1970
5.1.20.Function MILLISECONDS_1970
5.1.21.Function SET_TIMER
5.1.22.Function KILL_TIMER
5.1.23.Function PLAY_SOUND
5.1.24.Function GET_EVENT_VAL_L
5.1.25.Function GET_EVENT_VAL_D
5.2. Contract related functions
5.2.1. Function REGISTER_CONTRACT
5.2.2.
Function WAIT_FOR_ACCEPTED
5.2.3.
Function GET_CONTRACT_STATUS
5.2.4.
Function REQ_MARKET_DATA
5.2.5.
Function GET_CONTRACT_VAL
5.2.6.
Function CLOSE_CONTRACT
5.2.7.
Function GET_POSITIONS
5.2.8.
Function GET_STOPPROTECTION
5.2.9.
Function GET_MARKET_DATA
5.2.10.Function GET_TICK
5.2.11.Function QUERY_MARKET_DATA
5.2.12.Function ADD_COMBO_LEG
5.2.13.Function EXTRACT_MARKET_DATA
5.2.14.Function GET_CONTRACTUID_LIST
5.2.15.Function EXTRACT_ARRAY_VALUE
5.2.16.Function WAIT_FOR_TICK
5.2.17.Function CLOSE_CASH_POSITION
5.2.18.Function FORCE_CONTRACT
5.2.19.Function SET_INDICATOR_SIZE
5.2.20.Function VALIDATE_PRICE
5.2.21.Function REM_COMBO_LEG
5.2.22.Function SET_CONTRACT_VAL
5.2.23.Function REQ_BAR_DATA
5.2.24.Function GET_BAR_DATA
5.2.25.Function REGISTER_CONTRACT_XML
5.2.26.Function REGISTER_CONTRACT_XML_STYLE
5.2.27.Function REQ_MARKET_DEPTH
5.2.28.Function GET_MARKET_DEPTH
5.2.29.Function GET_MARKET_DEPTH2
5.2.30.Function REQ_HIST_DATA
5.2.31.Function REQ_SCANNER_PARAMETER
5.2.32.Function REQ_SCANNER_SUBSCRIPTION
5.2.33.Function CANCEL_SCANNER_SUBSCRIPTION
5.2.34.Function PIPS
5.2.35.Function REQ_FUNDAMENTAL_DATA
5.3.1.
Function PLACE_ORDER
5.3.2.
Function SET_ORDERVAL
5.3.3.
Function WAIT_FOR_ORDER_STATUS
5.3.4.
Function WAIT_FOR_ORDER_STATUS_RNG
5.3.5.
Function GET_ORDER_STATUS
5.3.6.
Function GET_ORDER_ERROR
5.3.7.
Function ATTACH
5.3.8.
Function ORDER_MODIFIABLE
5.3.9.
Function TRANSMIT
5.3.10.Function CANCEL_ORDER
5.3.11.Function SET_FA_MEMBERS
5.3.12.Function WAIT_FOR_FILLED
5.3.13.Function BUY_LMT
5.3.14.Function SELL_LMT
5.3.15.Function BUY_STPLMT
5.3.16.Function SELL_STPLMT
5.3.17.Function BUY_MKT
5.3.18.Function SELL_MKT
5.3.19.Function TOGGLE_ORDER
5.3.20.Function BUY_STP
5.3.21.Function SELL_STP
5.3.22.Function BUY_TRAIL
5.3.23.Function SELL_TRAIL
5.3.24.Function CONVERT_ID
5.3.25.Function CONVERT_ID_STRING
5.3.26.Function GET_ORDER_VAL
5.3.27.Function GET_EXECUTION_PRICE
5.3.28.Function GET_ORDERUID_LIST
5.3.29.Function TOGGLE_ORDER_PCT
5.3.30.Function WAIT_FOR_SUBMITTED
5.3.31.Function GET_OPEN_ORDERUID_LIST
5.4. Account
related functions
5.4.1.
Function GET_ACC_VAL
5.4.2.
Function GET_BASECURRENCY
5.4.3.
Function GET_ACC_NAME
5.4.4.
Function REQ_ACC_UPDATE
5.4.5.
Function GET_CASH_BALANCE
5.4.6.
Function GET_EXCHANGE_RATE
5.4.7.
Function GET_MARKET_VAL
5.4.8.
Function GET_PORTFOLIO_VAL
5.5.1.
General Consideration of Callback Usage
5.5.2.
Function SET_EVENT_HANDLER
5.5.3.
Function SET_EVENT_HANDLER_OLE
5.6.1.
Function SEND_MAIL
5.6.2.
Function SET_LNG_VAR
5.6.3.
Function SET_DBL_VAR
5.6.4.
Function SET_STR_VAR
5.6.5.
Function GET_LNG_VAR
5.6.6.
Function GET_DBL_VAR
5.6.7.
Function GET_STR_VAR
5.6.8.
Function REM_LNG_VAR
5.6.9.
Function CUSTOMCOMMENT
5.6.10.Function START_APPLICATION
5.6.11.Function FROM_FILE
5.6.12.Function TO_FILE
5.6.13.Function REM_DBL_VAR
5.6.14.Function REM_STR_VAR
5.6.15.Function NEWS_BULLETIN
5.6.16.Function CONNECT_DB
5.6.17.Function DISCONNECT_DB
5.6.18.Function SQL
5.6.19.Function SQL2
5.6.20.Function GET_LNG
5.6.21.Function GET_DBL
5.6.22.Function GET_STR
5.6.23.Function ADD_LNG
5.6.24.Function ADD_DBL
5.6.25.Function CUSTOMLOG
5.6.26.Function DELETE_CUSTOMLOG
5.6.27.Function PARSE_XML
6.1. Table Initialisation Flag Values
6.2. Table TWSLINK Parameter Names
6.3. Table TWSLINK Status Identifiers and their possible String Values
6.4. Table Contract Status Identifier
6.5. Table Contract Value Identifiers
6.6. Table Order Property Identifiers
6.7. Table Order Status Identifier
6.8. Table Order Error Identifier
6.9. Table Account Value Identifier
6.10.
Table TWSLINK Loglevel Values
6.11.
Table Callback Function Pointer Definition
6.11.1.Table of Primary Event Mask
6.12.
Table Market Data Field Identifiers
6.12.1.Table Market Data Sub Field Identifiers
6.12.2.Table Market Data ID Values
6.13.
Table TWSLINK Sub-Event Identifiers
6.14.
Table ID Conversion Types
6.15.
Table Market Value IDs
6.16.
Table Portfolio Value IDs
6.17.
Table Indicator Identifiers
6.18.
Table Date/Time Format Specifiers
6.19.
Table Realtime Bar Identifiers
6.20.
Table Contract Property Attribute Names
7.1. Determination
7.2. Plausibility
7.3. Technical Notes/Restrictions΄
7.4. API Reference-Help
10. General programming techniques
10.1.
Register Contracts
10.1.1.Register multiple contracts
10.2.
Accessing market data
10.3.
Placing Orders for FA Accounts
10.4.
Attaching Stop/Target Orders
10.5.
The Order ID Types and their Meaning
10.6.
Callback Usage
11. Database Support
The Interface DLL (TWSLINK)
is thought to link any Application, that can utilize a DLL or COM, with Interactive
Brokers TWS©, for the Purpose of Transmitting and Controlling Orders.
All necessary Actions around orderhandling, connection and necessary requests, are
done by the TWSLINK. This allows the user to concentrate on the strategy
behind. Various functions take control over orders, contracts and account.
An extensive and scaleable logging allows users to track and fix
problems and gives him the chance to integrate TWSLINK with his Strategy Builder / Signal Server to his preferred way.
Various samples e.g. for TradeStateson 2000i© given in .ELS Format, Excel etc, demonstrate the use of TWSLINK. However, it
should be easy to call all exported DLL-Functions from any other application that
allows DLL Function Call or COM.
Several TWSLINK-Parameters take effect on how to connect to TWS, sizing
buffers, timing delays for automatic reconnection etc.. But dont feel
cluttered by to many setup parameters. Most of these parameters can be used
with their default-value.
TWSLINK is provided as demo versions. It comes with no
restrictions except runtime limited to 2 hours. You can get a unlimited license
by purchasing EUR 180,- vial PayPal for
ce_@gmx.de.
You can easily create a PayPal account without costs. Only a valid
credit card is needed. Its number is transferred to PayPal once when creating
an account.
Once you have fnished the payment, you can activate TWSLink by using the
Set
License Key dialog which can be accessed through the trayicon in the
the lower right corner of your taskbar. Once this key is set, it is stored in
file twslink.lic
and the key is loaded automatically from this file at next startup. (If
you need to move with TWSLink, take this file on the trip as well).
Set Identification Dialog: You need to input license key only.

Note: The demoversion has a runtime of 2 hours. After
all exported functions are inaccessible expect
DISCONNECT , CANCEL_ORDER, CLOSE_CONTRACT and
CLOSE_CASH_POSITION.
The Use of the TWSLINK is at your own Risk. The
Author is not responsible for any monetary loss or physical or mental damage
that could be related to the use of TWSLINK. It is strongly recommend to test
the TWSLINK with Demo- or Paper Account before trading on real accounts.
Simply run TWSLink.msi. Pay attention
to the Readme/Install Text-Files in
each sample directory. Depending of the language to which the Samples refer,
additionally components may have to be installed (e.g. Perl, Python).
4. TWSLINK Setup and on principle usage.
A high-beep indicates that the DLL has been loaded. In contrariwise, a low-beep
signals DLL has been unloaded. In Addition a Tray Icon shows DLL Status and
Account Information. The Final Information String of the Tray has Format:
Account
Name (or Short List FA Accounts)
[clientid][process
id]
current
net liquidation value in base currency
runtime
net liquidation delta value in base currency
Tray Icons and their Meaning:
|
Icon |
Meaning |
|
|
TWSLink is not connected. |
|
|
TWSLink is connecting. |
|
|
Connection to TWS established. |
|
|
No License. This is shown in the 2. tray window,
left of TWSLink tray. |
|
|
Demo License. This is shown in the 2. tray window,
left of TWSLink tray. |
|
|
License granted. Only few seconds visible. This is
shown in the 2. tray window, left of TWSLink tray. |
Before placing orders, requesting marketdata or
calling any other contract dependent function, you need to register a contract
first in order to obtain a unique id.
Call:
Contractuid=
REGISTER_CONTRACT(
).
Now connect to TWS. This Function normally has to be
called once, if the automatic reconnect timer is enabled.
Call:
Check if your contract(s) has been accepted by TWS.
If WAIT_FOR_ACCEPTED(Contractuid, 000) >= -1 then
Begin
Do Your Trading Actions
End
Else
Begin
CUSTOMCOMMENT(Something is wrong with my Contract
Specification,1,1)
End
5. Description
of Exported Functions
5.1 TWSLINK Initialisation and Setup
5.1.1 Function INITDLL back
Description: Function removed.
5.1.2 Function CONNECT back
Description: Connect to TWS.
Return Type: int
Return Value Table
|
Value |
Meaning |
|
1 |
Connection established. |
|
0 |
Connection failed. |
Parameter Table
|
# |
Name |
Type |
Comment |
Default |
|
1 |
Host |
LPSTR |
Host for TWS Connection. |
127.0.0.1 |
|
2 |
Port |
int |
Port for TWS Connection. |
|
|
3 |
startingClientId |
int |
Preferred TWS Client ID for TWSLINK Connection. Set < 0 to allow TWSLink try Connection on next
free ClientId. |
1 |
|
4 |
Timeout |
int |
Timeout in Minutes. Pass -1 to wait Infinite. |
5000 |
Comments:
Sample: Connect to TWS at 192.166.0.2:7496 and use ClientID=1.
retcode = CONNECT (192.166.0.2,7496,1 ,-1)
Connect to TWS at 192.166.0.2:7496 and start with
ClientID=1 and allow TWSLink to try next ClientId if Id=1 should be already
used by another Client.
retcode = CONNECT (192.166.0.2,7496,-1 ,-1)
5.1.3 Function DISCONNECT back
Description: Disconnect from TWS. Once
called, it stop the automatic reconnect-cycle. Normally this function has not
to be called as TWSLink calls it before being unloaded.
Return Type: int
Return Value Table
|
Value |
Meaning |
|
1 |
Ok. |
|
0 |
No Ok. |
Sample: retcode = DISCONNECT ()
5.1.4 Function SET_DLLPARAM back
Description: Set a specific DLL parameter. This is usually called to set a parameter
which Initialisation is not supported by INITDLL.
Return Type: int
Return Value Table
|
Value |
Meaning |
|
1 |
Ok. |
|
0 |
Parameter couldnt be set. |
|
-2 |
Parameter unknown. |
Parameter Table
|
# |
Name |
Type |
Comment |
Value Ref. |
|
1 |
sCommand |
LPSTR |
Name of Parameter. |
|
|
2 |
sParam |
LPSTR |
Value of Parameter as string. |
|
Sample: Set the minimum delay between 2 commands to 300 milliseconds.
retcode = SET_DLLPARAM ("setcmddelay",300)
5.1.5 Function GET_DLLSTATUS back
Description: Get the status of a specific DLL parameter
(property).
Return Type: string (Constant String)
Return Value Table
|
Value |
Meaning |
|
String describing the Status. |
|
|
nok |
#1 unknown. |
Parameter Table
|
# |
Name |
Type |
Comment |
Value Ref. |
|
1 |
sParam |
string |
Name of Status. |
|
|
2 |
lParam |
int |
Additional Integer Parameter. Its use depends on #1. |
|
|
2 |
sParam2 |
string |
Additional String Parameter. Its use depends on #1. |
|
Sample: Get the Connection Status of TWSLINK.
StringStatus = GET_DLLSTATUS("connected",0,)
Check if
ISLAND_UNAV = GET_DLLSTATUS("exunav",0,
5.1.6 Function SET_STOP (not threadsafe) back
Description: Set Stop Flag to enable/disable Function
Call. The same Effect can be obtained by calling SET_DLLPARAM
with #1 = setfunctioncall and
Value = 1 or 0. Unlike SET_STOP, a Call of SET_DLLPARAM is
threadsafe. On the other Hand, SET_DLLPARAM could be locked due to a Prior
Call of another threadsafe Function. So call SET_STOP in Emergency Situations only and take care to call this Function from
one Thread only. Normally there should
be no Need to call this Function. It is thought as Escape from unormal
Situations during Tests.
Return Type: int
Return Value Table
|
Value |
Meaning |
|
New Stop Flag Value |
|
Parameter Table
|
# |
Name |
Type |
Comment |
Value Ref. |
|
1 |
Flag |
int |
If 1, Function gets disabled, otherwhise enabled |
|
Sample: Stop Function Call.
int_FunctionCallDisabled = SET_STOP(1)
5.1.7 Function SET_BREAK back
Description: Function removed.
5.1.8 Function WAITDLL back
Description: Pauses execution of calling thread.
Return Type: int
Return Value Table
|
Value |
Meaning |
|
1 |
Pause finished, |
|
0 |
Function Call stopped. |
Parameter Table
|
# |
Name |
Type |
Comment |
|
|
1 |
Duration |
int |
Duration of Pause in Milliseconds |
> 0 |
Sample: Let the calling Thread sleep 1.5 Seconds.
WAITDLL(1500)
5.1.9 Function WAIT_FOR_REQ_PROCESSED
back
Description: Waits until most important requests has
been answered by TWS. This function can be used if one or more functions have
been called which require an answer from TWS (like REGISTER_CONTRACT,
PLACE_ORDER, etc.) to wait until all of these requests have been answered. If function
returns 1, you can gather for instance contract status and order status without
waiting for them.
Return Type: int
Return Value Table
|
Value |
Meaning |
|
1 |
Latest Requests finished, |
|
0 |
Timeout or there are still pending Request. |
|
-1 |
Not connected. |
|
-2 |
Function Call stopped. |
Parameter Table
|
# |
Name |
Type |
Comment |
|
|
1 |
Duration |
int |
Time for Function Returns. If 0, Function returns immediately after having checked for pending
Requests. If > 0, Function waits the passed Time for all Requests having
finished. |
> 40 < 10000 |
1. Requests for Account Updates
2. Requests for Contract Details.
3. Requests for Order States.
4. Requests for Executions.
5. Requests for Open Orders.
Sample: Give IB Server/TWS 5 Seconds to process latest Requests.
WAIT_FOR_REQ_PROCESSED(5000)
5.1.10 Function GET_CONNECTED back
Description: Get Connection Status.
Return Type: int
Return Value Table
|
Value |
Meaning |
|
2 |
DLL connected to TWS and TWS connected to IB Server. |
|
1 |
DLL connected to TWS. |
|
0 |
DLL not connected to TWS. |
Comments:
Sample: Check Connection.
IsConnected = GET_CONNECTED()
If IsConnected >= 1 then
End
All ok
Else
May I should wait with
further operations
end
5.1.11 Function WAIT_FOR_EVENT back
Description: Wait for next event. An Event is of the
same structure as the callback parameter Set. Table 6.11
describes the event structure.
Return Type: int
Return Value Table
|
Value |
Meaning |
|
> 0 |
UID of Event. |
|
0 |
No Event in the Meantime or asked Event not occurred
in the Meantime. |
|
-1 |
Event Category (#1) not matching. |
|
-2 |
Event Subcateory (#2) not matching. |
|
2147483647 |
Function Call disabled. |
Parameter Table
|
# |
Name |
Type |
Comment |
|
|
1 |
timeout |
Long |
Timeout |
=> 0 |
Comments:
Sample: Wait at the most of 5 Seconds for next Event.
EventId = WAIT_FOR_EVENT(5000)
5.1.12 Function DISPOSE back
Description: Clean up Ressources. This Function should
be called in .NET Environments before closing the Application as well as in all
other Environments if TWSLink should hang on shutdown.
Return Type: int
Return Value Table
|
Value |
Meaning |
|
0 |
ok |
Comments:
Sample: Clean up DLL internal Ressources.
Ret = DISPOSE()
5.1.13 Function CONNECT_XML back
Description: Connect to TWS with Parameters predefined
in xml Setup File.
Return Type: int
Return Value Table
|
Value |
Meaning |
|
1 |
Connection established. |
|
0 |
Connection failed. |
|
-1 |
Unknown Connection |
Parameter Table
|
# |
Name |
Type |
Comment |
Default |
|
1 |
connectionid |
int |
Id of Connection in xml Setup File. |
|
|
2 |
timeout |
int |
Timeout of Connection in ms. |
|
Comments:
<cnct id="1"
ip="192.168.5.1" port="7496" clientid="1"
desc="accountname"/>
</connections>
Sample: Connect to TWS with connection of id=3. allow a 10 second
timeout.
retcode = CONNECT_XML (3,10000)
5.1.14 Function INITDLL_XML back
Description: Function removed.
5.1.15 Function GET_EVENT_VAL back
Description: Get Value as string for
specified event.
Return Type: string
Return Value Table
|
Value |
Meaning |
|
Any String |
Value demanded for as String. |
|
nok |
Function Call stopped. |
|
enf |
Event not found. |
|
vnf |
Value id unknown. |
Parameter Table
|
# |
Name |
Type |
Comment |
|
1 |
uidevent |
int |
Unique ID of Event. Previously returned by WAIT_FOR_EVENT
or -1 to refer to latest Event. |
|
2 |
valueid |
int |
Id of Value to be returned. Table 6.11. |
Sample: Get Value of 2. int Member of Event with uid=69 as String
retcode = GET_EVENT_VAL(69,2)
5.1.16 Function REQ_CURRENT_TIME back
Description: Get server time as passed seconds
since 01/01/1970.
Return Type: int
Return Value Table
|
Value |
Meaning |
|
Any Value |
Seconds Past since |
|
0 |
Internal Error. |
|
-1 |
Function Call stopped. |
|
-2 |
Memerror |
Parameter Table
|
# |
Name |
Type |
Comment |
|
1 |
timeout |
int |
Timeout for server response in Milliseconds. |
Sample: Wait at the most 1 Second to get current Server Time.
PastSeconds = GET_CURRENT_TIME(1000)
5.1.17 Function TIME_COMPONENT back
Description: Get time component Year,
Month, Day, Hour, Minute or Second of time given in seconds passed since
Return Type: int
Return Value Table
|
Value |
Meaning |
|
Any Value |
Component value. |
|
0 |
Function Call stopped. |
|
-1 |
Error. Invalid time. |
Parameter Table
|
# |
Name |
Type |
Comment |
|
1 |
timeinseconds |
int |
Seconds passed since |
|
2 |
componentcode |
int |
1: Year |
Sample: Get Day of date represented by time value 1207672395.
Day = TIME_COMPONENT(1207672395,3)
-> 8
5.1.18 Function TIME_STRING back
Description: Get formatted time string for
time given in seconds passed since
Return Type: string
Return Value Table
|
Value |
Meaning |
|
Any Value |
Time formatted as string. |
|
nok |
Function Call stopped. |
|
emtpy |
Error. Invalid time. |
Parameter Table
|
# |
Name |
Type |
Comment |
|
1 |
timeinseconds |
int |
Seconds passed since |
|
2 |
format |
string |
Format string. (Table 6.18) |
Sample: Get time string formatted of time represented by time
value 1207672395.
TimeString = TIME_
-> 2008-04-08
5.1.19 Function SECONDS_1970 back
Description: Se
Return Type: int
Return Value Table
|
Value |
Meaning |
|
Any Value |
Se |
|
0 |
Function Call stopped. |
|
-1 |
Internal Error. |
Sample: Get se
se
5.1.20 Function MILLISECONDS_1970 back
Description: Millise
Return Type: double
Return Value Table
|
Value |
Meaning |
|
Any Value |
Se |
|
0 |
Function Call stopped. |
|
-1 |
Internal Error. |
Sample: Get millise
mse
5.1.21 Function SET_TIMER back
Description: Set a timer.
Return Type: int
Return Value Table
|
Value |
Meaning |
|
Any Value |
Id of timer (used to reference timer event and to
stop timer) |
|
0 |
Function Call stopped. |
|
-1 |
Error. Invalid time. |
Parameter Table
|
# |
Name |
Type |
Comment |
|
1 |
delayinms |
int |
Timer delay in millise |
Comments:
Sample: Set a 2 se
id = SET_TIMER(2000)
5.1.22 Function KILL_TIMER back
Description: Kill specific/all timer(s).
Return Type: int
Return Value Table
|
Value |
Meaning |
|
1 |
Ok |
|
0 |
Function Call stopped. |
|
-1 |
Error. Invalid time. |
Parameter Table
|
# |
Name |
Type |
Comment |
|
1 |
idoftimer |
int |
> 0: Kill timer with id=#1. |
Sample: Kill timer with id=3
res = KILL_TIMER(3)
5.1.23 Function PLAY_SOUND back
Description: Play specified soundfile or
stop playing all soundfiles.
Return Type: int
Return Value Table
|
Value |
Meaning |
|
1 |
Ok |
|
0 |
Function Call stopped. |
|
-1 |
Error. |
Parameter Table
|
# |
Name |
Type |
Comment |
|
1 |
soundfilename |
string |
Path and name of soundfile. |
|
2 |
loop |
int |
1: play in loop. |
|
3 |
exclusive |
int |
1: play passed file only. 0: play passed file also. |
Sample: Play soundfile c:\mysound.wav in a loop exclusive
res = PLAY_SOUND(c:\\mysound.wav,1,1)
Stop playing all files.
res = PLAY_SOUND(,1,1)
5.1.24 Function GET_EVENT_VAL_L back
Description: Get Value as Long for
specified Event.
Return Type: int
Return Value Table
|
Value |
Meaning |
|
Any Value |
Value demanded for as String. |
|
2147483647 |
Function Call stopped. |
|
2147483646 |
Event not found. |
|
2147483645 |
Value id unknown. |
Parameter Table
|
# |
Name |
Type |
Comment |
|
1 |
Uidevent |
int |
Unique ID of Event. Previously returned by WAIT_FOR_EVENT
or -1 to refer to latest Event. |
|
2 |
Valueid |
int |
Id of Value to be returned. Table 6.11. |
Sample: Get Value of 2. int Member of Event with uid=69 as Long.
retcode = GET_EVENT_VAL_L(69,2)
5.1.25 Function GET_EVENT_VAL_D back
Description: Get Value as Double for
specified Event.
Return Type: double
Return Value Table
|
Value |
Meaning |
|
Any Value |
Value demanded for as String. |
|
888888888888888 |
Function Call stopped. |
|
777777777777777 |
Event not found. |
|
777777777777776 |
Value id unknown. |
Parameter Table
|
# |
Name |
Type |
Comment |
|
1 |
Uidevent |
int |
Unique ID of Event. Previously returned by WAIT_FOR_EVENT
or -1 to refer to latest Event. |
|
2 |
Valueid |
int |
Id of Value to be returned. Table 6.11. |
Sample: Get Value of 2. double Member of Event with uid=69 as
Double.
retcode = GET_EVENT_VAL_D(69,6)
5.2 Contract Related Functions
5.2.1 Function REGISTER_CONTRACT back
Description: Register a Contract. This
Function must be called once before any Function is called that needs a
Contract ID Parameter (e.g. PLACE_ORDER).
Return Type: int
Return Value Table
|
Value |
Meaning |
|
> 0 |
Unique TWSLINK internal Contract ID (UID). Contract
Registration successful. |
|
= 0 |
The Request defines multiple Contracts. |
|
< 0 |
Registration failed. |
Parameter Table
|
# |
Name |
Type |
Comment |
Format/ poss. Values/Sample |
|
1 |
symbol |
LPSTR |
Symbol Name of Contract. |
e.g. MSFT, QM |
|
2 |
sectype |
LPSTR |
Security Type Abbreviation of Contract. |
STK for Stock FUT for Future FOP for Futures Option OPT for Option CASH for Forex BAG for Bag |
|
3 |
currency |
LPSTR |
Currency Abbreviation of Contract. |
USD, EUR, GBP,
|
|
4 |
exchange |
LPSTR |
Exchange of Contract. |
NYSE,DTB,SMART
|
|
5 |
primaryExchange |
LPSTR |
Primary Exchange of Contract. |
|
|
6 |
expiry |
LPSTR |
Expiry of Contract (FUT,FOP,OPT only). |
YYYYMMDD |
|
7 |
right |
LPSTR |
Right of Contract (FOP,OPT only). |
|
|
8 |
strike |
double |
Strike of Contract (FOP,OPT only). |
|
|
9 |
multiplier |
LPSTR |
Multiplier. |
|
|
10 |
Expired_included |
int |
Flag defining if expired Contracts are included. 1 for Yes. |
|
|
11 |
mintick |
double |
Custom Minimum Price Movement. If 0.0 (default), Minimum Price
Movement is taken from Contract Details sent by TWS within Registration
Procedure. |
>= 0.0 Set 0.0 to use Value sent by TWS. |
Comments:
Sample: Register
Contract for November Oil Future at
NYMEX and wait maximal 5 Seconds for Contract being accepted by TWS.
ContractUID = REGISTER_CONTRACT (QM,FUT,USD,NYMEX,,20091119,,0.0,,0,0.0)
Register a Contract
Chain Family- multiple Contracts. To do this let one or more Parameter
empty or Zero. Here register all
November IBM Put Options on Smart.
ContractUID = REGISTER_CONTRACT (IBM,OPT,USD,SMART,,20091119,PUT,0.0,,0,0.0)
ContractUID will be 0 and TWS answers with all
matching Contracts that are all possible Strikes in this sample.
To get a list of all Contract UID affected by the
Requests above, call WAIT_REQ_PROCESSED
and GET_CONTRACTUI_LIST with the same Contract Parameters afterwards.
5.2.2 Function WAIT_FOR_ACCEPTED back
Description: Call this Function to be
certain that your contract has been accepted by TWS and is now ready for trading.
Return Type: int
Return Value Table
|
Value |
Meaning |
|
1 |
Contract accepted by TWS. From now on, Contract uid
can be used. |
|
0 |
Not yet accepted. Timeout. Try again. |
|
-1 |
Not yet accepted. Timeout and currently no
Connection. Try again. |
|
-2 |
Contract not found. Contract uid never cant be
used. |
|
-3 |
Contract has NOT been accepted and was deleted.
Contract uid never cant be used. |
Parameter Table
|
# |
Name |
Type |
Meaning |
Poss. Values |
|
1 |
contractuid |
int |
Unique Contract Id returned by a prior Call of REGISTER_CONTRACT |
> 0 |
|
2 |
timeout |
unsigned |
Timeout in Milliseconds the Functions returns if the Contract still
not accepted. Timeout can happen due to being disconnected currently, in this Case
TWSLink returns -1. Or for other (network, cpu load) reasons. In this Case TWSLink returns
0 and you should try it again. |
= 0, Timeout not active. This is not recommended. If the Status never occurs, the Function will
never return and blocks the calling Thread. > 0 Forces Function Return with current Status, if Time has been
elapsed. |
Comments:
Sample: Wait at most 4 seconds for Contract Status = ACCEPTED. Unique
ID of Contract is 1.
retStatus = WAIT_FOR_ACCEPTED (1, 4000)
if
retStatus = 1 then begin
end //
all good
else if retStatus < -1 then begin
end // all bad, Contract not been accepted.
Check its Definition again. Or Contractuid unknown.
5.2.3 Function GET_CONTRACT_STATUS back
Description: Get the current Status for the specified contract.
Function returns immediately.
Return Type: int
Return Value Table
|
Value |
Meaning |
|
> 0 |
The current Status as Number (Table 6.4). |
|
= 0 |
Contract unknown. |
Parameter Table
|
# |
Name |
Type |
Meaning |
Poss. Values |
|
1 |
contractuid |
int |
Unique Contract Id returned by a prior Call of REGISTER_CONTRACT |
> 0 |
Comments:
Sample: Get the current Status of Contract with id=1.
retStatus = GET_CONTRACT_STATUS (1)
5.2.4 Function REQ_MARKET_DATA back
Description: Subscribe/Unsubscribe Market Data for a
specific or all Contract(s).
Return Type: int
Return Value Table
|
Value |
Meaning |
|
> 0 |
Number of Subscribed/Unsubscribed Market Data. |
|
0 |
Request stacked (will be performed as soon as
possible) or Request erroneous or Contract not found. |
Parameter Table
|
# |
Name |
Type |
Meaning |
Poss. Values |
|
1 |
contractuid |
int |
Unique Contract Id returned by a prior Call of REGISTER_CONTRACT. Or 0 to refer to all registered Contracts. |
> 0, set the Flag for a specific Contract. = 0, set the Flag for all Contracts. |
|
2 |
subscribe |
int |
Subscribe/Unsubscribe Market Data. |
1,0 |
|
3 |
genericTick |
String |
List of comma separated IDs of Market Data Fields. |
|
|
snapshot |
int |
Flag indication if only a Snapshot Request. 2: Snapshot (first) and continuous Market Data
Update. |
|
Sample: Subscribe to Market Data for Contract with UID=1.
ret = REQ_MARKET_DATA (1, 1,,0)
5.2.5 Function GET_CONTRACT_VAL back
Description: Get a specific Contract Value.
Return Type: string (Constant String)
Return Value Table
|
Value |
Meaning |
|
Any String |
The Contract Value of Interest as String. |
|
nok |
Function Call failed due to Function Call disabled
or Contract Status is Not Accepted or internal Error. |
Parameter Table
|
# |
Name |
Type |
Meaning |
Poss. Values |
|
1 |
contractuid |
int |
Unique Contract Id returned by a prior Call of REGISTER_CONTRACT. |
> 0 |
|
2 |
idcontractval |
int |
Id of the Contract Value of Interest. |
|
|
3 |
extraparam |
string |
Additional Parameter which provides the Exchange. - Used for Exchange Name if idcontractval =
CONTRACT_UID. In this case, contractuid is taken as the conid
(provided by IB) and not as the contract uid, which is then returned as
String. - Used as Status ID for all Order Statistic Items.
In this Case pass one of the Status IDs of Table 6.7 or
let empty which means count SUBMITTED Orders only. |
|
|
4 |
account |
string |
Non-Advisor Accounts: Can be empty. Advisor Accounts: Comma-Separated List of Account Names or All to refer to all
Accounts. |
, empty Name1,
|
Sample: Get realised P&L for Contract with UID=1.
ret = GET_CONTRACT_VAL (1,15,,)
Get TWSLINK internal Contract UID (received by REGISTER_CONRACT) of that Contract with Contract ID =
1234588 (conid, unique IB Contract ID) and which is traded at NYSE.
ret = GET_CONTRACT_VAL (1234588,21,NYSE,)
5.2.6 Function CLOSE_CONTRACT back
Description: Close Positions of specified/all registered
contract(s).
Return Type: int
Return Value Table
|
Value |
Meaning |
|
>= 0 |
The Unique ID of Close Order (> 0) or, if passed
Contract UID = 0, the Number of Contracts which are to be closed. |
|
0 |
Contract already closed. |
|
-3 |
Contract not found. |
Parameter Table
|
# |
Name |
Type |
Meaning |
Poss. Values |
|
1 |
Contractuid |
int |
Unique Contract Id returned by a prior Call of REGISTER_CONTRACT. Or 0 to close all registered Contracts (of account
-> #3) . In this Case a Market Order gets performed and so #2 ignored. |
>= 0 |
|
2 |
Price |
double |
If > 0.0, a Limit Order of this Price gets
generated to Close the Contract. If = 0.0, a Market Order gets generated to Close the
Contract. |
>= 0.0 |
|
3 |
account |
string |
Non-Advisor Accounts: Can be empty. Advisor Accounts: Comma-Separated List of Account Names or empty to refer to all
Accounts. |
, empty Name1,
|
|
4 |
typefilter |
string |
Required Type of Contract to be closed. Let empty to disabled
Typefilter (all Types). |
, empty Type
|
Comments:
Sample: Close Positions of Contract with UID=1 at Market.
oidCloseOrder = CLOSE_CONTRACT (1,0.0,,)
Close Positions of Contract with UID=1 at Market.for
FA-Accounts named D110 and DUSR71.
oidCloseOrder = CLOSE_CONTRACT (1,0.0,D110,DUSR71,)
Close all Stocks.
oidCloseOrder = CLOSE_CONTRACT (0,0.0,,STK)
Close all except Stocks.
oidCloseOrder = CLOSE_CONTRACT (0,0.0,,~STK)
5.2.7 Function GET_POSITIONS back
Description: Get Positions of specified Contract.
Return Type: double
Return Value Table
|
Value |
Meaning |
|
<>= 0 |
The current Positions of Contract. |
|
-2147483647 |
Contract not found. |
Parameter Table
|
# |
Name |
Type |
Meaning |
Poss. Values |
|
1 |
contractuid |
int |
Unique |
> 0 |
|
2 |
accounts |
string |
Comma separated List of Accounts or empty. In Case
of FA Account the Sum of Positions is returned. An empty Account String than
returns the Sum of Contract Positions over all Accounts. |
|
Sample: Get Positions of Contract with UID=1 for all Accounts.
positions = GET_POSITIONS (1,)
5.2.8 Function GET_STOPPROTECTION back
Description: Function removed.
5.2.9 Function GET_MARKET_DATA back
Description: Get Market Data Field Value of specified
Contract.
Return Type: double
Return Value Table
|
Value |
Meaning |
|
<=>0 |
Market Data Field Value. |
|
-3 |
Contract not found. |
|
777777777777777 |
Function Call stopped or Value not yet available
(Can happen with #4 > 0 only) |
|
888888888888888 |
Unknown Ticktype (Wrong Value for #2). |
Parameter Table
|
# |
Name |
Type |
Meaning |
Poss. Values |
|
1 |
contractuid |
int |
Unique Contract Id returned by a prior Call of REGISTER_CONTRACT. |
> 0 |
|
2 |
fieldid |
int |
Id of primary Field. |
|
|
3 |
subfieldid |
int |
Id of Subfield. |
|
|
4 |
latest |
int |
If < 0, the Quote from Focus is used . This Quote
has prior been removed from Head of Market Data Stack (oldest Quote, next
Quote from Stack) . If >= 0, current, latest Market Data is returned. |
|
Comments:
Sample: Latest Bid Value for Contract with UID=1.
lastbid = GET_MARKET_DATA (1, 1,0,1)
Next Bid Option Delta for Contract with UID=1 from Stack.
lastbid = GET_MARKET_DATA (1, 10,2,0)
Latest Ask absolute Change in Pips for Contract with UID=19.
lastbid = GET_MARKET_DATA (19,2,5,1)
5.2.10 Function GET_TICK back
Description: Get current/next Tick of specified
Contract.
Return Type: double
Return Value Table
|
Value |
Meaning |
|
>= 0 |
Primary Id of last Tick. (Table 6.12) |
|
-1 |
Not tick since last call of this function or
Function Call breaked. |
|
-3 |
Contract not found. |
|
2147483647 |
Function Call stopped. |
Parameter Table
|
# |
Name |
Type |
Meaning |
Poss. Values |
|
1 |
contractuid |
int |
Unique Contract Id returned by a prior Call of REGISTER_CONTRACT. |
> 0 |
|
2 |
latest |
int |
Specifier from where Tick Type is taken. < 0: Get Tick
Type from oldest Quote on Stack. This also moves oldest Quote from Stack to Focus Quote. All subsequent
Calls of GET_MARKET_DATA(
,-1) than refer to this
Quote. == 0: < Get
Type of latest Tick for specified Contract. > 0. Get Type of latest Tick for specified Contract and reset this
Event. So Calls in fast Series could this Function let return -1, because
there was no Tick in the Meantime. |
<>= 0. |
Comments:
Sample: Get Market Data for next Tick on Stack for Contract with
UID uid.
TickType = GET_TICK(uid, -1)
Now get the tick value depending on its Type.
Switch IdOfLastTick
Case 1: lastBid = GET_MARKET_DATA(2, TickType,0,-1)
Case 2: lastAsk = GET_MARKET_DATA(2, TickType,0,-1)
End Switch
5.2.11 Function QUERY_MARKET_DATA back
Description: Get the queried Market Data in a formatted
string.
Return Type: string
Return Value Table
|
Value |
Meaning |
|
Formatted string |
lt=number|#[type=subtype]+. lt=number|# means that the returned string begins
with a expression type := value from Table 6.12. subtype := value from Table 6.121. |
|
cnf |
Contract not found. Check if #1 defines a valid
Contract. |
|
nok |
Function Call stopped. Contract not found. |
Parameter Table
|
# |
Name |
Type |
Meaning |
Poss. Values |
|
1 |
contractuid |
int |
Unique Contract Id returned by a prior Call of REGISTER_CONTRACT. |
> 0 |
|
descriptor |
string |
Descriptor defining which fields to be returned. The first char defines the delimiter which is the separator of
expressions in the returned string. Descriptor := delim type=subtype[delim type2=subtype2]+ delim := 1 char (e.g. ; or , or #
) type := Number (Table
6.12) subtype := Number (Table
6.121) |
|
Comments:
Sample: Get
current Bid,
absolute change of current Last, Implied Volatility of Bid Option and Ask Size for Contract with UID=1, Use , as Delimiter.
mdstring = QUERY_MARKET_DATA(1, ,1=0,4=3,10=1,3=0)
the returned mdstring could look like:
lt=0,1=35.44,0.04,0.8778,2000
what means: the last tick was a Bid Size (lt=0),
current Bid = 35.44, current change of Last = +0.04, implied Volatility of Bid
Option = 0.8778 and the current Ask Size = 2000.
5.2.12 Function ADD_COMBO_LEG back
Description: Add a Combo Leg to the Contract (Please
refer to IBs API Userguide to
understand Combolegs).
Return Type: int
Return Value Table
|
Value |
Meaning |
|
1 |
Ok. |
|
0 |
Nok. Internal error. |
|
-3 |
Contract not found. |
Parameter Table
|
# |
Name |
Type |
Meaning |
Poss. Values |
|
1 |
contractuid |
int |
Unique Contract Id returned by a prior Call of REGISTER_CONTRACT. |
> 0 |
|
2 |
conid |
int |
Unique IB Contract ID defining the Contract to which the Comboleg
refers to. |
> 0 |
|
3 |
ratio |
int |
Ratio. |
|
|
4 |
openclose |
int |
Open Close. |
|
|
5 |
action |
string |
Action. |
BUY or SELL |
|
6 |
exchange |
string |
Exchange. |
|
|
7 |
shortsaleslot |
int |
Shortsale Slot. |
|
|
8 |
designatedLoc |
string |
Designated Location. |
|
Comments:
5.2.13 Function EXTRACT_MARKET_DATA back
Description: Extract a Value from String prior returned
by GET_MARKET_DATA_STRING.
Return Type: double
Return Value Table
|
Value |
Meaning |
|
1 |
Ok. |
|
0 |
Nok. Internal error. |
|
-3 |
Contract not found. |
Parameter Table
|
# |
Name |
Type |
Meaning |
Poss. Values |
|
1 |
identifier |
int |
Primary Type Identifier. |
|
|
2 |
valueasstring |
string |
Market Data Values prior returned by GET_MARKET_DATA_STRING. |
> 0 |
Sample: Get
Bid from passed String which as has been prior returned by GET_MARKET_DATA_STRING
BidValue = EXTRACT_MARKET_DATA(1, ,1=0,4=3,10=1,3=0)
The returned double Value is the Bid Value e.g.:
11.55
5.2.14 Function GET_CONTRACTUID_LIST back
Description: Get a List of all Contract
unique IDs matching to the passed Parameter. Empty String Parameters or 0
Values for string/number Parameters are not respected for search.
Return Type: string
Return Value Table
|
Value |
Meaning |
|
Any delimited string |
List of Contract unique IDs separated by a Custom
Delimiter (default comma ). |
|
nok |
Function call stopped. Internal Error. |
Parameter Table
|
Name |
Type |
Comment |
Format/ poss. Values/Sample |
|
symbol |
LPSTR |
Symbol Name of Contract. |
e.g. MSFT, QM |
|
sectype |
LPSTR |
Security Type Abbreviation of Contract. |
STK for Stock FUT for Future FOP for Futures Option OPT for Option CASH for Forex |
|
currency |
LPSTR |
Currency Abbreviation of Contract. |
USD, EUR, GBP,
|
|
exchange |
LPSTR |
Exchange of Contract. |
NYSE,DTB,SMART
|
|
primaryExchange |
LPSTR |
Primary Exchange of Contract. |
|
|
expiry |
LPSTR |
Expiry of Contract (FUT,FOP,OPT only). |
YYYYMMDD |
|
right |
LPSTR |
Right of Contract (FOP,OPT only). |
|
|
strike |
double |
Strike of Contract (FOP,OPT only). |
|
|
multiplier |
LPSTR |
Multiplier. |
|
|
delimiter |
LPSTR |
Custom Delimiter separating IDs in the String returned. |
|
|
alias |
LPSTR |
Custom alias name. Let empty to ignore. |
|
Sample: Get
the Unique IDs of all IBM Put Options in USD with Expiry in March 2008 traded
at SMART. Delimiter is #.
ContractUIDList = GET_CONTRACTUID_LIST (IBM,OPT,USD,SMART,,200803,PUT,0.0,#,)
If REGISTER_CONTRACT
prior has been called with a Strike = 0.0 and same Properties, this function
returns the IDs of Options with all possible Strike Prices.
5.2.15 Function EXTRACT_ARRAY_VALUE back
Description:
Return Type: double
Return Value Table
|
Value |
Meaning |
|
value |
The Value been asked. |
|
nok |
Value not exists (Index out of Range). |
Parameter Table
|
# |
Name |
Type |
Meaning |
Poss. Values |
|
1 |
index |
int |
Zero based Index of Value to be returned. |
>= 0 |
|
2 |
arrayasstring |
string |
A String describing an Array of Values. |
Any String |
|
3 |
delimiter |
string |
Delimiter, Value Separator. |
Any legal Character. |
Sample: Get
the 3. Value stored in the passed Array where
Values are separated by ,.
ThirdValue = EXTRACT_ARRAY_VALUE(2,1,2,3,4,5,6,,)
The returned double Value:
3
5.2.16 Function WAIT_FOR_TICK back
Description: Wait for the unique Contract ID of that
Contract having the next Tick or had the latest Tick.
Return Type: double
Return Value Table
|
Value |
Meaning |
|
> 0 |
Uid of Contract which had latest Tick or has next
Tick on Tick Stack (FIFO) if #1 <= 0. |
|
0 |
No Tick available |
|
-1 |
Timeout. |
|
-2 |
Function breaked and not connected |
|
-3 |
Contract not found. |
|
-4 |
Timeout and not connected. |
|
-5 |
Ticktype not matching but Uid matching. |
|
2147483647 |
Function Call stopped (Function Call bypassed). |
Parameter Table
|
# |
Name |
Type |
Meaning |
Poss. Values |
|
1 |
uidfilter |
int |
If > 0, Function waits within timeout until contract specified by #2 has a
tick. In this Case Functions returns either > 0 what means the Contract
had a Tick since last Call or <= 0, what means no Tick occurred since last
Call. If -1 Function returns with UID of
Contract that has the next Tick on Stack. This Tick Event gets removed from
Stack. |
<>= 0. |
|
2 |
ticktype |
int |
Type of Tick which is wanted. Pass -1, to be Ticktype ignored. |
-1, Table 6.12 |
|
3 |
timeout |
int |
Timeout in milliseconds. If 0, Function returns immediately with Values depending on #1. |
>= 0. |
Comments:
WAIT_FOR_TICK
GET_TICK(prior returned contract uid)
Sample: Wait at the most of 50 Seconds for next Tick of any
Contract and remove Contract UID from Tick Stack.
IdOfContractOfNextTick = WAIT_FOR_TICK(-1,-1, 50000)
Now get ticktype of the Contracts next Tick. No wait
necessary, because we know there is a Tick in the
Stack.
IdOfLastTick = 1000000
Process all stored Ticks of this Contract in
chronological order.
While IdOfLastTick > 0
IdOfLastTick = GET_ TICK(IdOfContractOfNextTick ,-1)
Now get the tick value depending on its Type.
Switch IdOfLastTick
Case 1: lastBid =
GET_MARKET_DATA(2, IdOfLastTick,0,-1)
Case 2: lastAsk =
GET_MARKET_DATA(2, IdOfLastTick,0,-1)
Case 10: LastBidOptionDelta
= GET_MARKET_DATA(2, IdOfLastTick,2,-1)
End Switch
End While
5.2.17 Function CLOSE_CASH_POSITION back
Description: Close a Non Base Currency Cash Position.
Return Type: int
Return Value Table
|
Value |
Meaning |
|
>= 0 |
The Unique ID of Close Order (> 0) or, if passed
Contract UID = 0, the Number of Contracts which are to be closed. |
|
0 |
Contract already closed. |
|
-3 |
Contract not found. |
Parameter Table
|
# |
Name |
Type |
Meaning |
Poss. Values |
|
1 |
currency |
string |
Currency Abbreviation. |
EUR,GBP,SEK,.. |
|
2 |
Price |
double |
If > 0.0, a Limit Order of this Price gets
generated to Close the SINGLE Cash Position. Therefore, currency must not be
empty. If = 0.0, a Market Order gets generated to Close the
Contract. |
>= 0.0 |
|
3 |
account |
string |
Non-Advisor Accounts: Can be empty. Advisor Accounts: Comma-Separated List of Account Names or empty to refer to all
Accounts. |
, empty Name1,
|
Comments:
Sample: Close GBP Positions in Portfolio.
oidCloseOrder = CLOSE_CASH_POSITION(GBP,0.0,)
Close all Non Base-Currency Cash at Market.for
FA-Accounts named D110 and DUSR71.
oidCloseOrder = CLOSE_CASH_POSITION (,0.0,D110,DUSR71)
5.2.18 Function FORCE_CONTRACT back
Description: Enforce relative or absolute Positions for
Contract.
Return Type: int
Return Value Table
|
Value |
Meaning |
|
>= 0 |
The Unique ID of Force Order (> 0) or, if passed
Contract UID = 0, the Number of Contracts which are to be closed. |
|
0 |
Contract already has Positions, Type is not
matching. |
|
-3 |
Contract not found. |
Parameter Table
|
# |
Name |
Type |
Meaning |
Poss. Values |
|
1 |
Contractuid |
int |
Unique Contract Id returned by a prior Call of REGISTER_CONTRACT. Or 0 to close all registered Contracts (of account
-> #3) . In this Case a Market Order gets performed and so #2 ignored. |
>= 0 |
|
2 |
newSize |
double |
Either the new Size as absolute Value, |
< = > 0 |
|
3 |
isrelative |
int |
Flag defining if #2 defines a relative size or
absolute. Value = 0: #2 is absolute Size. |
1,0 |
|
2 |
Price |
double |
If > 0.0, a Limit Order of this Price gets
generated to Close the Contract. If = 0.0, a Market Order gets generated to Close the
Contract. |
>= 0.0 |
|
3 |
account |
string |
Non-Advisor Accounts: Can be empty. Advisor Accounts: Comma-Separated List of Account Names or empty to refer to all
Accounts. |
, empty Name1,
|
|
4 |
typefilter |
string |
Required Type of Contract to be closed. Let empty to disabled
Typefilter (all Types). |
, empty Type
|
Comments:
Sample: Switch Positions of Contract with UID=1 at Market.
oidForceOrder = FORCE_CONTRACT (1,-100,1,0.0,,)
Force contract of UID=1 for absolute 76 positions (int)
at limit 69.66
oidForceOrder = FORCE_CONTRACT(1,76,0,69.66,,)
5.2.19 Function SET_INDICATOR_LENGTH back
Description: Set the Length of an Indicator.
Return Type: int
Return Value Table
|
Value |
Meaning |
|
> 0 |
Number of Lengths set. |
|
0 |
No Indicator Length set. (wrong indicator ID). |
Parameter Table
|
# |
Name |
Type |
Meaning |
Poss. Values |
|
1 |
uidcontract |
int |
Unique Contract ID. Pass 0 to affect all registered
Contracts. |
>= 0 |
|
2 |
idindicator |
int |
Indicator ID. Table 6.17. Pass 0
to affect all Contracts and to apply default Length. |
>= 0 |
|
3 |
length |
int |
Length. Pass 0, to disabled Indicator. Pass -1 to apply default
Length. Pass > 0 for specific Length. |
,-1, >= 0 |
Comments:
Sample: Apply Default Length for all Indicators in all Contracts.
nbr = SET_INDICATOR_LENGTH(0,0,-1)
Set Length of N2 Ask Moving Average of Contract with
UID=7 to 400.
nbr = SET_INDICATOR_LENGTH(7,9,400)
5.2.20 Function VALIDATE_PRICE back
Description: Return the next Price as
double for passed double value that matches to the Contracts minimum Price
Variation.
Return Type: double
Return Value Table
|
Value |
Meaning |
|
> 0 |
The amended Price. |
|
#1 |
Function Call stopped or Price matches to minimum
Price Variation. |
Parameter Table
|
# |
Name |
Type |
Meaning |
Poss. Values |
|
1 |
uidcontract |
int |
Unique Contract ID. |
> 0 |
|
2 |
Price |
double |
Value of Price to be amended. |
> 0 |
|
3 |
ceil |
int |
1. ceil Price |
1,0 |
.
Sample: Get the next lower valid Price of passed Price for
Contract with UID=6 which minimum Price Move = 0.01.
NewPrice = VALIDATE_PRICE(6,45.047,0)
NewPrice = 45.04
5.2.21 Function REM_COMBO_LEG back
Description: Remove one or more Combo Legs
from Contract (Please refer to IBs API
Userguide to understand Combolegs).
Return Type: int
Return Value Table
|
Value |
Meaning |
|
1 |
Ok. |
|
0 |
Nok. Internal error. |
|
-3 |
Contract not found. |
Parameter Table
|
# |
Name |
Type |
Meaning |
Poss. Values |
|
1 |
contractuid |
int |
Unique Contract Id returned by a prior Call of REGISTER_CONTRACT. |
> 0 |
|
2 |
conid |
int |
Unique IB Contract ID defining the Contract to which the Comboleg
refers to. |
> 0 |
|
3 |
ratio |
int |
Ratio. |
<>= 0 |
|
4 |
openclose |
int |
Open Close. |
<>= 0 |
|
5 |
action |
string |
Action. |
BUY or SELL or |
|
6 |
exchange |
string |
Exchange. |
<>= 0 |
|
7 |
shortsaleslot |
int |
Shortsale Slot. |
<>= 0 |
|
8 |
designatedLoc |
string |
Designated Location. |
|
Comments:
5.2.22 Function SET_CONTRACT_VAL back
Description: Change some contract values
after registration.
Return Type: int
Return Value Table
|
Value |
Meaning |
|
1 |
Ok. |
|
0 |
Nok. Function Call stopped. |
|
-1 |
Contract Not found. |
|
-2 |
Value read only. |
Parameter Table
|
# |
Name |
Type |
Meaning |
Poss. Values |
|
1 |
contractuid |
int |
Unique Contract Id returned by a prior Call of REGISTER_CONTRACT. |
> 0 |
|
2 |
valueid |
int |
ID of Value to be changed. |
Table 6.5 (green) |
|
3 |
value |
string |
Value as String. |
|
Sample: Set a custom Mintick of 0.005 for Contract with uid=69.
Ret = SET_CONTRACT_VAL(69,20,0.005)
5.2.23 Function REQ_BAR_DATA back
Description: Subscribe/Unsubscribe
for/from 5 Seconds based Realtime
Bars.
Return Type: int
Return Value Table
|
Value |
Meaning |
|
1 |
Number of affected contracts. |
|
-1 |
Contract Not found (if #1 > 0). |
|
-2 |
Value read only. |
Parameter Table
|
# |
Name |
Type |
Meaning |
Poss. Values |
|
1 |
contractuid |
int |
Unique Contract Id returned by a prior Call of REGISTER_CONTRACT. |
>= 0 |
|
2 |
subscribe |
int |
1: Subscribe |
0,1 |
|
3 |
timeframe |
int |
Timeframe in Seconds. Must be
integer dividable by 5 Seconds (5, 10, 35,
) |
Mod 5 |
|
4 |
datatype |
int |
ID of Data to be retrieved. |
0 = TRADES 2 = ASK 3 = MIDPOINT 4 = All |
|
5 |
rthonly |
int |
0: Include outside Regular Tradings Hours also. |
0,1 |
Comments:
Sample: Request 15 Seconds Ask Bars for Contract with uid=69;
Allow Bars outside Regular Trading Hours.
Ret = REQ_BAR_DATA(69,1,15,2,0)
5.2.24 Function GET_BAR_DATA back
Description: Access specific Bar Data.
Return Type: double
Return Value Table
|
Value |
Meaning |
|
Any Value |
Value of desired Data. |
|
777777777777777 |
Function Call stopped. |
|
888888888888888 |
Value ID unknown. |
|
999999999999999 |
Contract Not found. |
Parameter Table
|
# |
Name |
Type |
Meaning |
Poss. Values |
|
1 |
contractuid |
int |
Unique Contract Id returned by a prior Call of REGISTER_CONTRACT. |
> 0 |
|
2 |
dataid |
int |
ID of Bar Data to be retrieved. |
0 = TRADES 2 = ASK 3 = MIDPOINT |
|
|
valueid |
int |
ID of Value to be retrieved. |
|
|
3 |
timeframe |
int |
Timeframe in Seconds. Must be
integer dividable by 5 Seconds (5, 10, 35,
) |
Mod 5 |
|
4 |
idx |
string |
Index of Historical Bar. By Default 50 Bars get stored for Access.
The lower Index the younger the Bar. The current Bar has Index 0. Bars of
Index > 0 have been closed. Bar of Index n is younger than Bar of Index
n+1, n >= 0. |
>= 0 |
Comments:
Sample: Get High-Value of current 15 Seconds Bid Bars for
Contract with uid=69.
Ret = GET_BAR_DATA(69,1,3,15,0)
5.2.25 Function REGISTER_CONTRACT_XML back
Description: Register Contracts defined in
an xml-file.
Return Type: int
Return Value Table
|
Value |
Meaning |
|
>= 0 |
Number of registered Contracts. |
|
-1 |
Filename empty. |
|
-2 |
Load File failed. Check Logfile for more
Information. |
|
-3 |
Memory Error. |
|
-4 |
Parsing Error. |
|
-5 |
Function Call stopped. |
Parameter Table
|
# |
Name |
Type |
Meaning |
Poss. Values |
|
1 |
pathandfile |
string |
Completed Path and Filename. |
Not empty |
|
2 |
ignoreloadflag |
int |
Flag defining if ignoring all load flags that are 0. 1. Load all Contracts defined in File. 0. Load only Contracts in File which load-flag >
0. |
0,1 |
Comments:
Further, all uids must be unique over all files loaded.
Sample: Register Contracts from File c:\trading\funny_basket.xml.
Dont ignore load flag.
Ret = REGISTER_CONTRACT_XML(c:\trading\funny_basket.xml,0)
5.2.26 Function REGISTER_CONTRACT_XML_STYLE back
Description: Register Contracts which
Properties are given by a String in the Format of an XML-Tag.
Return Type: int
Return Value Table
|
Value |
Meaning |
|
>= 0 |
Number of registered Contracts. |
|
-1 |
Filename empty. |
|
-2 |
Load File failed. Check Logfile for more
Information. |
|
-3 |
Memory Error. |
|
-5 |
Function Call stopped. |
Parameter Table
|
# |
Name |
Type |
Meaning |
|
1 |
attributeset |
string |
Space separated List of Attributes and Values listed
in Table 6.20 |
Comments:
Sample: Register Contracts MSFT Stock, with Currency USD at
SMART. Contract Details get requested
because
Attribute
dtr is not listed with value = 0 (dtr=0).
Ret = REGISTER_CONTRACT_XML_STYLE(typ=STK
sbl=MSFT cur=USD exc=SMART)
5.2.27 Function REQ_MARKET_DEPTH back
Description: Subscribe/Unsubscribe Market Depth for a
specific or all Contract(s).
Return Type: int
Return Value Table
|
Value |
Meaning |
|
> 0 |
Number of Subscribed/Unsubscribed Market Depth. |
|
0 |
Request stacked (will be performed as soon as
possible) or Request erroneous or Contract not found. |
Parameter Table
|
# |
Name |
Type |
Meaning |
Poss. Values |
|
1 |
contractuid |
int |
Unique Contract Id returned by a prior Call of REGISTER_CONTRACT. Or 0 to refer to all registered Contracts. |
> 0, set the Flag for a specific Contract. = 0, set the Flag for all Contracts. |
|
2 |
subscribe |
int |
Subscribe/Unsubscribe Market Data. |
1,0 |
|
3 |
numrows |
int |
Number of Market Depth Rows. |
|
Comments:
Sample: Subscribe to Market Depth for Contract of UID=1 with 4
Rows each Side.
ret = REQ_MARKET_DEPTH (1, 1,4)
5.2.28 Function GET_MARKET_DEPTH back
Description: Access specific Market Depth
Value.
Return Type: string
Return Value Table
|
Value |
Meaning |
|
Any String |
Value of desired Data. |
|
nok |
Function Call stopped. |
|
mdnf |
Market Depth Row not found. |
|
mdno |
No Market Depth. Either not yet received or not
requested for. |
|
cnf |
Contract not found. |
Parameter Table
|
# |
Name |
Type |
Meaning |
Poss. Values |
|
1 |
contractuid |
int |
Unique Contract Id returned by a prior Call of REGISTER_CONTRACT. |
> 0 |
|
2 |
side |
int |
Side of Market Depth Row. 2=Both (for some types only) |
0= Ask 1 = Bid 2 = Both |
|
3 |
position |
int |
Zero based Index of MD Row of Interest. |
|
|
4 |
type |
int |
The Type of required Market Depth Information. |
Comments:
Sample: Get Snapshot of Bid Side for Contract with UID=67.
Ret = GET_MARKET_DEPTH(67,0,-1,0)
Get Market Maker of 2. Ask Row for Contract with
UID=67.
Ret = GET_MARKET_DEPTH(67,1,1,5)
5.2.29 Function GET_MARKET_DEPTH2 back
Description: Access specific Market Depth
Value.
Return Type: double
Return Value Table
|
Value |
Meaning |
|
Any Value |
Value of desired Data. |
|
-1 |
Function Call stopped. |
|
-2 |
Contract not found. |
|
-3 |
Market Depth Row not found. |
|
-4 |
Invalid Type (either unknown or not valid for real
number return) |
|
-5 |
No Market Depth. Either not yet received or not
requested for. |
Parameter Table
|
# |
Name |
Type |
Meaning |
Poss. Values |
|
1 |
contractuid |
int |
Unique Contract Id returned by a prior Call of REGISTER_CONTRACT. |
> 0 |
|
2 |
side |
int |
Side of Market Depth Row. 2=Both fails here. |
0= Ask 1 = Bid |
|
3 |
position |
int |
Zero based Index of MD Row of Interest. |
|
|
4 |
type |
int |
The Type of required Market Depth Information. |
Comments:
Sample: Get 2. Bid Price for Contract with UID=67.
Ret = GET_MARKET_DEPTH2(67,0,1,3)
Get 1. Ask Size for Contract with UID=67.
Ret = GET_MARKET_DEPTH2(67,1,0,4)
5.2.30 Function REQ_HIST_DATA back
Description: Request Historical Data for
Contract.
Return Type: int
Return Value Table
|
Value |
Meaning |
|
Any Value |
Number of affected Requests. |
|
0 |
Failed for any reason (see logfile). |
|
-1 |
Function Call stopped. |
|
-3 |
No memory. |
Parameter Table
|
# |
Name |
Type |
Meaning |
Poss. Values |
|
1 |
contractuid |
int |
Unique Contract Id returned by a prior Call of REGISTER_CONTRACT. |
> 0 |
|
2 |
endtime |
string |
Endtime as String.Format: YYYYMMDD[ hh:mm:ss[ TMZ]] |
|
|
3 |
duration |
string |
Duration Term, Format: n [S|D|W|M|Y] (20 Days -> 20 D) |
n >= 1 |
|
4 |
barsize |
string |
Size of a single Bar, Format: |
|
|
5 |
whattoshow |
string |
|
|
|
6 |
useRTH |
int |
Bars from Regular Trading Hours only 1 or all 0. |
1,0 |
|
7 |
DateFormatStyle |
int |
Style of Date Format of Bars. |
1,2 |
Comments:
Sample: Get
1 Month in hourly Resolution for Contract with uid=1974. Allow also Bars
outside from Regular Trading Hours. Let the Bars Date be returned in Style 1.
Ret = REQ_HIST_DATA(1974,20080220,1 M,1
hour,0,1)
5.2.31 Function REQ_SCANNER_PARAMETER back
Description: Request Parameter for Market
Scanner.
Return Type: string
Return Value Table
|
Value |
Meaning |
|
Parameter |
Scanner Parameter as String, |
|
emtpy |
No Parameter currently available. |
|
nok |
Contract not found. |
Parameter Table
|
# |
Name |
Type |
Meaning |
Poss. Values |
|
1 |
timeout |
int |
Timeout in milliseconds. |
>= 0 |
Comments:
Sample: Wait
at the most of 1 Second for Scanner Parameter.
ScannerParam = REQ_SCANNER_PARAMETER(1000)
5.2.32 Function REQ_SCANNER_SUBSCRIPTION back
Description: Subscribe to Market Scanner
Data.
Return Type: int
Return Value Table
|
Value |
Meaning |
|
> 0 |
Id of request. You need this cancel subscription. |
|
0 |
Request failed due to not connected. |
|
-1 |
Function Call Stopped. |
|
-2 |
Memory Error. |
Parameter Table
|
# |
Name |
Type |
Meaning |
Poss. Values |
|
1 |
numberOfRows |
int |
Number of records returned |
|
|
2 |
instrument |
string |
Instrument type. (STK,FUT,OPT,FOP,CASH,BOND) |
|
|
3 |
locationCode |
string |
E.g. STK.US -> US Stocks |
|
|
4 |
scanCode |
string |
E.g. TOP_PERC_GAIN (REQ_SCANNER_PARAMETER) |
|
|
5 |
abovePrice |
double |
|
|
|
6 |
belowPrice |
double |
|
|
|
7 |
aboveVolume |
int |
|
|
|
8 |
marketCapAbove |
double |
|
|
|
9 |
marketCapBelow |
double |
|
|
|
10 |
stockTypeFilter |
string |
|
|
|
11 |
moodyRatingAbove |
string |
The Gurus minimum rating |
|
|
12 |
moodyRatingBelow |
string |
The Gurus maximum rating |
|
|
13 |
spRatingAbove |
string |
The Gurus minimum rating |
|
|
14 |
spRatingBelow |
string |
The Gurus maximum rating |
|
|
15 |
excludeConvertible |
int |
Flag |
0,1 |
|
16 |
avgOptionValueAbove |
int |
|
|
|
17 |
scannerSettingParis |
string |
e.g. Annual,true or Weekly,true |
|
|
18 |
couponRateAbove |
double |
|
|
|
19 |
couponRateBelow |
double |
|
|
|
20 |
maturityDateAbove |
string |
Format: YYYYMMDD |
|
|
21 |
maturityDateBelow |
string |
Format: YYYYMMDD |
|
Comments:
Sample: Get
the 10 best US-Stocks with Price above 3.0. Best means here winner by percentage gain.
subscriptionId =
REQ_SCANNER_SUBSCRIPTION(10,STK,STK.US,TOP_PERC_GAIN,3.0,0.0,0,100000000.0
,0.0,,,,,,0,0,Annual,true,0.0,0.0,,)
5.2.33 Function CANCEL_SCANNER_SUBSCRIPTION back
Description: Cancel Data for Market
Scanner.
Return Type: string
Return Value Table
|
Value |
Meaning |
|
1 |
Ok |
|
0 |
Unknown subscription |
Parameter Table
|
# |
Name |
Type |
Meaning |
Poss. Values |
|
1 |
subscriptionid |
int |
Id of Subscription to be cancelled. This Id was
previously returned by a call of REQ_SCANNER_SUBSCRIPTION |
>= 0 |
Sample: Cancel
Subscription with id=1977.
ret = CANCEL_SCANNER_SUBSCRIPTION(1977)
5.2.34 Function PIPS back
Description: Get Number of Pips for passed
Price.
Return Type: int
Return Value Table
|
Value |
Meaning |
|
>= 0 |
Ok |
|
-1 |
Contract not found |
Parameter Table
|
# |
Name |
Type |
Meaning |
Poss. Values |
|
1 |
contractid |
int |
Id of contract #2 refers to. |
> 0 |
|
2 |
price |
double |
Price value to be converted in PIPS. |
>= 0 |
Sample: Get
number of pips of passed price-difference for contract with uid=111.
nop = PIPS(111,23.455-23.667)
5.2.35 Function REQ_FUNDAMENTAL_DATA back
Description: Request Reuters Fundamental
Data for Contract.
Return Type: int
Return Value Table
|
Value |
Meaning |
|
Any Value |
Number of affected Requests. |
|
0 |
Failed for any reason (see logfile). |
|
-1 |
Function Call stopped. |
|
-3 |
No memory. |
Parameter Table
|
# |
Name |
Type |
Meaning |
Poss. Values |
|
1 |
contractuid |
int |
Unique Contract Id returned by a prior Call of REGISTER_CONTRACT. |
> 0 |
|
2 |
reporttype |
string |
Type of report |
estimates |
|
3 |
Path_and_file |
string |
Path and name of file request result is written to. |
Empty or not |
Comments:
http://www.interactivebrokers.com/en/software/apiReleaseNotes/api95.php?ib_entity=llc#9.5_reuters
Sample: Get
estimates for contract with uid=1974 reflected through callback
Ret = REQ_FUNDAMENTAL_DATA(1974,estimates,)
5.3 Order Related Functions
5.3.1 Function PLACE_ORDER back
Description: Place a new Order or modify an existing
One.
Return Type: int
Return Value Table
|
Value |
Meaning |
|
> 0 |
OK: The Unique ID of Order. |
|
<= 0 |
Order Place failed for any Reason. (Table
6.8) |
Parameter Table
|
# |
Name |
Type |
Meaning |
Poss. Values |
Default for Modify |
|
1 |
contractuid |
int |
Unique Contract Id returned by a prior Call of REGISTER_CONTRACT. |
> 0 |
|
|
2 |
uidorder |
int |
A unique Order ID > 0 in Case of Modifying an Order. Pass 0 if you want to create a new Order. |
>= 0. If 0, a new Order gets created. If > 0, TWSLINK looks for an Order which UID matches to this ID and
modifies this Order. |
|
|
3 |
action |
string |
Order Side. |
BUY,SELL |
(empty) |
|
4 |
ordertype |
string |
Order Type. |
All Ordertype Abbreviations accepted by TWS. |
(empty) |
|
5 |
totalquantitiy |
int |
Order Size. |
|
0 |
|
6 |
limitprice |
double |
Limit Price. |
|
-1.0 |
|
7 |
auxprice |
double |
Stop Price. |
|
-1.0 |
|
8 |
tif |
string |
Time in Force Abbreviation. |
DAY,GTC,
(TWS Doc.) |
(empty) |
|
Transmission flag |
int |
Transmission Flag. If -1, the Order
simply gets created on DLL Side (cant be seen at TWS). If 0, Order gets
created on TWS Side. (can be seen at TWS with the blue T or red T). If 1, the Order
gets immediately transmitted to IB. |
-1,0,1 |
1 (transmit to IB) |
|
|
10 |
uidparentorder |
int |
The unique ID of a Parent Order. |
>= 0 (0 no Order attached) |
= 0 |
|
11 |
GTD |
string |
Good till Date. (YYYYMMDD HH:MM:SS) |
|
(empty) |
|
12 |
GAT |
string |
Good after Time. (YYYYMMDD HH:MM:SS) |
|
(empty) |
|
13 |
overwritetimeout |
int |
Specific Timeout for this Order in Minutes (Dominates Value passed for
INITDLL). |
-1, do not overwrite Timeout 0, disable Timeout > 0, set this Timeout |
|
Comments:
To set Values for these Properties, place the Order with transmit=-1 or 0, call Function SET_ORDERVAL to set the Property Value and call TRANSMIT with prior
returned Order UID.
Sample: Place a new BUY STOP LIMIT Order for Contract UID=1 with 100 Shares. Transmit immediately.
MyNewOrderID = PLACE_ORDER(1,0,BUY,STP LMT,100,486.00,486.20,GTC,1,0,,,-1)
Implicit Attachment and explicit Transmission:
Create a new BUY MARKET Order for Contract
UID=1 with an attached STOP ORDER and PROFIT ORDER. Create on TWS Side only.
MyMktOrderID = PLACE_ORDER(1,0,BUY,MKT,100,0.0,0.0,GTC,-1,0,,,-1)
Create the STOP ORDER and attach it to MKT Order.
Create on DLL Side only.
MyStopOrderID =
PLACE_ORDER(1,0,BUY,STP,100,0.0,460.00,GTC,-1,MyMktOrderID,,,-1)
Create the PROFIT ORDER and attach it to MKT Order.
Create on DLL Side only.
MyProfitOrderID
= PLACE_ORDER(1,0,SELL,LMT,100,
500.00,0.0 ,GTC,-1,MyMktOrderID,,,-1)
Transmit the Parent Order which activates attached
Orders also.
TRANSMIT(MyMktOrderID,0,)
Implicit Attachment and implicit Transmission:
Place a Parent Order unstransmitted to IB (oi1) and place a Child Order (oi2) implicitly
attached to Parent Order. Parent Order (oi1) gets implicitly transmitted to IB
through Transmission for Child Order (oi2).
oid1=PLACE_ORDER(UidContract,0,"SELL","LMT",30000,1.481,0.0,"GTC",0,0,"","",-1)
oid2=PLACE_ORDER(UidContract,0,"SELL","LMT",30000,1.481,0.0,"GTC",
1, oid1,"","",-1)
5.3.2 Function SET_ORDERVAL back
Description: Change/Set an Order Property.
Return Type: int
Return Value Table
|
Value |
Meaning |
|
1 |
Property could be set. |
|
0 |
Property could not be set. (Value ID not found, Order not found, Order
not modifyable
). Check the Trace File for more Information. |
Parameter Table
|
# |
Name |
Type |
Meaning |
Poss. Values |
|
1 |
uidorder |
int |
Unique Order Id returned by a prior Call of PLACE_ORDER. |
> 0 |
|
2 |
propertyid |
int |
Order Property Identifier. |
|
|
3 |
Val |
string |
Property Value as String. The TWSLINK performs necessary Conversions. |
|
|
Transmission flag |
int |
Transmission Flag. If -1, the property gets
changed internally only. If 0, the property gets
changed and order transmitted to TWS again (can be seen at TWS with the blue T or red T). If 1, the property gets
changed and the order transmitted to IB. |
|
Comments:
Sample: Place a new BUY STOP LIMIT Order for Contract UID=57 with 100 Shares. Transmit immediately.
MyNewOrderID =
PLACE_ORDER(1,0,BUY,STP
LMT,100,486.00,486.20,GTC,-1,0,,,-1)
Set the OCA Group and Type for a newly created Order
with ID=57.
bret = SET_ORDERVAL (MyNewOrderID,19,MyGroup47,-1)
Set the Order Reference and transmit Order to IB.
bret = SET_ORDERVAL (MyNewOrderID,49,Random
Walk Strategy,1)
5.3.3 Function WAIT_FOR_ORDER_STATUS back
Description: Wait for a specific Order Status. This
Function usually is called to ascertain that an Order has a Status which
confirms that the Order has been filled or is working at Destination.
Return Type: int
Return Value Table
|
Value |
Meaning |
|
> 0 |
The current status. Either due to Status equals to
Parameter #2 or due to Timeout. |
|
= -1 |
The order status matches to statusbreakid. |
|
= 0 |
Order unknown. |
Parameter Table
|
# |
Name |
Type |
Meaning |
Poss. Values |
|
1 |
Orderuid |
int |
Unique Order Id returned by a prior Call of PLACE_ORDER. |
> 0 |
|
2 |
Status |
int |
Identifier of asked Status. The Function returns if the Order Status
fits to this Value. On Success, the Function returns this Value. |
|
|
3 |
Timeout |
unsigned |
Timeout in Milliseconds the Functions returns if the asked Status not
fits. If the Timeout is triggered, the Function returns the current Status. |
>= 0 |
|
4 |
statusidbreak |
int |
Second Status Identifier that breaks the Function. This
Parameter is thought as a Break Condition. If the Status of the Order equals to this Parameter Value, The
Function returns -1. |
Or -1. If statusidbreak = -1, no Break Condition is respected. |
Sample: Wait
for Status Submitted for the newly placed LIMIT Order. Break at the latest of
3 Seconds or if the Order is erroneous.
ostatus = WAIT_FOR_ORDER_STATUS( LMTOrderID,8,3000,12)
if ostatus = -1 then begin
--- do something to get out of trouble
end // place Order probably failed
else begin
.end // all good
5.3.4 Function WAIT_FOR_ORDER_STATUS_RNG back
Description: Wait for one of the Contract States defined
by the
Return Type: int
Return Value Table
|
Value |
Meaning |
|
> 0 |
The Current Status. Either due to Status lies
between Parameter #2 and Parameter #3 or due to Timeout. |
|
= -1 |
The order status matches to statusbreakid. |
|
= 0 |
Order unknown. |
Parameter Table
|
# |
Name |
Type |
Meaning |
Poss. Values |
|
1 |
Orderuid |
int |
Unique Order Id returned by a prior Call of PLACE_ORDER. |
> 0 |
|
2 |
lowerstatus |
int |
Identifier of lower Status. The Function returns if the Contract
Status >= Parameter #2 and <
Parameter #3. The returned Value
is the current Status. |
|
|
3 |
upperstatus |
int |
Identifier of upper Status. |
|
|
4 |
Timeout |
unsigned |
Timeout in Milliseconds the Functions returns if the asked Status not
fits. If the Timeout is triggered, the Function returns the current Status. |
= 0, Timeout not active. This is not recommended. If the Status never occurs, the Function will
never return and blocks the calling Thread. > 0 Forces Function Return with current Status, if Time has been
elapsed. |
|
5 |
statusidbreak |
int |
Second Status Identifier that breaks the Function. This Parameter is
thought as a Break Condition. If the Status of the Order equals to this Parameter Value, the
Function returns -1. |
Or -1. If statusidbreak = -1, no Break Condition is respected. |
Sample: Wait
for one of the Submitted States of the newly placed LIMIT Order. Break at the
latest of 3 Seconds or if the Order is erroneous.
ostatus = WAIT_FOR_ORDER_STATUS_RNG( LMTOrderID,5,8,3000,12)
5.3.5 Function GET_ORDER_STATUS back
Description: Get the current Order Status. Functions
returns immediately.
Return Type: int
Return Value Table
|
Value |
Meaning |
|
> 0 |
The Current Status. (Table 6.7) |
|
= 0 |
Contract unknown. |
Parameter Table
|
# |
Name |
Type |
Meaning |
Poss. Values |
|
1 |
orderuid |
int |
Unique Order Id returned by a prior Call of PLACE_ORDER. |
> 0 |
Sample: Get the Status of Order with UID=17.
ostatus = GET_ORDER_STATUS ( 17)
5.3.6 Function GET_ORDER_ERROR back
Description: Get Error related to Order, if the last PLACE_ORDER Call caused an Error.
Return Type: int
Return Value Table
|
Value |
Meaning |
|
> 0 |
Current Order Error (Table 6.9). |
|
= 0 |
Order has no Error. |
Parameter Table
|
# |
Name |
Type |
Meaning |
Poss. Values |
|
1 |
orderuid |
Long |
Unique Order Id returned by a prior Call of PLACE_ORDER. |
> 0 |
Comments:
Sample: Get the error ID of Order with UID=17.
oerror = GET_ORDER_ERROR ( 17)
5.3.7 Function ATTACH back
Description: Attach one Order to another.
Return Type: int
Return Value Table
|
Value |
Meaning |
|
1 |
Order successfully attached. |
|
0 |
Attachment failed. |
Parameter Table
|
# |
Name |
Type |
Meaning |
Poss. Values |
|
1 |
Uidchildorder |
int |
Unique ID of Child Order. |
> 0 |
|
2 |
Uidparentorder |
int |
Unique ID of Parent Order. |
> 0 |
Comments:
Sample: Attach Order with UID=12 to Order with UID=11.
ret = ATTACH( 12,11)
5.3.8 Function ORDER_MODIFIABLE back
Description: Check if an Order can be modified.
Return Type: int
Return Value Table
|
Value |
Meaning |
|
1 |
Order can be modified. |
|
0 |
Order can not be modified. |
Parameter Table
|
# |
Name |
Type |
Meaning |
Poss. Values |
|
1 |
uidorder |
int |
Unique ID of Order. |
> 0 |
Comments:
Sample: Check if Order with UID=12 can be modified.
ret = ORDER_ MODIFIABLE ( 12)
5.3.9 Function TRANSMIT back
Description: Place Order(s) again with Transmission-Flag
= 1 → Transmit to IB Server.
Return Type: int
Return Value Table
|
Value |
Meaning |
|
1 |
Order transmitted. |
|
0 |
Order not transmitted. Can have various Reasons,
such as Order not found. Check the Trace File for more Information. |
Parameter Table
|
# |
Name |
Type |
Meaning |
Poss. Values |
|
1 |
uidorder |
int |
Unique ID of Order. If > 0, only this Order gets transmitted. If == 0, all Orders of referenced Contract (#2) get
transmitted. If < 0, all Orders of referenced Contract (#2) get
transmitted, except that Order which negative UID=#1. |
<>= 0 |
|
2 |
uidcontract |
int |
Unique ID of Contract. If > 0 and uidorder = 0, all Orders of Contract
get transmitted. |
>= 0 |
|
3 |
otypefilter |
string |
Order Type Filter. Evaluated only if #1=0 and this Parameter is not empty. Transmit Orders which Order Type matches to this Parameter only. |
, empty or any Ordertype Abbr. |
Comments:
Sample: Transmit Order with UID=12.
ret = TRANSMIT (12,0,)
Transmit all Orders of Contract with UID=1.
ret = TRANSMIT (0,1,)
Transmit all Orders of all registered Contracts.
ret = TRANSMIT (0,0,)
Transmit all STOP Orders of Contract with UID=1,
except Order with UID=12
ret = TRANSMIT (-12,1,STP)
5.3.10 Function CANCEL_ORDER back
Description: Cancel one or more Orders.
Return Type: int
Return Value Table
|
Value |
Meaning |
|
1 |
Order(s) cancelled. |
|
0 |
One or more Order(s) could not be cancelled. Can
have various Reasons, such as Order not found. Check the Trace File for more Information. |
Parameter Table
|
# |
Name |
Type |
Meaning |
Poss. Values |
|
1 |
uidorder |
Long |
Unique ID of Order. If > 0, only this Order gets cancelled. If == 0, all Orders of referenced Contract (#2) get
cancelled. If < 0, all Orders of referenced Contract (#2)
get cancelled, except that Order which negative UID=#1. |
<>= 0 |
|
2 |
uidcontract |
Long |
Unique ID of Contract. If > 0 and uidorder = 0, all Orders of Contract
get cancelled. |
>= 0 |
|
3 |
otypefilter |
string |
Order Type Filter. Evaluated only if #1=0 and this Parameter is not empty. Cancel Orders which Order Type matches to this Parameter only. |
, empty or any Ordertype Abbr. |
|
4 |
submitted |
int |
Submitted Status Indicator. 1=Submitted only (Orders with Status = 5,7 or 8). 0=Unsubmitted only. -1=Discard Order Status. |
<=> 0 |
|
5 |
side |
string |
Side / Action of Order: BUY,SELL, |
for discard |
Comments:
Sample: Cancel Order with UID=12.
ret = CANCEL_ORDER (12,0,,-1,)
Cancel all Orders of Contract with UID=2.
ret = CANCEL_ORDER (0,2, ,-1,)
Cancel all STOP Orders of Contract with UID=2 except
Order with UID=12
ret = CANCEL_ORDER (0,2,STP ,-1,)
Cancel all Stop Orders of all registered Contracts that
are submitted.
ret = CANCEL_ORDER (0,0,STP ,1,)
5.3.11 Function SET_FA_MEMBERS back
Description: Change/Set those Properties
of an Order that are related to FA
Accounts. This is a more handy
Function that shall simplify Placements of Orders for FA
Accounts.
Return Type: int
Return Value Table
|
Value |
Meaning |
|
1 |
Properties could be set. |
|
0 |
Properties could not be set. (Order not found, Order not modifyable
).
Check the Trace File for more Information. |
Parameter Table
|
# |
Name |
Type |
Meaning |
Poss. Values |
|
1 |
uidorder |
int |
Unique Order Id returned by a prior Call of PLACE_ORDER. |
> 0 |
|
2 |
account |
string |
Name of Account for which the Order is to be
executed. |
|
|
3 |
fagroup |
string |
Please refer to the Interactive Brokers© User
Guide. |
|
|
4 |
faprofile |
string |
Please refer to the Interactive Brokers© User
Guide. |
|
|
5 |
famethod |
string |
Please refer to the Interactive Brokers© User
Guide. |
|
|
6 |
fapercentage |
string |
Please refer to the Interactive Brokers© User
Guide. |
|
|
7 |
transmittoTWS |
int |
Transmit the Order to TWS. Note: this is not the Transmit to IB Flag. Call TRANSMIT afterwards for that Purpose. |
|
Comments:
Sample: Specify
the Order with UID=12 to be placed for Account Group Huns to increase each
Position by 50 %. Finally transmit to TWS.
bret = SET_FA_MEMBERS (12,,Huns,,PctChange,50,0)
Specify the Order with UID=12 to be placed for Account
DF1648 only. Finally transmit to IB.
bret = SET_FA_MEMBERS (12,DF1648,,,,,1)
5.3.12 Function WAIT_FOR_FILLED back
Description: Wait for Order Status Filled.
Return Type: int
Return Value Table
|
Value |
Meaning |
|
1 |
Order Filled completely. |
|
0 |
Pending or Timeout. |
|
-1 |
Order cant be filled because not yet transmitted to
TWS or IB. |
|
-2 |
Order cant be filled because erroneous. |
Parameter Table
|
# |
Name |
Type |
Meaning |
Poss. Values |
|
1 |
Orderuid |
int |
Unique Order Id returned by a prior Call of PLACE_ORDER. |
> 0 |
|
2 |
Timeout |
int |
Timeout in Milliseconds the Functions returns if the Filled Status was
not reached within Timeout |
>= 0 |
Sample: Wait
for Status Filled for the newly placed LIMIT Order. Wait at the most of 3
Seconds.
ostatus = WAIT_FOR_FILLED( LMTOrderID,3000)
if ostatus <= -1 then
begin
--- do something to get out
of trouble
end // place Order probably failed
else if ostatus = 0 begin
--- wait or do something
other
end
else begin
all good
end
5.3.13 Function BUY_LMT back
Description: Place/Modify Buy Limit Order.
Return Type: int
R Return Value Table
|
Value |
Meaning |
|
> 0 |
OK: The Unique ID of Order. |
|
<= 0 |
Order Place failed for any Reason. (Table
6.8) |
Parameter Table
|
# |
Name |
Type |
Meaning |
Poss. Values |
|
1 |
contractuid |
int |
Unique Contract Id returned by a prior Call of REGISTER_CONTRACT. |
> 0 |
|
2 |
orderuid |
int |
Order UID. If > 0, the Order to which the id refers gets modified. |
>= 0 |
|
3 |
limitprice |
double |
The Limit Price. This is called Matching Limit. You can define the
number of Pips Price should be placed above Ask, for instance, Price = -2,
places a Lmt Order 2 Pips above current Ask in the Event that current Ask in
known in the System → REQ_MARKET_DATA. |
<>= 0.0 |
|
4 |
ordersize |
int |
The Order Size. |
>= 0 |
|
5 |
tif |
string |
Time in Force |
e.g. GTC, DAY
|
|
6 |
Transmission flag |
int |
Transmission Flag. If -1, the
property gets changed internally only. If 0, the
property gets changed and order transmitted to TWS again (can be seen at TWS
with the blue T
or red T). If 1, the property gets changed and
the order transmitted to IB. |
Transmission flag |
Sample: Place
a new Buy Limit Order for 100 Microsoft Shares at 29.50. The MSFT contract has
the id=4.
uid =BUY_LMT(4,0,29.50,100,DAY,1)
Place a new Buy Limit Order for 100 Microsoft Shares
one 1 Pip above current Ask. The MSFT contract has the id=4.
uid =BUY_LMT(4,0,-1,100,DAY,1)
5.3.14 Function SELL_LMT back
Description: Place/Modify Sell Limit Order.
Return Type: int
R Return Value Table
|
Value |
Meaning |
|
> 0 |
OK: The Unique ID of Order. |
|
<= 0 |
Order Place failed for any Reason. (Table
6.8) |
Parameter Table
|
# |
Name |
Type |
Meaning |
Poss. Values |
|
1 |
contractuid |
int |
Unique Contract Id returned by a prior Call of REGISTER_CONTRACT. |
> 0 |
|
2 |
orderuid |
int |
Order UID. If > 0, the Order to which the id refers gets modified. |
>= 0 |
|
3 |
limitprice |
double |
The Limit Price. If Price <= 0 and Market Data
for underyling Contract are requested, the current Bid is taken as Lmt Price. This is called Matching Limit. You can define the
number of Pips Price should be placed below Bid, for instance, Price = -2,
places a Lmt Order 2 Pips below current Bid in the Event that current Ask in
known in the System → REQ_MARKET_DATA |
<>= 0.0 |
|
4 |
ordersize |
int |
The Order Size. |
>= 0 |
|
5 |
tif |
string |
Time in Force |
e.g. GTC, DAY
|
|
6 |
Transmission flag |
int |
Transmission Flag. If -1, the
property gets changed internally only. If 0, the
property gets changed and order transmitted to TWS again (can be seen at TWS
with the blue T
or red T). If 1, the property gets changed and
the order transmitted to IB. |
Transmission flag |
Sample: Place
a new Sell Limit Order for 100 Microsoft Shares at 39.50. The MSFT contract has
the id=4.
uid =SELL_LMT(4,0,39.50,100,DAY,1)
Place a new Sell Limit Order for 100 Microsoft Shares
1 Pip below current Bid. The MSFT contract has the id=4.
uid =SELL_LMT(4,0,-1,100,DAY,1)
5.3.15 Function BUY_STPLMT back
Description: Place/Modify Buy Stop Stop Limit Order.
Return Type: int
Return Value Table
|
Value |
Meaning |
|
> 0 |
OK: The Unique ID of Order. |
|
<= 0 |
Order Place failed for any Reason. (Table
6.8) |
Parameter Table
|
# |
Name |
Type |
Meaning |
Poss. Values |
|
1 |
contractuid |
int |
Unique Contract Id returned by a prior Call of REGISTER_CONTRACT. |
> 0 |
|
2 |
orderuid |
int |
Order UID. If > 0, the Order to which the id refers gets modified. |
>= 0 |
|
3 |
limitprice |
double |
The Limit Price. |
>= 0.0 |
|
4 |
stopprice |
double |
The Stop Price. |
>= 0.0 |
|
5 |
ordersize |
int |
The Order Size. |
>= 0 |
|
6 |
tif |
string |
Time in Force |
e.g. GTC, DAY
|
|
7 |
Transmission flag |
int |
Transmission Flag. If -1, the
property gets changed internally only. If 0, the
property gets changed and order transmitted to TWS again (can be seen at TWS
with the blue T
or red T). If 1, the property gets changed and
the order transmitted to IB. |
Transmission flag |
Sample: Place
a new Buy Limit Order for 100 Microsoft Shares at 29.50, 32.50. The MSFT
contract has the id=4.
uid =BUY_STPLMT(4,0,29.50, 32.50,100,DAY,1)
5.3.16 Function SELL_STPLMT back
Description: Place/Modify Sell Stop Limit Order.
Return Type: int
R Return Value Table
|
Value |
Meaning |
|
> 0 |
OK: The Unique ID of Order. |
|
<= 0 |
Order Place failed for any Reason. (Table
6.8) |
Parameter Table
|
# |
Name |
Type |
Meaning |
Poss. Values |
|
1 |
contractuid |
int |
Unique Contract Id returned by a prior Call of REGISTER_CONTRACT. |
> 0 |
|
2 |
orderuid |
int |
Order UID. If > 0, the Order to which the id refers gets modified. |
>= 0 |
|
3 |
limitprice |
double |
The Limit Price. |
>= 0.0 |
|
4 |
stopprice |
double |
The Stop Price. |
>= 0.0 |
|
5 |
ordersize |
int |
The Order Size. |
>= 0 |
|
6 |
tif |
string |
Time in Force |
e.g. GTC, DAY
|
|
7 |
Transmission flag |
int |
Transmission Flag. If -1, the
property gets changed internally only. If 0, the
property gets changed and order transmitted to TWS again (can be seen at TWS
with the blue T
or red T). If 1, the property gets changed and
the order transmitted to IB. |
Transmission flag |
Sample: Place
a new Sell Stop Limit Order for 100 Microsoft Shares at 39.50, 29.50. The MSFT
contract has the id=4.
uid =SELL_STPLMT(4,0,39.50,29.50,100,DAY,1)
5.3.17 Function BUY_MKT back
Description: Place Buy Market Order.
Return Type: int
R Return Value Table
|
Value |
Meaning |
|
> 0 |
OK: The Unique ID of Order. |
|
<= 0 |
Order Place failed for any Reason. (Table
6.8) |
Parameter Table
|
# |
Name |
Type |
Meaning |
Poss. Values |
|
1 |
contractuid |
int |
Unique Contract Id returned by a prior Call of REGISTER_CONTRACT. |
> 0 |
|
2 |
ordersize |
int |
The Order Size. |
>= 0 |
|
3 |
Transmission flag |
int |
Transmission Flag. If -1, the
property gets changed internally only. If 0, the
property gets changed and order transmitted to TWS again (can be seen at TWS
with the blue T
or red T). If 1, the property gets changed and
the order transmitted to IB. |
Transmission flag |
Comments:
Sample: Place
a new Buy Market Order for 100 Microsoft Shares. The MSFT contract has the
id=4.
uid =BUY_MKT(4,100,1)
5.3.18 Function SELL_MKT back
Description: Place Sell Market Order.
Return Type: int
R Return Value Table
|
Value |
Meaning |
|
> 0 |
OK: The Unique ID of Order. |
|
<= 0 |
Order Place failed for any Reason. (Table
6.8) |
Parameter Table
|
# |
Name |
Type |
Meaning |
Poss. Values |
|
1 |
contractuid |
int |
Unique Contract Id returned by a prior Call of REGISTER_CONTRACT. |
> 0 |
|
2 |
ordersize |
int |
The Order Size. |
>= 0 |
|
3 |
Transmission flag |
int |
Transmission Flag. If -1, the
property gets changed internally only. If 0, the
property gets changed and order transmitted to TWS again (can be seen at TWS
with the blue T
or red T). If 1, the property gets changed and
the order transmitted to IB. |
Transmission flag |
Comments:
Sample: Place
a new Sell Market Order for 100 Microsoft Shares. The MSFT contract has the
id=4.
uid =SELL_MKT(4,100,1)
5.3.19 Function TOGGLE_ORDER back
Description: Modify exisiting Order regarding
Price/Size. The Price Parameter is interpreted as Pip Offset relative to
current Price.
Return Type: int
Return Value Table
|
Value |
Meaning |
|
> 0 |
OK: The Unique ID of Order. |
|
<= 0 |
Order Place failed for any Reason. (Table
6.8) |
Parameter Table
|
# |
Name |
Type |
Meaning |
Poss. Values |
|
1 |
contractuid |
int |
Unique Contract Id returned by a prior Call of REGISTER_CONTRACT
or 0. |
>= 0 |
|
2 |
orderuid |
int |
Order UID of that Order to be changed. If > 0 a specific Order gets changed. If = 0, all orders of specified Contract get changed. If = 0 and #1 = 0, all Orders get changed. |
>= 0 |
|
3 |
limitpips |
int |
Number of Pips counted on current Limit Price. |
<> 0 |
|
4 |
stoppips |
int |
Number of Pips counted on current Stop Price. |
<> 0 |
|
5 |
ordersize |
int |
The Order Size. |
>= 0 |
|
6 |
Transmission flag |
int |
Transmission Flag. If -1, the
property gets changed internally only. If 0, the
property gets changed and order transmitted to TWS again (can be seen at TWS
with the blue T
or red T). If 1, the property gets changed and
the order transmitted to IB. |
Transmission flag |
Sample: Lower
Stop Price of Order with uid=7 by 5 Pips. Contractid = 4. Let Size unchanged
and transmit to IB.
uid =TOGGLE_ORDER(4,7,0,-5,0,1)
Raise Limit Price of all Orders for Contract with UID
= 4 by 6 Pips. Let Size unchanged and transmit to IB.
uid =TOGGLE_ORDER(4,0,6,0,0,1)
5.3.20 Function BUY_STP back
Description: Place/Modify Buy Stop Order.
Return Type: int
Return Value Table
|
Value |
Meaning |
|
> 0 |
OK: The Unique ID of Order. |
|
<= 0 |
Order Place failed for any Reason. (Table
6.8) |
Parameter Table
|
# |
Name |
Type |
Meaning |
Poss. Values |
|
1 |
contractuid |
int |
Unique Contract Id returned by a prior Call of REGISTER_CONTRACT. |
> 0 |
|
2 |
orderuid |
int |
Order UID. If > 0, the Order to which the id refers gets modified. |
>= 0 |
|
3 |
stopprice |
double |
The Stop Price. |
>= 0.0 |
|
4 |
ordersize |
int |
The Order Size. |
>= 0 |
|
5 |
tif |
string |
Time in Force |
e.g. GTC, DAY
|
|
6 |
Transmission flag |
int |
Transmission Flag. If -1, the
property gets changed internally only. If 0, the
property gets changed and order transmitted to TWS again (can be seen at TWS
with the blue T
or red T). If 1, the property gets changed and
the order transmitted to IB. |
Transmission flag |
Sample: Place
a new Buy Stop Order for 100 Microsoft Shares at 32.50. The MSFT contract has
the id=4.
uid =BUY_STP(4,0,32.50,100,DAY,1)
5.3.21 Function SELL_STP back
Description: Place/Modify SELL Stop Order.
Return Type: int
Return Value Table
|
Value |
Meaning |
|
> 0 |
OK: The Unique ID of Order. |
|
<= 0 |
Order Place failed for any Reason. (Table
6.8) |
Parameter Table
|
# |
Name |
Type |
Meaning |
Poss. Values |
|
1 |
contractuid |
int |
Unique Contract Id returned by a prior Call of REGISTER_CONTRACT. |
> 0 |
|
2 |
orderuid |
int |
Order UID. If > 0, the Order to which the id refers gets modified. |
>= 0 |
|
3 |
stopprice |
double |
The Stop Price. |
>= 0.0 |
|
4 |
ordersize |
int |
The Order Size. |
>= 0 |
|
5 |
tif |
string |
Time in Force |
e.g. GTC, DAY
|
|
6 |
Transmission flag |
int |
Transmission Flag. If -1, the
property gets changed internally only. If 0, the
property gets changed and order transmitted to TWS again (can be seen at TWS
with the blue T
or red T). If 1, the property gets changed and
the order transmitted to IB. |
Transmission flag |
Sample: Place
a new Sell Stop Order for 100 Microsoft Shares at 22.50. The MSFT contract has
the id=4.
uid =BUY_STP(4,0,22.50,100,DAY,1)
5.3.22 Function BUY_TRAIL back
Description: Place/Modify BUY Trail Order.
Return Type: int
Return Value Table
|
Value |
Meaning |
|
> 0 |
OK: The Unique ID of Order. |
|
<= 0 |
Order Place failed for any Reason. (Table
6.8) |
Parameter Table
|
# |
Name |
Type |
Meaning |
Poss. Values |
|
1 |
contractuid |
int |
Unique Contract Id returned by a prior Call of REGISTER_CONTRACT. |
> 0 |
|
2 |
orderuid |
int |
Order UID. If > 0, the Order to which the id refers gets modified. |
>= 0 |
|
3 |
abstrailamount |
double |
The absolute Trailamount (not PIPS). |
>= 0.0 |
|
4 |
ordersize |
int |
The Order Size. |
>= 0 |
|
5 |
tif |
string |
Time in Force |
e.g. GTC, DAY
|
|
6 |
Transmission flag |
int |
Transmission Flag. If -1, the
property gets changed internally only. If 0, the
property gets changed and order transmitted to TWS again (can be seen at TWS
with the blue T
or red T). If 1, the property gets changed and
the order transmitted to IB. |
Transmission flag |
Sample: Place
a new Buy Trail Order for 100 Microsoft Shares with Trailamount = 0.01. The
MSFT contract has the id=4.
uid =BUY_TRAIL(4,0,0.1,100,DAY,1)
5.3.23 Function SELL_TRAIL back
Description: Place/Modify SELL Trail Order.
Return Type: int
Return Value Table
|
Value |
Meaning |
|
> 0 |
OK: The Unique ID of Order. |
|
<= 0 |
Order Place failed for any Reason. (Table
6.8) |
Parameter Table
|
# |
Name |
Type |
Meaning |
Poss. Values |
|
1 |
contractuid |
int |
Unique Contract Id returned by a prior Call of REGISTER_CONTRACT. |
> 0 |
|
2 |
orderuid |
int |
Order UID. If > 0, the Order to which the id refers gets modified. |
>= 0 |
|
3 |
abstrailamount |
double |
The absolute Trailamount (not PIPS). |
>= 0.0 |
|
4 |
ordersize |
int |
The Order Size. |
>= 0 |
|
5 |
tif |
string |
Time in Force |
e.g. GTC, DAY
|
|
6 |
Transmission flag |
int |
Transmission Flag. If -1, the
property gets changed internally only. If 0, the
property gets changed and order transmitted to TWS again (can be seen at TWS
with the blue T
or red T). If 1, the property gets changed and
the order transmitted to IB. |
Transmission flag |
Sample: Place
a new Sell Trail Order for 100 Microsoft Shares with Trailamount = 0.01. The
MSFT contract has the id=4.
uid =SELL_TRAIL(4,0,0.1,100,DAY,1)
5.3.24 Function CONVERT_ID back
Description: Convert a given Order related ID to another
Order related ID.
Return Type: int
Return Value Table
|
Value |
Meaning |
|
>= 0 |
Converted ID. |
|
< 0 |
Function Call stopped,ID not convertable,source not
found. |
Parameter Table
|
# |
Name |
Type |
Meaning |
Poss. Values |
|
1 |
sourceid |
int |
Order related ID. |
Order UID (DLL administrated), |
|
2 |
conversiontype |
int |
Kind of Conversion. |
Sample: Get
the
permid =CONVERT_ID(5,4)
5.3.25 Function CONVERT_ID_STRING back
Description: Convert a given Order related ID-String to
another Order related ID-String.
Return Type: int
Return Value Table
|
Value |
Meaning |
|
Target_id_string |
String of Converted IDs in the same order as passed
Source IDs. |
|
nok |
Function Call stopped,ID not convertable,source not
found. |
Parameter Table
|
# |
Name |
Type |
Meaning |
Poss. Values |
|
1 |
sourcestring |
string |
Comma separated string of Source IDs. |
Order UIDs (DLL administrated), Perm IDs (IB administrated) |
|
2 |
conversiontype |
int |
Kind of Conversion. |
Sample: Get
the Perm ID-String for Orders with UIDs= 0,8,1 and 5 (DLL administrated, that
id you pass e.g. for any Order Place Functions).
permidstring =CONVERT_ID(0,8,1,5,4)
5.3.26 Function GET_ORDER_VAL back
Description: Get an Order Property.
Return Type: string
Return Value Table
|
Value |
Meaning |
|
String value |
Property as String. |
|
nok |
Function Call stopped. |
|
onf |
Order not found. |
|
vnf |
Value of ID unknown. |
|
nim |
Value of passed ID not yet implemented. |
Parameter Table
|
# |
Name |
Type |
Meaning |
Poss. Values |
|
1 |
uidorder |
int |
Unique Order Id returned by a prior Call of PLACE_ORDER. |
> 0 |
|
2 |
propertyid |
int |
Order Property Identifier. |
|
|
3 |
extraparam |
string |
Extra Parameter. This Parameter is need for some
Properties. |
|
Sample: Get the (latest, could be filled partially before)
Execution Price for prior placed Market Order with UID=6.
ExecPriceAsString = GET_ORDERVAL(6,71)
5.3.27 Function GET_EXECUTION_PRICE back
Description: Get Last Fill Price or Average Price for
Order.
Return Type: double
Return Value Table
|
Value |
Meaning |
|
> 0 |
Execution Price, Average Fill or Fill Size. |
|
0.0 |
Price not yet available (Order not yet been filled.) |
|
-1.0 |
Order not found. |
|
-2.0 |
Function Call stopped. |
Parameter Table
|
# |
Name |
Type |
Meaning |
Poss. Values |
|
1 |
uidorder |
int |
Unique Order Id returned by a prior Call of PLACE_ORDER. |
> 0 |
|
2 |
type |
int |
Type of Price or Size. |
0: Last Fill. |
|
3 |
index |
int |
Index of Value. Sometimes an Order get filled in more than one Step.
The Index allows to retrieve Information about all partial Fills. |
>= 0 |
Sample: Get the latest average Execution Price for prior placed
Market Order with UID=6.
ExecPriceAsString = GET_EXECUTION_PRICE(6,1,0)
Retrieve the Number of fills for Order with UID=6
Fills = GET_EXECUTION_PRICE(6,3,0)
5.3.28 Function GET_ORDERUID_LIST back
Description: Get a comma separated List of uids of
Orders matching to passed Parameters.
Return Type: string
Return Value Table
|
Value |
Meaning |
|
Any String |
Comma separated List of Orderuids. |
|
nok |
Function Call stopped. |
Parameter Table
|
# |
Name |
Type |
Meaning |
Poss. Values |
|
1 |
contract |
int |
Unique ID of Contract Order belongs to. 0 for
discard Contract. |
>= 0 |
|
2 |
action |
string |
Action BUY/SELL. Empty for discard Action. |
BUY,SELL, |
|
3 |
type |
string |
Type of Order. Empty for discard Type. |
|
|
4 |
status |
int |
Status ID of Order. < 0 for discard Order Status. |
-1 - Table 6.7 |
|
5 |
isdead |
int |
Is Dead Flag for Order. < 0 to discard Is Dead
Flag. =1, order is dead -> filled, cancelled, invalid) |
< = > 0 |
|
6 |
lowerprice |
double |
Price lmt.-/aux. of Order must be equal or greater.
<= 0 to discard lower Price. |
<>= 0.0 |
|
7 |
upperprice |
double |
Price lmt.-/aux. of Order must be equal or less.
<= 0 to discard upper Price. |
<>= 0.0 |
|
8 |
exchange |
string |
Filter for exchange. |
|
|
9 |
orderref |
double |
Filter for order reference |
|
Sample: Get
list of UIDs of Buy-Orders that are submitted and belong to Contract with
UID=12 and which have a price equal or above 45.67.
orderuidlist = GET_ORDERUID_LIST(12,BUY,,8,-1,45.67,0.0,,)
5.3.29 Function TOGGLE_ORDER_PCT back
Description: Modify exisiting Order regarding
Price/Size. The Price Parameter is interpreted as relative Factor to current
Price.
Return Type: int
Return Value Table
|
Value |
Meaning |
|
> 0 |
OK: The Unique ID of Order. |
|
<= 0 |
Order Place failed for any Reason. (Table
6.8) |
Parameter Table
|
# |
Name |
Type |
Meaning |
Poss. Values |
|
1 |
contractuid |
int |
Unique Contract Id returned by a prior Call of REGISTER_CONTRACT
or 0. |
>= 0 |
|
2 |
orderuid |
int |
Order UID of that Order to be changed. If > 0 a specific Order gets changed. If = 0, all orders of specified Contract get changed. If = 0 and #1 = 0, all Orders get changed. |
>= 0 |
|
3 |
limitpct |
double |
Percentage of Change for Limit Price. |
> 0.0 |
|
4 |
stoppct |
double |
Percentage of Change for Stop Price. |
> 0.0 |
|
5 |
ordersize |
int |
The Order Size. |
>= 0 |
|
6 |
Transmission flag |
int |
Transmission Flag. If -1, the
property gets changed internally only. If 0, the
property gets changed and order transmitted to TWS again (can be seen at TWS
with the blue T
or red T). If 1, the property gets changed and
the order transmitted to IB. |
Transmission flag |
Comments:
Sample: Lower
Stop Price of Order with uid=7 by 0.02 %. Contractid = 4. Let Size unchanged
and transmit to IB.
uid =TOGGLE_ORDER(4,7,0.0,0.02,0,1)
5.3.30 Function WAIT_FOR_SUBMITTED back
Description: Wait for Order Status PreSubmitted, PendingSubmit or Submitted
Return Type: int
Return Value Table
|
Value |
Meaning |
|
1 |
Order Has Submitted Status. |
|
0 |
Pending or Timeout. |
|
-1 |
Order cant have Submitted Status due to not yet transmitted to TWS or IB. |
|
-2 |
Order cant have Submitted Status due to filled,
cancelled or erroneous. |
Parameter Table
|
# |
Name |
Type |
Meaning |
Poss. Values |
|
1 |
Orderuid |
int |
Unique Order Id returned by a prior Call of PLACE_ORDER. |
> 0 |
|
2 |
Timeout |
int |
Timeout in Milliseconds the Functions returns if the Filled Status was
not reached within Timeout |
>= 0 |
|
3 |
final |
int |
If > 0, accept Status = Submitted
only. |
>= 0 |
Sample: Wait
for Status Submitted for the newly placed LIMIT Order. Wait at the most of 3
Seconds.
ostatus = WAIT_FOR_SUBMITTED( LMTOrderID,3000,1)
if ostatus == 1 then begin
--- my Order has been
submitted
end
Wait for any of
the Submitted States for the newly placed LIMIT Order. Wait at the
most of 3 Seconds.
ostatus = WAIT_FOR_SUBMITTED( LMTOrderID,3000,0)
if ostatus == 1 then begin
--- my Order has Submitted,
PendingSub or PreSubmitted Status
end
5.3.31 Function GET_OPEN_ORDERUID_LIST back
Description: Get a comma separated List of uids of open
Orders.
Return Type: string
Return Value Table
|
Value |
Meaning |
|
Any String |
Comma separated List of Orderuids. |
|
nok |
Function Call stopped. |
Parameter Table
|
# |
Name |
Type |
Meaning |
Poss. Values |
|
1 |
contractuid |
int |
Unique ID of Contract Order belongs to. 0 for
discard Contract. |
>= 0 |
|
2 |
action |
string |
Action BUY/SELL. Empty for discard Action. |
BUY,SELL, |
|
3 |
type |
string |
Type of Order. Empty for discard Type. |
|
|
4 |
lowerprice |
double |
Price lmt.-/aux. of Order must be equal or greater.
<= 0 to discard lower Price. |
<>= 0.0 |
|
5 |
upperprice |
double |
Price lmt.-/aux. of Order must be equal or less.
<= 0 to discard upper Price. |
<>= 0.0 |
|
6 |
exchange |
string |
Exchange where order has been placed. Let empty to
be ignored. |
|
|
7 |
orderref |
string |
Orderreference. Let empty to be ignored. |
|
Sample: Get
list of UIDs of open Buy-Orders that belong to Contract with UID=12 and which
have a price equal or above 45.67.
orderuidlist = GET_OPEN_ORDERUID_LIST(12,BUY,, 45.67,0.0,,)
5.4 Account Related Functions
5.4.1 Function GET_ACC_VAL back
Description: Get a specific Account Value.
Return Type: string (Constant
String)
Return Value Table
|
Value |
Meaning |
|
Any String |
The Account Value of Interest as String. |
|
nok |
Function Call failed. Could be either #1 unknown or
Function Call disabled or internal Error. |
Parameter Table
|
# |
Name |
Type |
Meaning |
Poss. Values |
|
1 |
idaccval |
int |
Identifier of Account Value. |
|
|
2 |
currency |
string |
Most of the Account Values are related to a
Currency. If you want an Account Value related to Base
Currency, Pass # or Base Currency for #2. Account Values
that dont need a Currency are labeled with no in Table 6.9. |
- # for Base Currency - Specific Currency. |
|
3 |
accountlist |
string |
Comma separated string of accounts respected. Let empty for non
advisor accounts or if you want to be all Accounts to be respected for
advisor accounts. For advisor accounts the sum over all in #3 contained account values
is returned. This function unfortunately works
not reliable for FA account due to API
internal restrictions. |
, empty or acc1,acc2,
,accn |
|
4 |
valuetype |
int |
Type of Value returned. Convention: The Relative Change from 100 to 120 is
20 % and not 120 %. |
0 : Direct Value. 1 : Absolute Change. 2: Relative Change. 3: Initial Value. |
Comments:
Sample: Get the total Net Liquidation.
ret = GET_ACC_VAL (12,,,0)
Get the absolute Change of total Net Liquidation since
Runtime.
ret = GET_ACC_VAL (12,,,1)
Get total Cash Balance in MXN.
ret = GET_ACC_VAL (8,MXN,,0)
Get Initial Leverage for Securities.
ret = GET_ACC_VAL (66,,,3)
5.4.2 Function GET_BASECURRENCY back
Description: Get the Base Currency of Account.
Return Type: string (Constant String)
Return Value Table
|
Value |
|
Base Currency as String |
|
Empty String.
No Account Values available. This can happen if no Request for Account
Updates has been done or Account Values are not yet available. |
|
nok. Function Call failed due to Function Call
disabled. |
Parameter Table
|
# |
Name |
Type |
Meaning |
Poss. Values |
|
1 |
accountname |
string |
Name of Accoun. Let empty for non advisor accounts
or if you want to be all Accounts to be respected for advisor accounts. |
, empty or acc1,acc2,
,accn |
Comments:
Sample: Get the Base Currency.
ret = GET_BASECURRENCY ()
5.4.3 Function GET_ACC_NAME back
Description: Get the Account Name.
Return Type: string (Constant String)
Return Value Table
|
Value |
|
Account as String |
|
Empty String.
No Account Values available. This can happen if no Request for Account
Updates has been done or Account Values are not yet available. |
|
nok. Function Call failed due to Function Call
disabled. |
Parameter Table
|
# |
Name |
Type |
Meaning |
|
1 |
idaccount |
int |
Index of Account. Pass >= 0 to get Zero based Subaccount of FA
Account. Pass < 0 to get a comma separated List of
Subaccounts. |
Sample: Get the Account Name for a normal Account or the 1.
Subaccount in Case of an FA Account.
ret = GET_ACC_NAME(0)
Get the Name of the 2. Subaccount of a FA Account.
ret = GET_ACC_NAME(1)