Hi guys,
I have been working on a DLL which makes use of DAS trader API to place orders. Now, for couple of days, I have been trying to call a simple function from a EFS file. But every time I reload the script, I keep on getting the following error message:
Internal Error : DLL.call can not locate (testFunction)
Following is my efs code.
Following is my DLL file code :
I am trying to call "testFunction" from my efs. Can any one tell me why am I getting this error. Any help/advice will be greatly appreciated.
Thanks and Regards,
Vipin
I have been working on a DLL which makes use of DAS trader API to place orders. Now, for couple of days, I have been trying to call a simple function from a EFS file. But every time I reload the script, I keep on getting the following error message:
Internal Error : DLL.call can not locate (testFunction)
Following is my efs code.
Code:
var DASdll = null; function loadDASDLL() { if(DASdll == null) { DASdll = new DLL("C://Users//0004//Documents//Visual Studio 2010//Projects//ESignalDASConnector//ESignalDASConnector//bin//Release//ESignalDASConnectorx64.dll"); DASdll.AddFunction("testFunction",DLL.STRING,DLL.STDCALL,"testFunction"); } } function preMain() { loadDASDLL(); } function main() { if(getBarState() == BARSTATE_NEWBAR) { var str = DASdll.call("testFunction"); debugPrintln(str); } }
Following is my DLL file code :
Code:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using daslibrary; namespace ESignalDASConnector { public class Connector { private int masterTraderID; // Need to get it from DAS private int brokerID; private string mrrno; private SocketOrderServer sOS; private SocketQuoteServer quoteServer = null; private itemTrader itemtrader = null; private string orderServer = ""; private string quoteServerAddress = ""; private string masterTraderName; private int orderPort = 0; private int quotePort = 0; private const int waitSeconds = 5; private int masterAccountID = 53; // will change private string username = ""; // will change private string password = ""; // will change private itemOrder CreateOrder(string symbol, int qty, double askPrice, double bidPrice, double executionPrice, bool isBuyOrder, bool isMarketOrder, string route, byte exch, int accid) { itemOrder iOrder = new itemOrder(); iOrder.mstatus = 0; this.getSocketOrderServer(); if (isMarketOrder == true) { iOrder.mstatus |= 1 << 9; // placing market order if (isBuyOrder == true) { iOrder.mstatus |= 1 << 6; iOrder.mprice = askPrice; } else { iOrder.mprice = bidPrice; } } else { if (isBuyOrder == true) { iOrder.mstatus |= 1 << 6; } iOrder.mprice = executionPrice; iOrder.mtmforce = 65535; } iOrder.msecsym = symbol; iOrder.mqty = qty; iOrder.mroute = route; iOrder.maccid = accid; iOrder.mtrid = this.masterTraderID; iOrder.mbrid = this.brokerID; iOrder.mrrno = this.mrrno; iOrder.mexchange = exch; return iOrder; } private void connectSocketOrderServer() { sOS = new SocketOrderServer(); sOS.Connect(orderServer, orderPort); sOS.PkgLongin(username, password, orderServer); int timeout = 0; while (timeout <= waitSeconds * 1000) // wait waitseconds(default =3) seconds { timeout += 500; System.Threading.Thread.Sleep(500); itemtrader = sOS.sitemTrader.FindItemByName(username); if (itemtrader != null) { System.Console.WriteLine("Connection established"); try { this.connectQuoteServer(); masterTraderName = username; masterTraderID = itemtrader.mtrid; brokerID = itemtrader.mbrid; mrrno = sOS.sitemAccount.FindItem(masterAccountID).mitemifo.mrrno; System.Console.WriteLine("MasterID " + masterTraderID); } catch (Exception e) { System.Console.WriteLine(e.StackTrace); } break; } } if (timeout > waitSeconds * 1000) { System.Console.WriteLine("Connection problem and timed out"); Environment.Exit(0); } } private void connectQuoteServer() { if (quoteServer == null) { quoteServer = new SocketQuoteServer(sOS); quoteServer.Connect(quoteServerAddress, quotePort); quoteServer.PkgLogin(username, password, quoteServerAddress); } } public SocketOrderServer getSocketOrderServer() { if (this.sOS == null || !this.sOS.IsConnected()) { this.connectSocketOrderServer(); this.connectQuoteServer(); } return sOS; } public bool sendOrder(string symbol, int qty, double askPrice, double bidPrice, double executionPrice, bool isBuyOrder, bool isMarketOrder, string route, byte exch, int accid) { string errmsg = ""; long morig = -1; long timeout = 0; itemOrder iOrder = CreateOrder(symbol, qty, askPrice, bidPrice, executionPrice, isBuyOrder, isMarketOrder, route, exch, accid); if (itemOrder.LSendOrder(iOrder, ref errmsg, true, this.sOS, ref morig) == 0) { itemOrder myorder = null; while (timeout <= 60000) { timeout += 1000; System.Threading.Thread.Sleep(1000); myorder = sOS.sitemOrder.FindItemBymorig((int)morig); if (myorder != null) { if (!(((myorder.mstatus & (1 << 4)) != 0) || ((myorder.mstatus & (1 << 1)) != 0))) continue; if ((myorder.mstatus & (1 << 1)) != 0) { System.Console.WriteLine("Order Executed"); return true; } else if ((myorder.mstatus & (1 << 2)) != 0) { System.Console.WriteLine("Order Canceled"); return true; } else if ((myorder.mstatus & (1 << 3)) != 0) { System.Console.WriteLine("Order Rejected"); return true; } else if ((myorder.mstatus & (1 << 4)) != 0) { System.Console.WriteLine("Order Accepted"); return true; } else if ((myorder.mstatus & (1 << 5)) != 0) { System.Console.WriteLine("Order Timeout"); return true; } } } } return false; } [B] public String testFunction() { return "Hello world"; }[/B] } }
Thanks and Regards,
Vipin
Comment