本文整理汇总了C#中StockSharp.Messages.ExecutionMessage.ToTrade方法的典型用法代码示例。如果您正苦于以下问题:C# ExecutionMessage.ToTrade方法的具体用法?C# ExecutionMessage.ToTrade怎么用?C# ExecutionMessage.ToTrade使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StockSharp.Messages.ExecutionMessage
的用法示例。
在下文中一共展示了ExecutionMessage.ToTrade方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ProcessTradeMessage
public Tuple<Trade, bool> ProcessTradeMessage(Security security, ExecutionMessage message)
{
if (security == null)
throw new ArgumentNullException(nameof(security));
if (message == null)
throw new ArgumentNullException(nameof(message));
var trade = GetTrade(security, message.TradeId, message.TradeStringId, (id, stringId) =>
{
var t = message.ToTrade(EntityFactory.CreateTrade(security, id, stringId));
t.LocalTime = message.LocalTime;
t.Time = message.ServerTime;
message.CopyExtensionInfo(t);
return t;
});
return trade;
}
示例2: ProcessMyTradeMessage
public Tuple<MyTrade, bool> ProcessMyTradeMessage(Security security, ExecutionMessage message)
{
if (security == null)
throw new ArgumentNullException(nameof(security));
if (message == null)
throw new ArgumentNullException(nameof(message));
var originalTransactionId = _orderStatusTransactions.Contains(message.OriginalTransactionId)
? 0 : message.OriginalTransactionId;
if (originalTransactionId == 0 && message.OrderId == null && message.OrderStringId.IsEmpty())
throw new ArgumentOutOfRangeException(nameof(message), originalTransactionId, LocalizedStrings.Str715);
var securityData = GetData(security);
var myTrade = securityData.MyTrades.TryGetValue(Tuple.Create(originalTransactionId, message.TradeId ?? 0));
if (myTrade != null)
return Tuple.Create(myTrade, false);
var order = GetOrder(security, originalTransactionId, message.OrderId, message.OrderStringId);
if (order == null)
return null;
var trade = message.ToTrade(EntityFactory.CreateTrade(security, message.TradeId, message.TradeStringId));
var isNew = false;
myTrade = securityData.MyTrades.SafeAdd(Tuple.Create(order.TransactionId, trade.Id), key =>
{
isNew = true;
var t = EntityFactory.CreateMyTrade(order, trade);
if (t.ExtensionInfo == null)
t.ExtensionInfo = new Dictionary<object, object>();
if (message.Commission != null)
t.Commission = message.Commission;
if (message.Slippage != null)
t.Slippage = message.Slippage;
message.CopyExtensionInfo(t);
//trades.Add(t);
_myTrades.Add(t);
return t;
});
return Tuple.Create(myTrade, isNew);
// mika
// http://stocksharp.com/forum/yaf_postst1072_Probliemy-so-sdielkami--pozitsiiami.aspx
// из-за того, что сделки по заявке иногда приходит быстрее события NewOrders, неправильно расчитывается поза по стратегиям
//var raiseOrderChanged = false;
//trades.SyncDo(d =>
//{
// var newBalance = order.Volume - d.Sum(t => t.Trade.Volume);
// if (order.Balance > newBalance)
// {
// raiseOrderChanged = true;
// order.Balance = newBalance;
// if (order.Balance == 0)
// order.State = OrderStates.Done;
// }
//});
//if (raiseOrderChanged)
// RaiseOrderChanged(order);
}