|
|
DSAPI_Client APIп»ї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 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):
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:
Description of DSAPI_Client functions 1. CancelOrder (OrdID As Long) As LongCancels 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 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 LongCloses 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 DoubleReturns 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. GetAccSum_S (InCurrency As String)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 6. GetChartData (Instrument As String, iTypeInter As String, fname As String, DateFrom As Double, DateTo As Double, errNumber As Long) As LongDisplays 0/1 - false/true exporting chart data to another file. Inputs: Instrument - instrument code iTypeInter - time period:
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: 7. GetChartData_S (Instrument As String, iTypeInter As String, fname As String, DateFrom As Double, DateTo As Double) As LongDisplays 0/1 - false/true exporting chart data to another file. Inputs: Instrument - instrument code iTypeInter - time period:
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: 8. GetErrDescription (ErrorNumber As Long) As StringDisplays error description after an error number is entered.
Example: GetErrDescription (-10) - "-10 - CFD trading not authorized." 9. GetUsedMargin (InCurrency As String, errNumber As Long) As DoubleDisplays 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 10. GetUsedMargin_S (InCurrency As String) As StringDisplays 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 11. GetFreeMargin (InCurrency As String, errNumber As Long) as DoubleWithdraws 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 12. GetFreeMargin_S (InCurrency As String)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 13. GetOrdList_Async (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 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 As
Long, OrdID As Long, Instrument As String,
ordStatus As Long, ordType As Long, ordBuySell As String, ordDate1 As Double, ordDate2 As Double, ordCount As Double, ordPrice As Double, ordPrice1 As Double, errNumber As Long) 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. 15. GetOrdStatus (OrdID As Long) As LongAsks 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). 16. GetOrdStatus_S(OrdID As Long)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). 17. GetPosition (Instrument As String, Count As Double, Price As Double, errNumber As Long)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. 18. GetPosition_S (Instrument As String) as StringDisplays 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 19. GetPositionRes (Instrument As String, InCurrency As String, errNumber As Long) As DoubleDisplays 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 20. GetPositionRes_S (Instrument As String, InCurrency As String) As StringDisplays 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 21. GetPositionsRes (InCurrency As String, errNumber As Long) As DoubleDisplays 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 22. GetPositionsRes_S (InCurrency As String) As StringDisplays 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 23. GetQuote (Instrument As String QBid As Double, QAsk As Double, QHi As Double, QLow As Double, errNumber As Long)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 24. GetQuote_S (Instrument As String)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 25. GetTotalResult (InCurrency As String, errNumber As Long) As DoubleDisplays 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 26. GetTotalResult_S(InCurrency As String) As StringDisplays 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 27. NewOrder (Instrument As String, ordCount As Long, ordPriceReq1 As Double, ordPriceReq2 As Double, ordType As Long, ordBuySell As String, ordValidity As String) As LongPlaces 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 28. NewOrder_Async (Instrument 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)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) 29. GetOrdParams (OrdID As Long, errNumber As Long) As StringDisplays 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 30. GetOrdParams_S(OrdID As Long) As StringDisplays 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 31. GetClnNum() As StringDisplays the client number. Example: GetClnNum() - Result - "000102310" 32. GetApiVersion() As StringDisplays the version of the Delta Trading API. Example: GetApiVersion() - Result - "1.0.41" 33. GetDTVersion() As StringDisplays the version of the Delta Trading platform. Example: GetDTVersion() - Result - "4.0.12" 34. GetParam(strKey as String, strExpr as String) As StringDisplays 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 35. CreateClientAPI(Optional ByVal strExtNumber As String = "") As LongCreates 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. 36. DestroyClientAPI() As LongTurns off the Delta Trading ClientAPI. More examples. Windows Script Host:
Microsoft Visual Basic 6.0
Microsoft VB.NET 2005
Microsoft Visual C# 2005
|
DTWeb Login
Suport Live
Profilul meu
Platforme