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:
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 AD that he wants to use the interface DSAPI_Client.
DSAPI_Client has all the following functions:
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/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 Delta Trading platform.
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
Cancels an order.
Inputs: OrdID - # of the order you want to cancel.
Result:
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
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.
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)
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.
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").
Example:
GetAccSum_S ("USD") - Result - RES2345.33 *ERR0*
GetParam("RES", Result) - Result 2345.33
GetParam("ERR", Result) - Result ErrorNumber - 0
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
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_S("EUR/USD", "24", "C:\chart\eurusd5.txt", 234242.2246, 353535.666) – result RES1*ERR0
GetParam("RES", Result) = 1
GetParam("ERR", Result) = 0
The Result has been saved into a file with the following (.csv- comma delimited) pattern:
<date>, <open>, <hi>, <low>,
<close>, <volume> crlf
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 | Not available funds for the order's execution. |
| -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. |
| -36 | Unexpected Error: DSAPI_Client.ClientAPI/SendMssg. |
| -37 | Unexpected Error: DSAPI_Client.ClientAPI/GetPosition. |
| -38 | Unexpected Error: DSAPI_Client.ClientAPI/GetOrdList_Async. |
| -39 | Unexpected Error: DSAPI_Client.ClientAPI/ClosePosition. |
| -40 | Unexpected Error: DSAPI_Client.ClientAPI/GetChartData. |
| -41 | Unexpected Error: DSAPI_Client.ClientAPI/GetOrdStatus. |
| -42 | Unexpected Error: DSAPI_Client.ClientAPI/GetOrdParams. |
| -43 | Unexpected Error: DSAPI_Client.ClientAPI/GetAccNum. |
| -44 | Unexpected Error: DSAPI_Client.ClientAPI/GetFreeMargin. |
| -45 | Unexpected Error: DSAPI_Client.ClientAPI/GetUsedMargin. |
| -46 | Unexpected Error: DSAPI_Client.ClientAPI/GetAccSum. |
| -47 | Unexpected Error: DSAPI_Client.ClientAPI/GetPositionRes. |
| -48 | Unexpected Error: DSAPI_Client.ClientAPI/GetQuote. |
| -49 | Unexpected Error: DSAPI_Client.ClientAPI/GetPositionsRes.. |
| -50 | Unexpected Error: DSAPI_Client.ClientAPI/CancelOrder_ASync. |
| -51 | Unexpected Error: DSAPI_Client.ClientAPI/CancelOrder. |
| -52 | Unexpected Error: DSAPI_Client.ClientAPI/NewOrder_Async. |
| -53 | Unexpected Error: DSAPI_Client.internalAPI/GetClnNumExecuted. |
| -54 | Unexpected Error: DSAPI_Client.internalAPI/GetOrdParamsExecuted. |
| -55 | Unexpected Error: DSAPI_Client.internalAPI/CancelOrderExecuted. |
| -56 | Unexpected Error: DSAPI_Client.internalAPI/Error_DSAPI. |
| -57 | Unexpected Error: DSAPI_Client.internalAPI/SetResValueExecuted. |
| -58 | Unexpected Error: DSAPI_Client.internalAPI/GetPositionExecuted. |
| -59 | Unexpected Error: DSAPI_Client.internalAPI/GetOrdListExecuted. |
| -240 | Delta Trading with the required account has not been started.. |
| -241 | There is API connected to Delta Trading with the same account.. |
| -242 | Account number is not found in DSAPI_Client.exe. |
| -243 | Unexpected Error: DSAPI_Client.internalAPI. |
Example: GetErrDescription (-10) - "-10 - CFD trading not authorized."
Displays the money locked in margin.
Inputs:
InCurrency - currency code (Example: InCurrency = "EUR");
errNumber - 0 or negative number (see Error Table)
Example:
GetUsedMargin ("USD", errNumber) - 1403.34 USD
errNumber - 0
Displays the money locked in margin.
Inputs:
InCurrency - currency code (Example: InCurrency = "EUR");
Example:
GetUsedMargin ("USD") - Result - RES1403.34 *ERR0*
GetParam("RES", Result) - 1403.34
GetParam("ERR", Result) - 0
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
Withdraws the free margin of the desired currency.
Inputs:
InCurrency - currency code (Example: InCurrency = "EUR")
Example:
GetFreeMargin_S("USD", errNumbe1) - Result - RES5431.31 *ERR0*
GetParam("RES", Result) - Result 34324.44 USD
GetParam("ERR", Result) - Result ErrorNumber - 0
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 which displays the error number (see Error Table)
Example:
GetOrdList_Async ("EUR/USD", 3, 2, "B", 01.05.2007, 30.05.2007, RequestID1, errNumber1)
RequestID1 - 242334
errNumber1 - 0
...
The result is displayed through the following message:
Instance_GetOrdListExecuted
RequestID - ID of the order received in GetOrdList_Async;
OrdID - order ID;
Instrument - instrument cross code;
ordStatus - order status: 1 - ordered, 2 - confirmed, 3 - completed, 4 - canceled, 5 - asked to cancel;
ordType - order type: 1 - market, 2 - limit, 3 - stop, 4 - One-Cancels-Other (OCO);
ordBuySell - buy - 'B' or sell - 'S';
ordDate1 - date of order converted in Double (8-byte);
ordDate2 - date of last status change converted in Double (8-byte);
оrdCount - order quantity;
ordPrice - order price;
ordPrice1 - order price as asked;
errNumber - error number, (see Error Table), if there is an error, that means that there is data missing.
Asks the serer about the order status.
Inputs:
OrdID - ID of the order which you aim to check.
Result:
1 - ordered, 2 - confirmed, 3 - completed, 4 - canceled, 5 - asked to cancel;
< 0 - error number (see Error Number).
Example: GetOrdStatus (12345678) - 3 (completed).
Asks the serer about the order status.
Inputs:
OrdID - ID of the order which you aim to check.
Result:
1 - ordered, 2 - confirmed, 3 - completed, 4 - canceled, 5 - asked to cancel;
< 0 - error number (see Error Number).
Example: GetOrdStatus_S (12345678) - 3 (completed).
Displays the current status of a position.
Inputs:
Instrument - instrument cross code (Example: "EUR/USD");
Count - variable which displays the quantity of the position using a reference;
Price - variable which displays the average price of the position using a reference;
errNumber - error number (see Error Table), if there is an error, that means that there is data missing from in the inputs.
Example:
GetPosition ("USD/JPY", "USD", errNumber1)
errNumber1 - 0
Result:
Count - quantity;
Price - price;
errNumber - error number.
Displays the current status of a position.
Inputs:
Instrument – instrument cross code (Example: "EUR/USD");
Example:
GetPosition_S ("USD/JPY")
Result: CNT1000*PR1.2567*ERR0
CNT – variable which displays the quantity of the position using a reference;
PR – variable which displays the average price of the position using a reference;
ERR – variable, which displays the number of the error (see Error Table).
GetParam("CNT", "CNT1000*PR1.2567*ERR0") - 1000
GetParam("PR", "CNT1000*PR1.2567*ERR0") - 1.2567
GetParam("ERR", "CNT1000*PR1.2567*ERR0") - 0
Displays the result from open positions on the given instrument.
Inputs:
Instrument - instrument code (Example: InCurrency = "EUR/USD");c
InCurrency - currency in which the result is calculated (Example: InCurrency = "EUR");
errNumber - displays the error number (see Error Table),
Result:
Result from open positions.
Example:
GetPositionRes ("EUR/USD", "EUR", errNumber1) - 34324.44 (in "EUR")
errNumber1 - 0
Displays the result from open positions on the given instrument.
Inputs:
Instrument - instrument code (Example: "EUR/USD");
InCurrency - currency in which the result is calculated (Example: InCurrency = "EUR");
Result:
Result from open positions.
Example:
GetPositionRes_S ("EUR/USD", "EUR") - RES34324.44 *ERR0*
GetParam("RES", "RES34324.44 *ERR0*") - Result 34324.44 EUR
GetParam("ERR", "RES34324.44 *ERR0*") - Result ErrorNumber - 0
Displays the total result from all the open positions.
Inputs:
InCurrency - currency in which the result is calculated (Example: InCurrency = "EUR");
errNumber - displays the error number (see Error Table),
Result:
Result of all the open positions displayed in the given currency.
Example:
GetPositionRes ("EUR" , errNumber1) - 34114.44 (in "EUR")
errNumber1 - 0
Displays the total result from all the open positions.
Inputs
:InCurrency - currency in which the result is calculated (Example: InCurrency = "EUR")
Result:
Result of all the open positions displayed in the given currency.
Example:
GetPositionsRes ("EUR") - Result RES34114.44*ERR0*
GetParam("RES", "RES34114.44*ERR0*") - Result 34114.44 EUR
GetParam("ERR", "RES34114.44*ERR0*") - Result ErrorNumber - 0
Displays the quote of the Instrument.
Inputs:
Instrument - instrument ticker code (Example: "EUR/USD")
QBid, QAsk, QHi, QLow, ErrNumber - Buy, sell, high, low, error. These inputs must be variables because the result is displayed after a reference to them.
Result:
QBid, QAsk, QHi, QLow, ErrNumber
Example:
GetQuote ("USD/GBP", QBid1, QAsk1, QHi1, QLow1, ErrNumber1)
QBid1 - 1.3681
QAsk1 - 1.3684
QHi1 - 1.3689
QLow1 - 1.3680
ErrNumber1 - 0
Displays the quote of the Instrument.
Inputs:
Instrument - instrument ticker code (Example: "EUR/USD")
Example:
GetQuote ("USD/GBP") - Result = BID1.3681*ASK1.3684*HI1.3689*LOW1.3680*ERR0*
GetParam("BID", Result) - 1.3681
GetParam("ASK", Result) - 1.3684
GetParam("HI", Result) - 1.3689
GetParam("LOW", Result) - 1.3680
GetParam("ERR", Result) - 0
Displays the total result of the specified currency.
Inputs:
InCurrency - currency (Example: InCurrency = "EUR");
errNumber - 0 or negative number (see Error Table).
Example:
GetTotalResult ("USD" , errNumber1) - 5307.23
errNumber1 - 0
Displays the total result of the specified currency.
Inputs:
InCurrency - currency (Example: InCurrency = "EUR");
Example:
GetTotalResult ("USD") - Result - RES5307.23 *ERR0*
GetParam("RES", Result) - 5307.23
GetParam("ERR", Result) - 0
Places a new order.
Inputs:
Instrument - instrument cross code (Example: "EUR/USD");
ordCount - quantity;
ordPriceReq1 - price;
ordPriceReq2 - price2 (concerning OCO orders);
ordType - order type: 1 - market, 2 - limit, 3 - stop, 4 - OCO;
ordBuySell - buy- 'B' or sell - 'S';
ordValidity - for the day - '1' until cancelled - '2'.
Result:
Displays OrdID - the order ID. If the result is a negative number, then an error exists.
Example:
NewOrder ("EUR/USD", 10000, 0, 0, 1, "B", 2) - market order buys 10 lots (10000) "EUR/USD" validity: until cancelled
NewOrder ("EUR/USD", 10000, 1.3680, 0, 2, "S", 2) - limit order sells 10 lots
(10000) "EUR/USD" at 1.3680, validity: until cancelled
Inputs:
Instrument - instrument cross code (Example: "EUR/USD");
ordCount - quantity;
ordPriceReq1 - price;
ordPriceReq2 - price2 (concerning OCO orders);
ordType - rder type: 1 - market, 2 - limit, 3 - stop, 4 - OCO;
ordBuySell - Buy - 'B' or Sell - 'S';
ordValidity - for the day - '1'; until cancelled - '2'.
Result:
RequestID As Long
If an error exists then the error number = ErrNumber.
Example:
NewOrder ("EUR/USD", 10000, 0, 0, 1, "B", 2) - Market price order buys 10 lots(10000) "EUR/USD" validity: until cancelled;
NewOrder ("EUR/USD", 10000, 1.3680, 0, 2, "S", 2) - limit sells 10 lots(10000) "EUR/USD" at 1.3680, validity: until cancelled.
...
The result is displayed through the following result:
Instance_NewOrder_Async (InstrDispCode As String, ordCount As Long, ordPriceReq1 As Double, ordPriceReq2 As Double, ordType As Long, ordBuySell As String, ordValidity As String, RequestID As Long, errNumber As Long)
Displays the instrument ID, price, status and the type of an order - Buy/Sell.
Inputs:
OrdID - order number.
errNumber - 0 or negative number (see Error Table)
Example:
GetOrdParams("467298", errNumber)
Result - *IAUD/NZD*CNT1000*PR1.23424*ST3*BSB
GetParam("I", Result) - Instrument: AUD/NZD
GetParam("CNT", Result) - Quantity: 1000
GetParam("PR", Result) - Price: 1.23424
GetParam("ST", Result) - Status: 3
GetParam("BS", Result) - Buy/Sell: B
Displays the instrument ID, price, status and the type of an order - Buy/Sell.
Inputs:
OrdID - order number.
Example:
GetOrdParams_S("467298", errNumber)
Result - *IAUD/NZD*CNT1000*PR1.23424*ST3*BSB*ERR0
GetParam("I", Result) - Instrument: AUD/NZD
GetParam("CNT", Result) - Quantity: 1000
GetParam("PR", Result) - Price: 1.23424
GetParam("ST", Result) - Status: 3
GetParam("BS", Result) - Buy/Sell: B
GetParam("ERR", Result) - Error: 0
Displays the client number.
Example:
GetClnNum() - Result - "000102310"
Displays the version of the Delta Trading API.
Example:
GetApiVersion() - Result - "1.0.41"
Displays the version of the Delta Trading platform.
Example:
GetDTVersion() - Result - "4.0.12"
Displays the parameters on the result from a specified function.
Inputs:
strKey - index;
strExpr - result from a specified function.
Example:
GetParam("CNT", "*IAUD/NZD*CNT1000*PR1.23424*ST3*BSB*ERR0") - Result - 1000
Creates Delta Trading ClientAPI for the specified account.
Inputs:
strExtNumber - client number.
Example:
CreateClientAPI() - If an error exists then the error number = ErrNumber.
CreateClientAPI("000123456") - If an error exists then the error number = ErrNumber.
Turns off the Delta Trading ClientAPI.
More examples.
Save file as NewOrder.js - the extension .js is mandatory.