The
Deltastock Application Program Interface (API) ensures access to some of the
most important applications of the trading platform Delta Trading. It can be
used to connect the trading platform to automated trading systems
. There are several requirements that you must meet before the API
starts working. First, the software needs to be compatible with ActiveX
component DSAPI_Client.exe and instancing of the DSAPI_Client.clientAPI.
DSAPI_Client.exe is available in Delta Trading
version 4.0.7
and higher.
There are
three basic types to enter the data:
Long – 32-bit (4-byte) integers, positive or negative;
Double – IEEE 64-bit (8-byte) numbers with floating decimal point;
String – Unicode character set, 2 bytes per character;
The Date type (8-byte)
has to be converted 1:1 to
Double type (8-byte). The DeltaStock server's datetime
format is "dd.mm.yyyy hh:mm:ss"
The
other requirement is the Delta Trading platform has to be started. Client need
to report to Deltastock Inc. that he wants to use the interface DSAPI_Client.
DSAPI_Client
has all the following functions:
1. CancelOrder –
Cancels an order.
2. CancelOrder_Async –
Cancels an order using a filter.
3. ClosePosition
– Closes a position at market
price.
4. GetAccSum – Returns the available money
from the account.
5. GetChartData – Exports data from
charts for a given financial instrument.
6. GetErrDescription – Returns
a description of the error.
7. GetFreeMargin – Returns the free money (not
used for margin) from the account.
8. GetOrdList_Async – Displays list of
orders using a filter.
9. GetOrdStatus –
Displays order status.
10. GetPosition – Displays size and average price of a
position.
11. GetPositionRes – Displays the current result of a
position.
12. GetPositionsRes – Displays the current result of all open
positions.
13. GetQuote – Displays current market
quotes (Bid, Ask, Hi, Low)
14. GetTotalResult – Displays the total result
of trading.
15. GetUsedMargin – Returns the money, locked in margins for
the current open positions.
16. NewOrder – Enters a new order.
17. NewOrder_Async – Enters a new order
using a filter.
Input financial
instruments in DSAPI_Client API using their tickers.
Currencies (as of 14-JUN-2007):
|
AUD/CAD |
AUD/CHF |
AUD/JPY |
AUD/NZD |
AUD/USD |
|
CAD/CHF |
CAD/JPY |
CHF/BGN |
CHF/JPY |
EUR/AUD |
|
EUR/CAD |
EUR/CHF |
EUR/GBP |
EUR/JPY |
EUR/NOK |
|
EUR/NZD |
EUR/RON |
EUR/SEK |
EUR/USD |
EUR/ZAR |
|
GBP/AUD |
GBP/BGN |
GBP/CAD |
GBP/CHF |
GBP/JPY |
|
GBP/NOK |
GBP/NZD |
GBP/USD |
GBP/ZAR |
NZD/CAD |
|
NZD/CHF |
NZD/JPY |
NZD/USD |
USD/BGN |
USD/CAD |
|
USD/CHF |
USD/DKK |
USD/JPY |
USD/NOK |
USD/RON |
|
USD/RUB |
USD/SEK |
USD/TRY |
USD/ZAR |
|
Stocks, indexes, gold, and oil can be accessed
from the menu of the platform Delta Trading (Trading -> Instruments).
Instruments that you want to use in DSAPI_Client API must be loaded in advance
in the platform Delta Trading.
To refer to different Currencies (input: InCurrency) use their
standard tickers:
|
AUD |
BGN |
CAD |
CHF |
EUR |
|
GBP |
JPY |
NOK |
NZD |
RON |
|
RUB |
SEK |
ZAR |
USD |
|
Description of DSAPI_Client functions
1. CancelOrder(OrdID As Long) As
Long
Cancels
an order.
Inputs: OrdID – (# of the order
you want to cancel)
If the displayed result equals OrdID, then
the order has been cancelled.
If the displayed
result is less than zero - an
error occurred and the displayed result indicates the error’s number. (see Error Table)
Example:
CancelOrder (12345678) à 12345678 (order is
cancelled)
CancelOrder (12345678) à
(-8) ðError: Market is closed
________________________________________________________________________________
2. CancelOrder_ASync(OrdID As Long, RequestID As Long, errNumber As Long)
Places an order for Cancellation. You need to enter two
different inputs because the filter is not synchronized
(asynchronized processing). It displays two results – RequestID and errNumber, that is why these two must be set as variables.
RequestID – an Identification Number (ID)
which is unique for the order in DSAPI_Client.clientAPI. This ID allows you to
follow your order status.
errNumber
– the number of the error that took place
Inputs:
OrdID –
the IN of the order that you want to cancel
RequestID
– unique number of the order in DSAPI_Client.clientAPI
errNumber
– variable, which returns a description if an error occurrs (see Error Table)
Result:
RequestID - unique number of the order in DSAPI_Client.clientAPI
errNumber
- returns error number (see Error Table)
Example:
CancelOrder_ASync (12345678, RequestID1, errNumber1)
RequestID1
à 453628
errNumber1
à 0
Getting a result from the order is executed by
the command:
CancelOrderExecuted(RequestID As Long,
OrdID As Long)
Instance_CancelOrderExecuted(RequestID As Long, OrdID As
Long)
à The order is cancelled by the command RequestID order number OrdID.
_______________________________________________________________________________
3. ClosePosition(Instrument As String) As Long
Closes position of the
Instrument.
Input:
Instrument
= currency cross code (Example: “EUR/USD”)
Output:
1 –
position is closed;
0 – no
result;
if
negative number (-1, -2, -3 etc.) – explaining the number of the error (see Error Table).
Example:
ClosePosition(“EUR/USD”) à 1 (position is closed)
_______________________________________________________________________________
4. GetAccSum (InCurrency As String, errNumber As Long) as Double
Returns the current
balance in the account of the specified currency, or it
returns 0 if an error exists.
The error number is
displayed by the command errNumber. It must be a variable defined in advance
which is valued by the reference to the function GetAccSum.
Inputs:
InCurrency
- currency code (Example: InCurrency = „EUR”).
errNumber
– variable, which displays the number of the error (see Error Table)
Example:
GetAccSum
(“USD”, errNumber1) à 2345.33 (in USD)
errNumber1 à 0; therefore there is
no error
________________________________________________________________________________
5. GetChartData(Instrument As String,
iTypeInter As String, fname As String, DateFrom As Double, DateTo As Double,
errNumber As Long) As Long
Displays 0/1 –
false/true exporting chart data to another file.
Inputs:
Instrument – instrument code
iTypeInter
– time period:
|
“1”
– 1 min. |
“5”
– 5 min |
“30”
– 30 min. |
“60”
– 1 hour |
“4”
– 4 hours |
|
“24”
– 1 day |
“7”
– 1 week |
“33”
– 1 month |
|
|
Fname – file name – example: C:\chart\eurusd5.txt (file path needs to be created in advance!)
DateFrom
– Date (Not Datetime) marks the start of export period
(converted in Double);
DateTo – Date (Not Datetime) marks the end of the export period (converted in Double)
errNumber – variable
which displays the number of the error (see Error Table)
Example: GetChartData(“EUR/USD”, ”24”, ”C:\chart\eurusd5.txt”, 234242.2246, 353535.666, errNumber1) à 1
errNumber1à 0; therefore no error
exists
The Result
has been saved into a file with the following (.csv-
comma delimited) pattern:
<date>,
<open>, <hi>, <low>, <close>, <volume> crlf
_______________________________________________________________________________
6. GetErrDescription (ErrorNumber As Long) As String
Displays error
description after an error number is entered.
|
Digit |
Description |
|
-1 |
The
instrument code not found in DeltaTrading platform. |
|
-2 |
Order's
quantity must be positive number and divisible by 1000. |
|
-3 |
ordPriceReq1/ordPriceReq2
< 1 or not a double format number. |
|
-4 |
Unknown
ordType 1-market;2-limit;3-stop;4-OCO. |
|
-5 |
Unknown
ordBuySell 'B' - Buy / 'S' - Sell. Unknown ordBuySell 'B' - Buy / 'S' -
Sell." |
|
-6 |
Unknown
ordValidity 1- day / 2- good till cancelled. |
|
-7 |
Not
available funds for the order's execution. |
|
-8 |
Market is
closed. |
|
-9 |
Forex
trading not authorized. |
|
-10 |
CFD trading
not authorized. |
|
-11 |
Precious
Metal trading not authorized. |
|
-12 |
Commodity
trading not authorized. |
|
-13 |
DSAPI_Client
Object not set. |
|
-14 |
Unexpected
Error: DSAPI_Client.ClientAPI/NewOrder. |
|
-15 |
Unexpected
Error: DSAPI_Client.ClientAPI/myApp1Events.RiseClientEvent. |
|
-16 |
ReqID_NWE
< 1 No Request ID. |
|
-17 |
ordID_NOE
< 1 No order ID. |
|
-18 |
ordStatus_NOE
<> 1, 2, 3, 4, 5. Order Status not Specified. |
|
-19 |
DSAPI_Client.internalAPI
Object not set |
|
-20 |
Unexpected
Error: DSAPI_Client.internalAPI/NewOrderExecuted. |
|
-21 |
Unexpected
Error: DSAPI_Client.internalAPI/myApp2Events.RiseClientEvent. |
|
-22 |
Operation's
execution declined! DT-Client busy with another operation. |
|
-23 |
Operation's
execution declined by DT-Client! This Logical Order cannot close the
position. |
|
-24 |
Operation's
execution declined by DT-Client! The requested price is not a valid market
price. |
|
-25 |
DT-Client
has placed the order for execution, but the order status not returned from
the server. |
|
-26 |
OCO order;
The first price must be higher than the second price. |
|
-27 |
Delta
Trading can not execute the requested operation. Check the status of the
operation. |
|
-28 |
Unexpected
Error: DSAPI_Client.internalAPI/GetCommonOper. |
|
-29 |
Unknown
currency symbol. |
|
-30 |
Unexpected
Error: DSAPI_Client.internalAPI/GetQuote. |
|
-31 |
Unexpected
Error: DeltaTrading/frmDSAPI/internalAPI_GetQuoteAPI. |
|
-32 |
Unexpected
Error: DeltaTrading/frmDSAPI/internalAPI_GetOrdStatusAPI. |
|
-33 |
No open
currently position of specified instrument. |
|
-34 |
Wrong
parameters. |
|
-35 |
Order List
Is Not Complete. |
|
-9999 |
unknown
error message." |
Example: GetErrDescription (-10) à -10 - CFD trading not
authorized.
_______________________________________________________________________________
7. GetFreeMargin (InCurrency As String, errNumber As Long) as Double
Withdraws the free
margin of the desired currency.
Inputs:
InCurrency
= currency code (Example: InCurrency = „EUR”)
errNumber
– variable which displays the number of the error (see Error Table)
Example:
GetFreeMargin
(“USD”, errNumbe1) à 5431. 31 (in USD)
errNumbe1 à 0
_______________________________________________________________________________
8. GetOrdList_Asyn(Instrument As String, ordStatus
As Long, ordType As Long, ordBuySell As String, ordDate1 As Double, ordDate2 As
Double, RequestID As Long, errNumber As Long)
Displays list of orders
after the data is filtered. Filter is asynchronized. It displays two values –
RequestID and errNumber which is the reason for these two inputs to be set as
variables in advance.
Inputs:
Instrument –
Instrument cross code (Example: „EUR/USD”);
ordStatus
– order status 1 – ordered, 2 – confirmed, 3 – completed, 4 – cancelled,
5 – placed for cancellation;
ordType
– order
type: 1 – market, 2 – limit, 3 – stop, 4 – One-Cancels-Other (OCO);
ordBuySell - buy
– ‘B’ or sell – ‘S’;
ordDate1 –
Date; from:
ordDate2 – Date; To:
RequestID
– unique ID of the order to DSAPI_Client.clientAPI
errNumber
– error number (see Error Table)
Result:
RequestID – unique ID of the order to DSAPI_Client.clientAPI
errNumber
– variable wh