using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; using System.Windows.Forms; namespace uaAPI { class Program { static void Main(string[] args) { //Read EXE arguments string paramFile = args[0]; string outputDir = args[1]; //Read Param file containing all Futures contracts to manipulate StreamReader param = new StreamReader(paramFile); //Add Instrument to a list List instruments = new List(); string line; while ((line = param.ReadLine()) != null) instruments.Add(line.Split(',')); //Instantiate CSI UA UA.API2Class ua = new UA.API2Class(); //Set Properties ua.IncludeSaturdays = 0; ua.IncludeHolidays = 0; ua.OnHolidaysUsePreviousData= 0; ua.OnHolidaysUseCloseOnly = 0; ua.ShowDecimalPoint = 1; ua.detrendMethod = 0; ua.FillInCashPrice= 1; ua.ApplyCommodityAdjustments = 1; //check how adjusted ua.UseAlternateBackAdjuster = 1; ua.RaiseNegBackAdjustSeries= 0; ua.NumDaysConfirmation = 2; ua.CloseOutOfRangeAdjustmentMethod = 0; ua.RoundToTick = 0; ua.UseTradeableTick = 0; //Loop through the list of futures and get data from CSI foreach (string[] instru in instruments) { string instrument = instru[0]; //We could use options to drive what type of data we extract here //for now just back-adjusted proportional contract int iInst = int.Parse(instrument); //Get Market Profile for Valid Months ua.MarketNumber = iInst; ua.GetMarketProfile(); string validMonths = ua.ValidMonths; ua.RetrieveBackAdjustedContract2(iInst, -1, 1, 0, 0, 1, -1, validMonths, 1, 5, -1, -1, 1); //long RetrieveBackAdjustedContract2( //long MarketNumber, //short rollLogicType, //short rollWhen, //short DayOfMonthToRoll, //short MonthsPriorToRoll, //short accumulationMethod, //short rollDeltaType, //String ValidMonths, //short GenerateForward, //short RollAtLeastNDaysBeforeExpiration, //long StartDate, //long EndDate, //short ProportionalAdjustment); //Object a = new Object() { }; //Object b = new Object() { }; //Object c = new Object() { }; //Object d = new Object() { }; //Object e = new Object() { }; //Object f = new Object() { }; //Object g = new Object() { }; //Object h = new Object() { }; //Object i = new Object() { }; //Object j = new Object() { }; //Object k = new Object() { }; //Object l = new Object() { }; //Object m = new Object() { }; //Object n = new Object() { }; //ua.CopyRetrievedDataToArray(1, out a, out b, out c, out d, out e, out f, out g, out h, out i, out j, out k, out l, out m, out n); Object results; Object filt; ua.CopyRetrievedDataToArray2(0, out results, out filt); //THERE SEEMS TO NOW BE A PROBLEM WITH CLIPBOARD INTERACTION SO WE HAD TO REPLACE THE //APPROACH WITH COPYING DATA TO ARRAYS AND READING FROM ARRAYS //Copy retrieve Data into clipboard //ua.CopyDataToClipboard(); //ua.CombineDataToClipboard(1); //Read data from the clipboard and outputs it to a file //string text = Clipboard.GetText(); //using (StringReader reader = new StringReader( text )) //{ // StreamWriter sw = new StreamWriter(outputDir + "\\" + instru[1] + ".txt"); // while ((line = reader.ReadLine()) != null) // { // sw.WriteLine( line ); // } // sw.Close(); //} int[,] res = (int[,])results; double[,] fil = (double[,])filt; StreamWriter sw = new StreamWriter(outputDir + "\\" + ua.MarketSymbol + "_" + ua.MarketName + "_" + ua.MarketNumber + ".txt"); for (long i = 0; i <= res.GetUpperBound(1); i++) { string outline = res[0, i].ToString(); for (long l = 1; l <= res.GetUpperBound(0); l++) { outline += "," + res[l, i].ToString(); } for (long l = 0; l <= fil.GetUpperBound(0); l++) { outline += "," + fil[l, i].ToString(); } sw.WriteLine(outline); } sw.Close(); } } } }