本文整理汇总了C#中StockSharp.Messages.MarketDataMessage类的典型用法代码示例。如果您正苦于以下问题:C# MarketDataMessage类的具体用法?C# MarketDataMessage怎么用?C# MarketDataMessage使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MarketDataMessage类属于StockSharp.Messages命名空间,在下文中一共展示了MarketDataMessage类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UnsubscribeCandles
public void UnsubscribeCandles(CandleSeries series)
{
var tuple = _subscriptionDates.TryGetValue(series.Security.Id);
if(tuple == null)
return;
var msg = new MarketDataMessage().FillSecurityInfo(this, series.Security);
msg.TransactionId = TransactionIdGenerator.GetNextId();
msg.OriginalTransactionId = tuple.Item2;
msg.SecurityId = GetSecurityId(series.Security);
msg.DataType = MarketDataTypes.CandleTimeFrame;
msg.IsSubscribe = false;
msg.From = tuple.Item1;
msg.Arg = series.Arg;
SendInMessage(msg);
UnSubscribeMarketData(series.Security, MarketDataTypes.CandleTimeFrame);
}
示例2: ProcessMarketData
private void ProcessMarketData(MarketDataMessage mdMsg)
{
switch (mdMsg.DataType)
{
case MarketDataTypes.Level1:
{
if (mdMsg.IsSubscribe)
_subscribedLevel1.Add(mdMsg.SecurityId);
else
_subscribedLevel1.Remove(mdMsg.SecurityId);
break;
}
case MarketDataTypes.MarketDepth:
{
if (mdMsg.IsSubscribe)
_subscribedDepths.Add(mdMsg.SecurityId, mdMsg.MaxDepth ?? MarketDataMessage.DefaultMaxDepth);
else
_subscribedDepths.Remove(mdMsg.SecurityId);
break;
}
case MarketDataTypes.Trades:
{
if (mdMsg.IsSubscribe)
_subscribedTicks.Add(mdMsg.SecurityId);
else
_subscribedTicks.Remove(mdMsg.SecurityId);
break;
}
default:
{
SendOutMarketDataNotSupported(mdMsg.TransactionId);
return;
}
}
var reply = (MarketDataMessage)mdMsg.Clone();
reply.OriginalTransactionId = mdMsg.OriginalTransactionId;
SendOutMessage(reply);
}
示例3: SubscribeCandles
public void SubscribeCandles(CandleSeries series)
{
var transId = TransactionIdGenerator.GetNextId();
_subscriptionDates[series.Security.Id] = Tuple.Create(series.From, transId);
var msg = new MarketDataMessage().FillSecurityInfo(this, series.Security);
msg.TransactionId = transId;
msg.SecurityId = GetSecurityId(series.Security);
msg.DataType = MarketDataTypes.CandleTimeFrame;
msg.IsSubscribe = true;
msg.From = series.From;
msg.Arg = (TimeSpan)series.Arg;
_lastCandles.Remove(Tuple.Create(msg.SecurityId, msg.Arg));
SendInMessage(msg);
SubscribeMarketData(series.Security, MarketDataTypes.CandleTimeFrame);
}
示例4: SubscribeCandles
public void SubscribeCandles(CandleSeries series)
{
if (!IsConnected)
{
_subscribersBuffer.Add(series);
return;
}
var key = new SubscriptionKey(series.Security.Id, (TimeSpan) series.Arg);
var transId = TransactionIdGenerator.GetNextId();
var subscription = _candleSubscriptions.TryGetValue(key);
if (subscription != null)
{
Candles?.Invoke(series, subscription.CandleBuilder.AllCandles);
subscription.AddSubscriber(series);
return;
}
subscription = new CandleSubscription(series.Security, series.From, (TimeSpan) series.Arg, transId);
subscription.AddSubscriber(series);
_candleSubscriptions.Add(key, subscription);
subscription.CandleBuilder.Candle += CandleBuilderOnCandle;
var msg = new MarketDataMessage().FillSecurityInfo(this, series.Security);
msg.TransactionId = transId;
msg.SecurityId = GetSecurityId(series.Security);
msg.DataType = MarketDataTypes.CandleTimeFrame;
msg.IsSubscribe = true;
msg.From = series.From;
msg.Arg = series.Arg;
SendInMessage(msg);
SubscribeMarketData(series.Security, MarketDataTypes.CandleTimeFrame);
}
示例5: SubscribeCandles
private void SubscribeCandles(CandleSeries series, DateTimeOffset from, DateTimeOffset to, long transactionId)
{
var mdMsg = new MarketDataMessage
{
DataType = GetCandleType(series.CandleType),
TransactionId = transactionId,
From = from,
To = to,
Arg = series.Arg,
IsSubscribe = true,
}.FillSecurityInfo(this, series.Security);
_candleSeries.Add(transactionId, series);
SendInMessage(mdMsg);
}
示例6: Clone
/// <summary>
/// Create a copy of <see cref="MarketDataMessage"/>.
/// </summary>
/// <returns>Copy.</returns>
public override Message Clone()
{
var clone = new MarketDataMessage
{
Arg = Arg,
DataType = DataType,
Error = Error,
From = From,
To = To,
IsSubscribe = IsSubscribe,
TransactionId = TransactionId,
Count = Count,
MaxDepth = MaxDepth,
NewsId = NewsId,
LocalTime = LocalTime,
IsNotSupported = IsNotSupported
};
CopyTo(clone);
return clone;
}
示例7: SubscribeMarketDepth
/// <summary>
/// Call this method to request market depth for a specific contract. The market depth will be returned by the updateMktDepth() and updateMktDepthL2() methods.
/// </summary>
/// <param name="message">this structure contains a description of the contract for which market depth data is being requested.</param>
private void SubscribeMarketDepth(MarketDataMessage message)
{
if (message == null)
throw new ArgumentNullException("message");
//var security = SessionHolder.Securities[message.SecurityId];
ProcessRequest(RequestMessages.SubscribeMarketDepth, ServerVersions.V6, ServerVersions.V5,
socket => socket
.Send(message.TransactionId)
.SendIf(ServerVersions.V68, s => socket.SendContractId(message.SecurityId))
.SendSecurity(message, false)
.SendIf(ServerVersions.V68, s => socket.Send(message.Class))
.SendIf(ServerVersions.V19, s => socket.Send(message.MaxDepth ?? MarketDataMessage.DefaultMaxDepth))
.SendIf(ServerVersions.V70, s =>
{
//StringBuilder realTimeBarsOptionsStr = new StringBuilder();
//int realTimeBarsOptionsCount = realTimeBarsOptions == null ? 0 : realTimeBarsOptions.size();
//if (realTimeBarsOptionsCount > 0)
//{
// for (int i = 0; i < realTimeBarsOptionsCount; ++i)
// {
// TagValue tagValue = (TagValue)realTimeBarsOptions.get(i);
// realTimeBarsOptionsStr.append(tagValue.m_tag);
// realTimeBarsOptionsStr.append("=");
// realTimeBarsOptionsStr.append(tagValue.m_value);
// realTimeBarsOptionsStr.append(";");
// }
//}
//send(realTimeBarsOptionsStr.toString());
socket.Send(string.Empty);
}));
}
示例8: SubscribeRealTimeCandles
/// <summary>
/// Подписаться на получение свечек реального времени.
/// </summary>
/// <param name="message"></param>
/// <param name="field">Поля маркет-данных, на основе которых будут строяться свечи. Поддерживаются следующие значения:
/// <list type="number">
/// <item>
/// <description><see cref="CandleDataTypes.Trades"/>.</description>
/// </item>
/// <item>
/// <description><see cref="CandleDataTypes.Bid"/>.</description>
/// </item>
/// <item>
/// <description><see cref="CandleDataTypes.Ask"/>.</description>
/// </item>
/// <item>
/// <description><see cref="CandleDataTypes.Midpoint"/>.</description>
/// </item>
/// </list>
/// </param>
/// <param name="useRth">Строить свечи только по торговому времени. По-умолчанию используется торговое время.</param>
private void SubscribeRealTimeCandles(MarketDataMessage message, Level1Fields field = CandleDataTypes.Trades, bool useRth = true)
{
if (message == null)
throw new ArgumentNullException("message");
//var security = SessionHolder.Securities[message.SecurityId];
ProcessRequest(RequestMessages.SubscribeRealTimeCandles, ServerVersions.V34, ServerVersions.V3,
socket =>
socket
.Send(message.TransactionId)
.SendIf(ServerVersions.V68, s => socket.SendContractId(message.SecurityId))
.SendSecurity(message)
.SendIf(ServerVersions.V68, s => socket.Send(message.Class))
.Send(5) // Поддерживается только 5 секундный тайм-фрейм.
.SendLevel1Field(field)
.Send(useRth)
.SendIf(ServerVersions.V70, s =>
{
//StringBuilder realTimeBarsOptionsStr = new StringBuilder();
//int realTimeBarsOptionsCount = realTimeBarsOptions == null ? 0 : realTimeBarsOptions.size();
//if (realTimeBarsOptionsCount > 0)
//{
// for (int i = 0; i < realTimeBarsOptionsCount; ++i)
// {
// TagValue tagValue = (TagValue)realTimeBarsOptions.get(i);
// realTimeBarsOptionsStr.append(tagValue.m_tag);
// realTimeBarsOptionsStr.append("=");
// realTimeBarsOptionsStr.append(tagValue.m_value);
// realTimeBarsOptionsStr.append(";");
// }
//}
//send(realTimeBarsOptionsStr.toString());
socket.Send(string.Empty);
}));
}
示例9: SubscribeMarketData
/// <summary>
/// Call this method to request market data. The market data will be returned by the tickPrice, tickSize, tickOptionComputation(), tickGeneric(), tickString() and tickEFP() methods.
/// </summary>
/// <param name="message">this structure contains a description of the contract for which market data is being requested.</param>
/// <param name="genericFields">comma delimited list of generic tick types. Tick types can be found here: (new Generic Tick Types page) </param>
/// <param name="snapshot">Allows client to request snapshot market data.</param>
/// <param name="marketDataOff">Market Data Off - used in conjunction with RTVolume Generic tick type causes only volume data to be sent.</param>
private void SubscribeMarketData(MarketDataMessage message, IEnumerable<GenericFieldTypes> genericFields, bool snapshot, bool marketDataOff)
{
if (message == null)
throw new ArgumentNullException("message");
//var security = SessionHolder.Securities[message.SecurityId];
ProcessRequest(RequestMessages.SubscribeMarketData, ServerVersions.V47, ServerVersions.V11,
socket =>
{
socket
.Send(message.TransactionId)
.SendContractId(message.SecurityId)
.SendSecurity(message)
.SendIf(ServerVersions.V68, s => socket.Send(message.Class));
if (socket.ServerVersion >= ServerVersions.V8 && message is WeightedIndexSecurity)
{
// TODO
//socket.SendCombo((WeightedIndexSecurity)security);
}
if (socket.ServerVersion >= ServerVersions.V40)
{
//if (contract.UnderlyingComponent != null)
//{
// UnderlyingComponent underComp = contract.UnderlyingComponent;
// send(true);
// send(underComp.ContractId);
// send(underComp.Delta);
// send(underComp.Price);
//}
//else
//{
socket.Send(false);
//}
}
if (socket.ServerVersion >= ServerVersions.V31)
{
/*
* Even though SHORTABLE tick type supported only
* starting server version 33 it would be relatively
* expensive to expose this restriction here.
*
* Therefore we are relying on TWS doing validation.
*/
var genList = new StringBuilder();
genList.Append(genericFields.Select(t => ((int)t).To<string>()).Join(","));
if (marketDataOff)
{
if (genList.Length > 0)
genList.Append(",");
genList.Append("mdoff");
}
socket.Send(genList.ToString());
}
if (socket.ServerVersion >= ServerVersions.V35)
{
socket.Send(snapshot);
}
if (socket.ServerVersion >= ServerVersions.V70)
{
//StringBuilder mktDataOptionsStr = new StringBuilder();
//int mktDataOptionsCount = mktDataOptions == null ? 0 : mktDataOptions.size();
//if( mktDataOptionsCount > 0) {
// for( int i = 0; i < mktDataOptionsCount; ++i) {
// TagValue tagValue = (TagValue)mktDataOptions.get(i);
// mktDataOptionsStr.append( tagValue.m_tag);
// mktDataOptionsStr.append( "=");
// mktDataOptionsStr.append( tagValue.m_value);
// mktDataOptionsStr.append( ";");
// }
//}
//send( mktDataOptionsStr.toString());
socket.Send(string.Empty);
}
});
}
示例10: ProcessMarketData
private void ProcessMarketData(MarketDataMessage mdMsg)
{
var secCode = mdMsg.SecurityId.SecurityCode;
var boardCode = mdMsg.SecurityId.BoardCode;
switch (mdMsg.DataType)
{
case MarketDataTypes.Level1:
{
if (mdMsg.IsSubscribe)
_client.SubscribeQuote(secCode, boardCode);
else
_client.UnsubsribeQuote(secCode, boardCode);
break;
}
case MarketDataTypes.MarketDepth:
{
if (mdMsg.IsSubscribe)
_client.SubscribeLevel2(secCode, boardCode);
else
_client.UnsubsribeLevel2(secCode, boardCode);
break;
}
case MarketDataTypes.Trades:
{
if (mdMsg.IsSubscribe)
{
_subscribedSecuritiesToTrade.Add(secCode);
_client.SubscribeQuote(secCode, boardCode);
}
else
{
_subscribedSecuritiesToTrade.Remove(secCode);
_client.UnsubsribeQuote(secCode, boardCode);
}
break;
}
case MarketDataTypes.News:
{
if (mdMsg.IsSubscribe)
_client.SubscribeNews();
else
_client.UnsubscribeNews();
break;
}
default:
{
SendOutMarketDataNotSupported(mdMsg.TransactionId);
return;
}
}
var reply = (MarketDataMessage)mdMsg.Clone();
reply.OriginalTransactionId = mdMsg.TransactionId;
SendOutMessage(reply);
}
示例11: ProcessMarketData
private void ProcessMarketData(MarketDataMessage mdMsg)
{
switch (mdMsg.DataType)
{
case MarketDataTypes.Level1:
{
//if (mdMsg.IsSubscribe)
// _subscribedLevel1.Add(secCode);
//else
// _subscribedLevel1.Remove(secCode);
break;
}
case MarketDataTypes.MarketDepth:
{
if (mdMsg.IsSubscribe)
{
_subscribedDepths.Add(mdMsg.SecurityId, mdMsg.MaxDepth);
if (_subscribedDepths.Count == 1)
_pusherClient.SubscribeDepths();
}
else
{
_subscribedDepths.Remove(mdMsg.SecurityId);
if (_subscribedDepths.Count == 0)
_pusherClient.UnSubscribeDepths();
}
break;
}
case MarketDataTypes.Trades:
{
if (mdMsg.IsSubscribe)
{
if (mdMsg.From == DateTime.Today)
{
_httpClient.RequestTransactions().Select(t => new ExecutionMessage
{
ExecutionType = ExecutionTypes.Tick,
SecurityId = _btcUsd,
TradeId = t.Id,
TradePrice = (decimal)t.Price,
Volume = (decimal)t.Amount,
ServerTime = t.Time.ApplyTimeZone(TimeZoneInfo.Utc)
}).ForEach(SendOutMessage);
}
_subscribedTicks.Add(mdMsg.SecurityId);
if (_subscribedTicks.Count == 1)
_pusherClient.SubscribeTrades();
}
else
{
_subscribedTicks.Remove(mdMsg.SecurityId);
if (_subscribedTicks.Count == 0)
_pusherClient.UnSubscribeTrades();
}
break;
}
default:
{
SendOutMarketDataNotSupported(mdMsg.TransactionId);
return;
}
}
var reply = (MarketDataMessage)mdMsg.Clone();
reply.OriginalTransactionId = mdMsg.OriginalTransactionId;
SendOutMessage(reply);
}
示例12: ProcessMarketDataMessage
private void ProcessMarketDataMessage(MarketDataMessage mdMsg)
{
var secCode = mdMsg.SecurityId.SecurityCode;
var boardCode = mdMsg.SecurityId.BoardCode;
switch (mdMsg.DataType)
{
case MarketDataTypes.Level1:
{
if (mdMsg.IsSubscribe)
_client.Session.subscribe(boardCode, secCode, SubscriptionFlags.All & ~(SubscriptionFlags.Prints | SubscriptionFlags.PrintsCond | SubscriptionFlags.Quotes), mdMsg.TransactionId);
else
_client.Session.unsubscribe(boardCode, secCode);
break;
}
case MarketDataTypes.MarketDepth:
{
if (mdMsg.IsSubscribe)
{
_client.Session.rebuildBook(boardCode, secCode, mdMsg.TransactionId);
_client.Session.subscribe(boardCode, secCode, SubscriptionFlags.Quotes, mdMsg.TransactionId);
}
else
_client.Session.unsubscribe(boardCode, secCode);
break;
}
case MarketDataTypes.Trades:
{
if (mdMsg.From == null || mdMsg.To == null)
{
if (mdMsg.IsSubscribe)
_client.Session.subscribe(boardCode, secCode, SubscriptionFlags.Prints | SubscriptionFlags.PrintsCond, mdMsg.TransactionId);
else
_client.Session.unsubscribe(boardCode, secCode);
}
else
_client.Session.replayTrades(boardCode, secCode, mdMsg.From.Value.ToSsboe(), mdMsg.To.Value.ToSsboe(), mdMsg.TransactionId);
break;
}
//case MarketDataTypes.OrderLog:
// break;
//case MarketDataTypes.News:
// break;
case MarketDataTypes.CandleTimeFrame:
{
if (mdMsg.From == null || mdMsg.To == null)
{
if (mdMsg.IsSubscribe)
_client.Session.subscribeTimeBar(boardCode, secCode, mdMsg.TransactionId);
else
_client.Session.unsubscribeTimeBar(boardCode, secCode);
}
else
_client.Session.replayTimeBars(boardCode, secCode, mdMsg.From.Value.ToSsboe(), mdMsg.To.Value.ToSsboe(), mdMsg.TransactionId);
break;
}
default:
{
SendOutMarketDataNotSupported(mdMsg.TransactionId);
return;
}
}
var reply = (MarketDataMessage)mdMsg.Clone();
reply.OriginalTransactionId = mdMsg.TransactionId;
SendOutMessage(reply);
}
示例13: RaiseMarketDataMessage
private void RaiseMarketDataMessage(MarketDataMessage message, Exception error)
{
var reply = (MarketDataMessage)message.Clone();
reply.OriginalTransactionId = message.TransactionId;
reply.Error = error;
SendOutMessage(reply);
}
示例14: ProcessMarketDataMessage
private void ProcessMarketDataMessage(MarketDataMessage message)
{
var securityId = message.SecurityId;
var security = SecurityProvider.LookupById(securityId.ToStringId());
if (security == null)
{
RaiseMarketDataMessage(message, new InvalidOperationException(LocalizedStrings.Str704Params.Put(securityId)));
return;
}
if (StorageRegistry == null)
{
RaiseMarketDataMessage(message, new InvalidOperationException(LocalizedStrings.Str1117Params.Put(message.DataType, securityId)));
return;
}
var history = message as HistorySourceMessage;
Exception error = null;
switch (message.DataType)
{
case MarketDataTypes.Level1:
{
if (message.IsSubscribe)
{
if (history == null)
{
BasketStorage.AddStorage(StorageRegistry.GetLevel1MessageStorage(security, Drive, StorageFormat));
BasketStorage.AddStorage(new InMemoryMarketDataStorage<ClearingMessage>(security, null, date => new[]
{
new ClearingMessage
{
LocalTime = date.Date + security.Board.ExpiryTime,
SecurityId = securityId,
ClearMarketDepth = true
}
}));
}
else
{
BasketStorage.AddStorage(new InMemoryMarketDataStorage<Level1ChangeMessage>(security, null, history.GetMessages));
}
}
else
{
BasketStorage.RemoveStorage<IMarketDataStorage<Level1ChangeMessage>>(security, MessageTypes.Level1Change, null);
BasketStorage.RemoveStorage<InMemoryMarketDataStorage<ClearingMessage>>(security, ExtendedMessageTypes.Clearing, null);
}
break;
}
case MarketDataTypes.MarketDepth:
{
if (message.IsSubscribe)
{
if (history == null)
BasketStorage.AddStorage((IMarketDataStorage<QuoteChangeMessage>)StorageRegistry.GetMarketDepthStorage(security, Drive, StorageFormat));
else
BasketStorage.AddStorage(new InMemoryMarketDataStorage<QuoteChangeMessage>(security, null, history.GetMessages));
}
else
BasketStorage.RemoveStorage<IMarketDataStorage<QuoteChangeMessage>>(security, MessageTypes.QuoteChange, null);
break;
}
case MarketDataTypes.Trades:
{
if (message.IsSubscribe)
{
if (history == null)
BasketStorage.AddStorage((IMarketDataStorage<ExecutionMessage>)StorageRegistry.GetTradeStorage(security, Drive, StorageFormat));
else
BasketStorage.AddStorage(new InMemoryMarketDataStorage<ExecutionMessage>(security, null, history.GetMessages));
}
else
BasketStorage.RemoveStorage<IMarketDataStorage<ExecutionMessage>>(security, MessageTypes.Execution, ExecutionTypes.Tick);
break;
}
case MarketDataTypes.OrderLog:
{
if (message.IsSubscribe)
{
if (history == null)
BasketStorage.AddStorage((IMarketDataStorage<ExecutionMessage>)StorageRegistry.GetOrderLogStorage(security, Drive, StorageFormat));
else
BasketStorage.AddStorage(new InMemoryMarketDataStorage<ExecutionMessage>(security, null, history.GetMessages));
}
else
BasketStorage.RemoveStorage<IMarketDataStorage<ExecutionMessage>>(security, MessageTypes.Execution, ExecutionTypes.OrderLog);
break;
}
//.........这里部分代码省略.........
示例15: LookupCandles
public void LookupCandles(MarketDataMessage message)
{
if (message.From == null || message.To == null)
throw new ArgumentException("message");
var placeCode = _adapter.SecurityClassInfo.GetSecurityClass(message.SecurityType, message.SecurityId.BoardCode);
_adapter.AddDebugLog("Candles SC={0} PC={1} TF={2} F={3} T={4}", message.SecurityId.SecurityCode, placeCode, message.Arg, message.From, message.To);
if (placeCode == null)
throw new InvalidOperationException(LocalizedStrings.Str2279);
var timeFrame = (AlfaTimeFrames)(TimeSpan)message.Arg;
//to = timeFrame.GetCandleBounds(series.Security).Min;
var data = _ad.GetArchiveFinInfoFromDB(placeCode, message.SecurityId.SecurityCode, timeFrame.Interval, message.From.Value.ToLocalTime(TimeHelper.Moscow), message.To.Value.ToLocalTime(TimeHelper.Moscow));
if (_ad.LastResult != StateCodes.stcSuccess)
ThrowInError((tagStateCodes)_ad.LastResult);
_adapter.AddDebugLog("Candles DT={0}", data);
DoInSysCulture(() => ProcessCandles.SafeInvoke(message, data.ToRows()));
}