private static Dictionary <TradeInstrument.Issuer, double> GetInstruments(string text) { Dictionary <TradeInstrument.Issuer, double> dictionary = new Dictionary <TradeInstrument.Issuer, double>(); string[] lineSplit = text.Split('\n', '\r'); bool isFutures = true; foreach (string line in lineSplit) { if (!String.IsNullOrEmpty(line)) { string lineWoCommas = line.Trim(':', ';'); if (lineWoCommas == SLSettings.FuturesName) { isFutures = true; continue; } if (lineWoCommas == SLSettings.StocksName) { isFutures = false; continue; } string[] issuerAndStop = lineWoCommas.Split(' '); TradeInstrument.Issuer issuer = TradeInstrument.GetIssuerRa(issuerAndStop[0], isFutures); dictionary.Add(issuer, StringFunctions.ParseDouble(issuerAndStop[1])); } } return(dictionary); }
public static void SetOpenValuesLittleTable(ref ObservableCollection <LittleTableViewer> table) { RaBotProgram.Qt = new QT(); RaBotProgram.Qt.LuaConnect(); try { foreach (LittleTableViewer tableViewer in table) { RaBotProgram.Qt.RegisterSecurity(TradeInstrument.GetIssuerCode(tableViewer.Instrument)); } for (int i = 0; i < table.Count; i++) { decimal?openValue = RaBotProgram.Qt.GetSecOpenVal (TradeInstrument.GetIssuerCode(table[i].Instrument)); if (openValue.HasValue) { table[i].OpenValue = openValue.Value; } } } finally { RaBotProgram.Qt.LuaDisconnect(); } }
public static void ReadCurrentDeals() { _currentDeals = new List <Deal>(); StreamReader streamReader = new StreamReader (Path.Combine(Application.StartupPath, Config.MiscFolderName, Folder, CurrentDealsFileName), Encoding.UTF8); try { while (!streamReader.EndOfStream) { string line = streamReader.ReadLine(); if (string.IsNullOrEmpty(line)) { break; } string[] split = line.Split(';'); DateTime date = DateTime.ParseExact(split[0], "dd.MM.yyyy HH:mm:ss", CultureInfo.InvariantCulture); TradeInstrument.Issuer issuer = TradeInstrument.GetIssuer(split[1]); decimal openVal = StringFunctions.ParseDecimal(split[2]); string dir = split[3]; int vol = int.Parse(split[4]); decimal stopVal = StringFunctions.ParseDecimal(split[5]); DateTime stopDate = DateTime.ParseExact(split[6], "dd.MM.yyyy HH:mm:ss", CultureInfo.InvariantCulture); Deal deal = new Deal(issuer, dir, date, openVal, vol, stopVal, stopDate); _currentDeals.Add(deal); } } finally { streamReader.Close(); } }
public static void GetLittleStops() { _littleDeals = new Dictionary <DateTime, List <LittleTableViewer> >(); string filePath = Path.Combine(Application.StartupPath, Config.MiscFolderName, Folder, FileName); if (File.Exists(filePath)) { List <LittleTableViewer> deals = new List <LittleTableViewer>(); DateTime date = DateTime.Today; using (StreamReader streamReader = new StreamReader(filePath, Encoding.UTF8)) { while (!streamReader.EndOfStream) { string line = streamReader.ReadLine(); string[] parametrs = line.Split(';'); if (parametrs.Length > 1) { LittleTableViewer tbV = new LittleTableViewer(); tbV.Instrument = TradeInstrument.GetIssuer2Name(parametrs[0]); int isLong = Int32.Parse(parametrs[1]); switch (isLong) { case 0: tbV.IsLong = false; break; case 1: tbV.IsLong = true; break; } tbV.OpenValue = StringFunctions.ParseDecimal(parametrs[2]); tbV.StopValue = StringFunctions.ParseDecimal(parametrs[3]); if (String.IsNullOrEmpty(parametrs[4])) { tbV.Profit = null; } else { tbV.Profit = StringFunctions.ParseDouble(parametrs[4]); } deals.Add(tbV); } else { if (deals.Count > 0) { _littleDeals.Add(date, deals); deals.Clear(); } date = StringFunctions.GetDate(line, "dd.MM.yyyy"); } } _littleDeals.Add(date, deals); } } }
public static void AppendLittleTable(DateTime dateTime, ObservableCollection <LittleTableViewer> table) { List <LittleTableViewer> littleTable = _littleDeals[dateTime.Date]; { for (int i = 0; i < littleTable.Count; i++) { littleTable[i].Instrument = table[i].Instrument; littleTable[i].IsLong = table[i].IsLong; littleTable[i].OpenValue = table[i].OpenValue; littleTable[i].StopValue = table[i].StopValue; littleTable[i].Profit = table[i].Profit; } } string newFilePath = Path.Combine (Application.StartupPath, Config.MiscFolderName, Folder, CopyFileName); using (StreamWriter sw = new StreamWriter(newFilePath, false, Encoding.UTF8)) { foreach (KeyValuePair <DateTime, List <LittleTableViewer> > dayLittleTable in _littleDeals) { sw.WriteLine(dayLittleTable.Key.ToShortDateString()); foreach (LittleTableViewer dealParams in dayLittleTable.Value) { sw.Write(TradeInstrument.GetIssuerName(dealParams.Instrument)); sw.Write(';'); if (dealParams.IsLong) { sw.Write(1); } else { sw.Write(0); } sw.Write(';'); sw.Write(dealParams.OpenValue); sw.Write(';'); sw.Write(dealParams.StopValue); sw.Write(';'); sw.WriteLine(dealParams.Profit); } sw.Flush(); } sw.Close(); } string oldFilePath = Path.Combine (Application.StartupPath, Config.MiscFolderName, Folder, FileName); if (File.Exists(oldFilePath)) { File.Delete(oldFilePath); } File.Move(newFilePath, oldFilePath); }
public static void Check() { bool selectFiles = SetFiles(); if (selectFiles) { foreach (string file in Files) { TradeInstrument instrument = new TradeInstrument(file); instrument.ReadAllQuotes(); instrument.ReadAllRomanDeals(); instrument.WriteAllDeals(); instrument.WriteSimpleDeals(); } } MessageBox.Show("vse!"); }
private long GetOrCreateTradeFeeInstrumentId(TradeInstrument tradeInstrument) { if (_tradeInstrumentModel.Contains(tradeInstrument.InstrumentName)) { return(_tradeInstrumentModel.GetById(tradeInstrument.InstrumentName).Id); } var result = _importJobRepository.AddTradeInstrument(tradeInstrument); _importJobRepository.SaveChanges(); _tradeInstrumentModel.Add(result.InstrumentName, new TradeInstrumentModel { Id = result.Id }); return(result.Id); }
private static void SetRomanIssuer(LittleTableViewer props) { string shortFileName = TradeInstrument.GetIssuerCode(props.Instrument); string fullPath = SetFile(shortFileName); using (ExcelClass xls = new ExcelClass()) { xls.OpenDocument(fullPath, false); int firstFreeRow = int.Parse(xls.GetCellStringValue(1, 1)); xls.SetCellValue(9, firstFreeRow, Deal.GetDirection(props.IsLong)); xls.SetCellValue(10, firstFreeRow, props.OpenValue.ToString()); xls.SetCellValue(11, firstFreeRow, props.StopValue.ToString()); xls.SetCellValue(12, firstFreeRow, props.Profit.ToString()); xls.CloseDocumentSave(); } }
public static void SaveQuotes(ObservableCollection <LittleTableViewer> list) { RaBotProgram.Qt.LuaConnect(); try { foreach (LittleTableViewer tableViewer in list) { if (tableViewer.OpenValue > 0) { string code = TradeInstrument.GetIssuerCode(tableViewer.Instrument); Quote quote = RaBotProgram.Qt.GetQuote(code); SetQuote(quote, code); } } } finally { RaBotProgram.Qt.LuaDisconnect(); } }
private static void SaveCurrentDeals() { StreamWriter streamWriter = new StreamWriter (Path.Combine (Application.StartupPath, Config.MiscFolderName, Folder, CurrentDealsFileName), false, Encoding.UTF8); try { foreach (Deal deal in _currentDeals) { streamWriter.WriteLine ("{0};{1};{2};{3};{4};{5};{6}", deal.OpenDate.ToString("dd.MM.yyyy HH:mm:ss"), TradeInstrument.GetIssuerCode(deal.Issuer), deal.OpenValue, deal.DirectionStr, deal.Volume, deal.LastStopValue, deal.LastStopDate.ToString("dd.MM.yyyy HH:mm:ss")); } streamWriter.Flush(); } finally { streamWriter.Close(); } }
public TradeInstrument AddTradeInstrument(TradeInstrument tradeInstrument) { tradeInstrument = _dbContext.TradeInstruments.Add(tradeInstrument); return(tradeInstrument); }