Импорт внешних данных
C#
Импорт внешних данных с диска на примере сценария
Код
public override void Run()
{
= InstrumentManager["AAPL2"];
Instrument instrument string filepath = "F:\\dataSample.txt";
using (System.IO.StreamReader sr = new System.IO.StreamReader(filepath))
{
.ReadLine(); //header
sr
while(sr.Peek() >= 0)
{
string[] parts = sr.ReadLine().Split(',');
//reducing fraction part to be able use in formatter
string dt_ = parts[0].Substring(0, parts[0].Length-2);
= DateTime.ParseExact(dt_, "yyyy-MM-dd HH:mm:ss.fffffff", null);
DateTime dt
if (parts[1] != "NaN") //parse trade
{
double tradePrice = double.Parse(parts[1]);
int tradeSize = int.Parse(parts[2]);
= new Trade(dt, 0, instrument.Id, tradePrice, tradeSize);
Trade trade
.Save(trade);
DataManager}
if (parts[4] != "NaN") //parse bid
{
double bidPrice = double.Parse(parts[4]);
int bidSize = int.Parse(parts[5]);
= new Bid(dt, 0, instrument.Id, bidPrice, bidSize);
Bid bid
.Save(bid);
DataManager}
if (parts[6] != "NaN") //parse ask
{
double askPrice = double.Parse(parts[6]);
int askSize = int.Parse(parts[7]);
= new Ask(dt, 0, instrument.Id, askPrice, askSize);
Ask ask
.Save(ask);
DataManager}
}
}
.WriteLine("Finishedd");
Console}