1: using System;
2: using System.Collections.Generic;
3: using System.Linq;
4: using System.Text;
5: using System.IO;
6: using System.Windows.Forms;
7:
8: namespace uaAPI
9: {
10: class Program
11: {
12: static void Main(string[] args)
13: {
14: //Read EXE arguments
15: string paramFile = args[0];
16: string outputDir = args[1];
17:
18: //Read Param file containing all Futures contracts to manipulate
19: StreamReader param = new StreamReader(paramFile);
20:
21: //Add Instrument to a list
22: List<string[]> instruments = new List<string[]>();
23: string line;
24: while ((line = param.ReadLine()) != null)
25: instruments.Add(line.Split(','));
26:
27: //Instantiate CSI UA
28: UA.API2Class ua = new UA.API2Class();
29:
30: //Set Properties
31: ua.IncludeSaturdays = 0;
32: ua.IncludeHolidays = 0;
33: ua.OnHolidaysUsePreviousData= 0;
34: ua.OnHolidaysUseCloseOnly = 0;
35: ua.ShowDecimalPoint = 1;
36: ua.detrendMethod = 0;
37: ua.FillInCashPrice= 1;
38: ua.ApplyCommodityAdjustments = 1; //check how adjusted
39: ua.UseAlternateBackAdjuster = 1;
40: ua.RaiseNegBackAdjustSeries= 0;
41: ua.NumDaysConfirmation = 2;
42: ua.CloseOutOfRangeAdjustmentMethod = 0;
43: ua.RoundToTick = 0;
44: ua.UseTradeableTick = 0;
45:
46: //Loop through the list of futures and get data from CSI
47: foreach (string[] instru in instruments)
48: {
49: string instrument = instru[0];
50:
51: //We could use options to drive what type of data we extract here
52: //for now just back-adjusted proportional contract
53: int iInst = int.Parse(instrument);
54:
55: //Get Market Profile for Valid Months
56: ua.MarketNumber = iInst;
57: ua.GetMarketProfile();
58: string validMonths = ua.ValidMonths;
59:
60: ua.RetrieveBackAdjustedContract2(iInst, -1, 1, 0, 0, 1, -1, validMonths, 1, 5, -1, -1, 1);
61: //long RetrieveBackAdjustedContract2(
62: //long MarketNumber,
63: //short rollLogicType,
64: //short rollWhen,
65: //short DayOfMonthToRoll,
66: //short MonthsPriorToRoll,
67: //short accumulationMethod,
68: //short rollDeltaType,
69: //String ValidMonths,
70: //short GenerateForward,
71: //short RollAtLeastNDaysBeforeExpiration,
72: //long StartDate,
73: //long EndDate,
74: //short ProportionalAdjustment);
75:
76: //Copy retrieve Data into clipboard
77: ua.CopyDataToClipboard();
78:
79: //Read data from the clipboard and outputs it to a file
80: string text = Clipboard.GetText();
81: using (StringReader reader = new StringReader( text ))
82: {
83: StreamWriter sw = new StreamWriter(outputDir + instru[1] + ".txt");
84: while ((line = reader.ReadLine()) != null)
85: {
86: sw.WriteLine( line );
87: }
88: sw.Close();
89: }
90: }
91: }
92: }
93: }