public void UpdateSecurityDefinition(SecurityMessage securityDefinition) { if (securityDefinition == null) { throw new ArgumentNullException("securityDefinition"); } _securityDefinition = securityDefinition; _stepsUpdated = true; }
public void UpdateSecurityDefinition(SecurityMessage securityDefinition) { if (securityDefinition == null) { throw new ArgumentNullException("securityDefinition"); } _securityDefinition = securityDefinition; _priceStepUpdated = _securityDefinition.PriceStep != null; _volumeStepUpdated = _securityDefinition.VolumeStep != null; }
private void ProcessSecurityMessage(SecurityMessage message/*, string boardCode = null*/) { var secId = CreateSecurityId(message.SecurityId.SecurityCode, message.SecurityId.BoardCode); var security = GetSecurity(secId, s => { s.ApplyChanges(message, _entityCache.ExchangeInfoProvider); return true; }); if (message.OriginalTransactionId != 0) _lookupResult.Add(security); }
public static IBSocket SendPrimaryExchange(this IBSocket socket, SecurityMessage security) { if (security == null) { throw new ArgumentNullException(nameof(security)); } if (socket.ServerVersion < ServerVersions.V14) { return(socket); } return(socket.SendBoardCode(security.GetRoutingBoard())); }
public void UpdateSecurityDefinition(SecurityMessage securityDefinition) { _securityDefinition = securityDefinition ?? throw new ArgumentNullException(nameof(securityDefinition)); if (_securityDefinition.PriceStep != null) { _priceStepUpdated = true; } if (_securityDefinition.VolumeStep != null) { _volumeStepUpdated = true; } }
private void ReplaceSecurityId(SecurityMessage secMsg) { if (secMsg.NotRequiredSecurityId()) { return; } var stockSharpId = secMsg.SecurityId.SetNativeId(null); var adapterId = Storage.TryGetAdapterId(StorageName, stockSharpId); if (adapterId != null) { this.AddInfoLog("{0}->{1}, {2}", stockSharpId, adapterId.Value, secMsg); secMsg.ReplaceSecurityId(adapterId.Value); } }
public static bool NotRequiredSecurityId(this SecurityMessage secMsg) { if (secMsg == null) { throw new ArgumentNullException(nameof(secMsg)); } if (secMsg.Type == MessageTypes.MarketData && ((MarketDataMessage)secMsg).DataType == MarketDataTypes.News) { return(secMsg.SecurityId.IsDefault()); } else if (secMsg.Type == MessageTypes.OrderGroupCancel) { return(secMsg.SecurityId.IsDefault()); } return(false); }
/// <summary>Коллбэк результата поиска инструментов.</summary> /// <param name="lookupTransId">Номер транзакции операции Lookup.</param> /// <param name="data">Список инструментов, удовлетворяющих условию поиска.</param> /// <param name="ex">Ошибка поиска.</param> private void ClientOnProductLookupResult(long lookupTransId, IEnumerable <ProductInfo> data, Exception ex) { if (ex != null) { SendOutError(new ETradeException(LocalizedStrings.Str3363, ex)); if (lookupTransId > 0) { SendOutMessage(new SecurityLookupResultMessage { OriginalTransactionId = lookupTransId }); } return; } foreach (var info in data.Where(info => info.securityType == "EQ")) { var secId = new SecurityId { SecurityCode = info.symbol, BoardCode = AssociatedBoardCode, }; var msg = new SecurityMessage { SecurityId = secId, Name = info.companyName, ShortName = info.companyName, SecurityType = SecurityTypes.Stock, PriceStep = 0.01m, Currency = CurrencyTypes.USD, }; SendOutMessage(msg); } if (lookupTransId > 0) { SendOutMessage(new SecurityLookupResultMessage { OriginalTransactionId = lookupTransId }); } }
private void ProcessSecurityMessage(SecurityMessage message/*, string boardCode = null*/) { var secId = CreateSecurityId(message.SecurityId.SecurityCode, message.SecurityId.BoardCode); var security = GetSecurity(secId, s => { s.ApplyChanges(message); return true; }); if (message.OriginalTransactionId != 0) _lookupResult.Add(security); if (CreateAssociatedSecurity && !IsAssociated(message.SecurityId.BoardCode)) { var clone = (SecurityMessage)message.Clone(); clone.SecurityId = CreateAssociatedId(clone.SecurityId); ProcessSecurityMessage(clone); } }
private void IBSocket_NewSymbol(int row, int rowCount, long contractId, string name, string secCode, string secClass, int decimals, int lotSize, double stepPrice, double priceStep, string isin, string board, System.DateTime expiryDate, double daysBeforeExpiry, double strike) { if (secCode.IsEmpty()) { secCode = contractId.To <string>(); } var securityId = new SecurityId { SecurityCode = secCode, BoardCode = board, NativeAsInt = contractId, Isin = isin }; if (secClass.IsEmpty()) { secClass = board; } DateTime?expDate = DateTime.FromOADate(0) == expiryDate ? (DateTime?)null : expiryDate; var secMsg = new SecurityMessage { PriceStep = Convert.ToDecimal(priceStep.ToDecimal()), Decimals = decimals, Multiplier = lotSize, Name = name, ShortName = name, ExpiryDate = expDate == null ? (DateTimeOffset?)null : expDate.Value.ApplyTimeZone(TimeHelper.Est), ExtensionInfo = new Dictionary <string, object> { { "Class", secClass } }, OriginalTransactionId = _lookupSecuritiesId }; SendOutMessage(secMsg); }
internal static void SetEvRule(this SecurityMessage security, string evRule) { security.AddValue(_evRule, evRule); }
internal static void SetTradingHours(this SecurityMessage security, string tradingHours) { security.AddValue(_tradingHours, tradingHours); }
internal static void SetLiquidHours(this SecurityMessage security, string liquidHours) { security.AddValue(_liquidHours, liquidHours); }
internal static void SetSubCategory(this SecurityMessage security, string subCategory) { security.AddValue(_subCategory, subCategory); }
internal static void SetTimeZoneId(this SecurityMessage security, string timeZoneId) { security.AddValue(_timeZoneId, timeZoneId); }
private void OnNewSecurity(int row, int rowCount, string smartId, string name, string secCode, string secClass, int decimals, int lotSize, decimal?stepPrice, decimal?priceStep, string isin, string board, DateTime?expiryDate, decimal?daysBeforeExpiry, decimal?strike) { //AMU: заглушка. 11.01.2013 обнаружил, что через SmartCom стали приходить инструменты (класс EQBR и FISS) с пустым secCode - "longName" в понятии АйтиИнвеста if (secCode.IsEmpty()) { secCode = smartId; } var securityId = new SecurityId { SecurityCode = secCode, BoardCode = board, Native = smartId, Isin = isin }; if (secClass.IsEmpty()) { secClass = board; } var secMsg = new SecurityMessage { PriceStep = priceStep, Decimals = decimals, Multiplier = lotSize, Name = name, ShortName = name, ExpiryDate = expiryDate?.ApplyTimeZone(TimeHelper.Moscow), ExtensionInfo = new Dictionary <object, object> { { "Class", secClass } }, OriginalTransactionId = _lookupSecuritiesId }; if (secClass.CompareIgnoreCase("IDX")) { secMsg.SecurityType = SecurityTypes.Index; switch (secMsg.SecurityId.BoardCode) { case "RUSIDX": securityId.BoardCode = secCode.ContainsIgnoreCase("MICEX") || secCode.ContainsIgnoreCase("MCX") ? ExchangeBoard.Micex.Code : ExchangeBoard.Forts.Code; break; //default: // security.Board = ExchangeBoard.Test; // break; } } else { var info = SecurityClassInfo.GetSecurityClassInfo(secClass); secMsg.SecurityType = info.Item1; securityId.BoardCode = info.Item2; // http://stocksharp.com/forum/yaf_postsm16847_Vopros-po-vystavlieniiu-zaiavok.aspx#post16847 if (ExchangeBoard.GetOrCreateBoard(info.Item2).IsMicex && /* проверяем, что не началась ли трансляция правильных дробных шагов */ secMsg.PriceStep != null && secMsg.PriceStep == (int)secMsg.PriceStep) { // http://stocksharp.com/forum/yaf_postsm21245_Sokhranieniie-stakanov-po-GAZP-EQNE.aspx#post21245 secMsg.PriceStep = 1m / 10m.Pow(secMsg.PriceStep.Value); } } secMsg.SecurityId = securityId; if (secMsg.SecurityType == SecurityTypes.Option) { var optionInfo = secMsg.Name.GetOptionInfo(ExchangeBoard.Forts); if (optionInfo != null) { // http://stocksharp.com/forum/yaf_postst1355_Exception-Change-Set-11052.aspx if (!secCode.IsEmpty()) { var futureInfo = optionInfo.UnderlyingSecurityId.GetFutureInfo(secCode, ExchangeBoard.Forts); if (futureInfo != null) { secMsg.UnderlyingSecurityCode = futureInfo.SecurityId.SecurityCode; } } secMsg.ExpiryDate = optionInfo.ExpiryDate; secMsg.OptionType = optionInfo.OptionType; secMsg.Strike = optionInfo.Strike; } } SendOutMessage(secMsg); if (stepPrice != null) { SendOutMessage( new Level1ChangeMessage { SecurityId = securityId, ServerTime = CurrentTime.Convert(TimeHelper.Moscow), } .TryAdd(Level1Fields.StepPrice, stepPrice.Value)); } if ((row + 1) < rowCount) { return; } SendOutMessage(new SecurityLookupResultMessage { OriginalTransactionId = _lookupSecuritiesId }); _lookupSecuritiesId = 0; }
/// <summary> /// /// </summary> /// <param name="securities"></param> /// <param name="code"></param> /// <param name="type"></param> /// <param name="board"></param> /// <param name="secMsg"></param> /// <param name="onlyLocal"></param> public static void TryFindLocal(this IDictionary <Tuple <string, SecurityTypes>, SecurityMessage> securities, string code, SecurityTypes type, string board, SecurityMessage secMsg, bool onlyLocal = false) { if (_ignoreCodes.Contains(code)) { return; } var secProvider = ServicesRegistry.TrySecurityProvider; if (secProvider != null) { var found = (board.IsEmpty() ? null : new[] { secProvider.LookupById(new SecurityId { SecurityCode = code, BoardCode = board }) }.Where(f1 => f1 != null)) ?? secProvider.LookupByCode(code, type).Where(s => s.ToSecurityId().SecurityCode.CompareIgnoreCase(code)) ?? secProvider.Lookup(new SecurityLookupMessage { ShortName = code, SecurityType = type }) ?? secProvider.Lookup(new SecurityLookupMessage { Name = code, SecurityType = type }); if (type == SecurityTypes.Stock) { found = found.OrderBy(f2 => { var id = f2.Id.ToSecurityId(); if (id.BoardCode.EndsWithIgnoreCase("EMU")) { return(100); } if (id.BoardCode.StartsWithIgnoreCase("TQ")) { return(0); } return(50); }); } var f = found.FirstOrDefault(); if (f != null) { f.ToMessage().CopyTo(secMsg); return; } } if (!onlyLocal) { securities.TryAdd(Tuple.Create(code.ToUpperInvariant(), type), secMsg); } }
internal static void SetEvMultiplier(this SecurityMessage security, decimal evMultiplier) { security.AddValue(_evMultiplier, evMultiplier); }
/// <summary> /// Download securities info. /// </summary> /// <param name="securities">Securities.</param> public static void DownloadInfo(this IDictionary <Tuple <string, SecurityTypes>, SecurityMessage> securities) { if (securities.Count == 0) { return; } void MostAppropriated(IEnumerable <SecurityMessage> messages, Tuple <string, SecurityTypes> key, SecurityMessage destination) { SecurityMessage found = null; if (messages != null) { messages = messages.Where(s => { var name = key.Item1; return(s.SecurityId.SecurityCode.CompareIgnoreCase(name) || s.ShortName.CompareIgnoreCase(name) || s.Name.CompareIgnoreCase(name)); }); switch (key.Item2) { case SecurityTypes.Future: found = messages.OrderByDescending(m => m.ExpiryDate).FirstOrDefault(); break; case SecurityTypes.Stock: found = messages.OrderBy(m => m.SecurityId.BoardCode.StartsWithIgnoreCase("TQ") ? 0 : 1).FirstOrDefault(); break; } } if (found == null) { System.Diagnostics.Debug.WriteLine("{0}={1}", key.Item1, key.Item2); } else { var native = destination.SecurityId.Native; found.CopyTo(destination); destination.SetNativeId(native); } } var client = new InstrumentProviderClient(); if (securities.Count <= 10) { foreach (var pair in securities) { var name = pair.Key.Item1; var type = pair.Key.Item2; var found = client.LookupSecurities(new SecurityLookupMessage { SecurityId = new SecurityId { SecurityCode = name }, SecurityType = type, }); if (found.Count == 0) { found = client.LookupSecurities(new SecurityLookupMessage { SecurityType = type, ShortName = name }); if (found.Count == 0) { found = client.LookupSecurities(new SecurityLookupMessage { SecurityType = type, Name = name }); } } MostAppropriated(found, pair.Key, pair.Value); } } else { var byCode = new Dictionary <Tuple <string, SecurityTypes?>, List <SecurityMessage> >(); var byShortName = new Dictionary <Tuple <string, SecurityTypes?>, List <SecurityMessage> >(); var byName = new Dictionary <Tuple <string, SecurityTypes?>, List <SecurityMessage> >(); foreach (var message in client.LookupSecurities(Extensions.LookupAllCriteriaMessage)) { var secType = message.SecurityType; byCode.SafeAdd(Tuple.Create(message.SecurityId.SecurityCode.ToUpperInvariant(), secType)).Add(message); if (!message.ShortName.IsEmpty()) { byShortName.SafeAdd(Tuple.Create(message.ShortName.ToUpperInvariant(), secType)).Add(message); } if (!message.Name.IsEmpty()) { byName.SafeAdd(Tuple.Create(message.Name.ToUpperInvariant(), secType)).Add(message); } } List <SecurityMessage> TryFind(Dictionary <Tuple <string, SecurityTypes?>, List <SecurityMessage> > dict, Tuple <string, SecurityTypes> key) { return (dict.TryGetValue(Tuple.Create(key.Item1, (SecurityTypes?)key.Item2)) ?? dict.TryGetValue(Tuple.Create(key.Item1, (SecurityTypes?)null))); } foreach (var pair in securities) { var found = TryFind(byCode, pair.Key) ?? TryFind(byShortName, pair.Key) ?? TryFind(byName, pair.Key); MostAppropriated(found, pair.Key, pair.Value); } } }
internal static void SetValidExchanges(this SecurityMessage security, string validExchanges) { security.AddValue(_validExchanges, validExchanges); }
internal static void SetOrderTypes(this SecurityMessage security, string orderTypes) { security.AddValue(_orderTypes, orderTypes); }
internal static void SetMarketName(this SecurityMessage security, string marketName) { security.AddValue(_marketName, marketName); }
internal static void SetRoutingBoard(this SecurityMessage security, string exchange) { security.AddValue(_routingExchange, exchange); }
internal static string GetRoutingBoard(this SecurityMessage security) { return(security.GetValue <string>(_routingExchange)); }
internal static void SetMarketValue(this SecurityMessage position, decimal marketValue) { position.AddValue(_marketValue, marketValue); }
internal static void SetContractMonth(this SecurityMessage security, string contractMonth) { security.AddValue(_contractMonth, contractMonth); }
internal static void SetIndustry(this SecurityMessage security, string industry) { security.AddValue(_industry, industry); }
internal static void SetCategory(this SecurityMessage security, string category) { security.AddValue(_category, category); }
internal static void SetPriceMagnifier(this SecurityMessage security, decimal priceMagnifier) { security.AddValue(_priceMagnifier, priceMagnifier); }
private void OnProcessSecurities(long transactionId, string[] data) { var f = Wrapper.FieldsSecurities; var secMessages = new List <Tuple <int, SecurityMessage> >(); var level1Messages = new List <Level1ChangeMessage>(); foreach (var row in data) { var cols = row.ToColumns(); var secType = f.ATCode.GetValue(cols); if (secType == null) { continue; } var paperNo = f.PaperNo.GetValue(cols); var code = f.PaperCode.GetValue(cols); var name = f.AnsiName.GetValue(cols); var time = f.ILastUpdate.GetValue(cols); _securityCodes[paperNo] = code; var secId = new SecurityId { Native = paperNo, SecurityCode = code, BoardCode = this.GetBoardCode(f.PlaceCode.GetValue(cols)) }; var msg = new SecurityMessage { SecurityId = secId, Name = name, ShortName = name, SecurityType = secType, Multiplier = f.LotSize.GetValue(cols), PriceStep = f.PriceStep.GetValue(cols), //LocalTime = time, Currency = f.CurrCode.GetValue(cols), Strike = f.Strike.GetValue(cols) }; if (msg.SecurityType == SecurityTypes.Option || msg.SecurityType == SecurityTypes.Future) { msg.ExpiryDate = f.MatDate.GetValue(cols).ApplyTimeZone(TimeHelper.Moscow); } if (msg.SecurityType == SecurityTypes.Option) { msg.OptionType = f.ATCode.GetStrValue(cols).ATCodeToOptionType(); msg.Strike = f.Strike.GetValue(cols); } secMessages.Add(Tuple.Create(f.BasePaperNo.GetValue(cols), msg)); var l1Msg = new Level1ChangeMessage { SecurityId = secId, ServerTime = time.ApplyTimeZone(TimeHelper.Moscow) }; l1Msg.TryAdd(Level1Fields.MarginBuy, f.GoBuy.GetValue(cols)); l1Msg.TryAdd(Level1Fields.MarginSell, f.GoSell.GetValue(cols)); l1Msg.TryAdd(Level1Fields.StepPrice, f.PriceStepCost.GetValue(cols)); level1Messages.Add(l1Msg); } secMessages.Where(t => t.Item2.SecurityType == SecurityTypes.Option).ForEach(t => t.Item2.UnderlyingSecurityCode = _securityCodes.TryGetValue(t.Item1)); secMessages.ForEach(t => SendOutMessage(t.Item2)); level1Messages.ForEach(SendOutMessage); if (transactionId > 0) { SendOutMessage(new SecurityLookupResultMessage { OriginalTransactionId = transactionId, }); } }