Creating your first application¶
Note: This does not include the installation of Visual Studio; if you need to install Visual Studio, please go here.
Download the RefineryCsAPI¶
The librarys for the API are available on the First Derivatives Nexus server here
Download the latest version of the RefineryCsAPI package and unzip it into your preferred location; we will use these later. If you do not have a Nexus account, please contact your administrator.
Open Visual Studio and create a new console app¶
If you are new to Visual Studio and C#, follow the instructions here to make a short console app that prints Hello World. This link is for Visual Studio 2019; if you are using a different version, you can modify the end of the URL to target your version. E.g ?view=vs-2017
Add references to your project¶
Now that you have a basic project set up, you need to add references to it in order the use the API.
These are:
- System.Configuration
- The RefineryCsAPI dll's that you downloaded earlier
- DaaSCsAPICore.dll
- DeltaAPICore.dll
- NewtonSoft.Json.dll
Details of how to add a reference are here. When adding the references, use the Browse button to find the dll's in the location that you unzipped them into earlier.
Again, to view the documentation for a different version of Visual Studio you can modify ?view=vs-2019 in the URL.
Set your Visual Studio target platform¶
The Refinery API is compiled to work with x64 architecture. In Visual Studio we need to specify this as show here
Connect your console app to an instance of Refinery¶
At this point, you need to add some details of where your console application should connect to. This is set by the host and port keys in the App.config file. Update your App.config file to match the example provided here and then modify the keys to point to the instance that you want to target.
Load your application settings into your program¶
In your Main method of your program, you can load the settings from the App.config file and then start an instance of the Service class to connect to your environment.
// use ConfigurationManager.AppSettings to load your App.config settings
string host = ConfigurationManager.AppSettings["host"];
int port = Convert.ToInt32(ConfigurationManager.AppSettings["port"]);
string username = ConfigurationManager.AppSettings["username"];
string password = ConfigurationManager.AppSettings["password"];
bool tls = Convert.ToBoolean(ConfigurationManager.AppSettings["tls"]);
bool exclusive = Convert.ToBoolean(ConfigurationManager.AppSettings["exclusive"]);
string instanceName = ConfigurationManager.AppSettings["instanceName"];
string messagingServerConfigName = ConfigurationManager.AppSettings["messagingServerConfigName"];
string secondaryHost = ConfigurationManager.AppSettings["secondaryHost"];
int secondaryPort = Convert.ToInt32(ConfigurationManager.AppSettings["secondaryPort"]);
// Start an instance of the Service class
var _service = new Service(host, port, username, password, instanceName, exclusive, messagingServerConfigName, tls);
Console.WriteLine("{0} Starting Service...", DateTime.Now);
_service.Start(TimeSpan.FromSeconds(20));
Console.WriteLine("{0} Service started.", DateTime.Now);
Run a test query¶
Once you have an instance of the Service started, you can use the RunQuery method to send a sample query to the system.
// Create a parameter dictionary for the query
Dictionary<string, object> parameters = new Dictionary<string, object>();
parameters["symList"] = new[] { "VOD.L" };
parameters["dataType"] = "trade";
parameters["assetClass"] = "equity";
parameters["startDate"] = new DateTime(2019, 01, 27);;
parameters["endDate"] = new DateTime(2019, 01, 27);;
parameters["applyFilter"] = new object[] { '=', "volume", 25 };
// Execute the query
var result = service.RunQuery("getTicks", parameters);