本文整理汇总了C#中Security.GetLastData方法的典型用法代码示例。如果您正苦于以下问题:C# Security.GetLastData方法的具体用法?C# Security.GetLastData怎么用?C# Security.GetLastData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Security
的用法示例。
在下文中一共展示了Security.GetLastData方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LimitFill
/// <summary>
/// Analyse the market price of the security provided to see if the limit order has been filled.
/// </summary>
/// <param name="security">Asset we're working with</param>
/// <param name="order">Limit order in market</param>
/// <returns>OrderEvent packet with the full or partial fill information</returns>
/// <seealso cref="OrderEvent"/>
/// <seealso cref="Order"/>
public virtual OrderEvent LimitFill(Security security, Order order)
{
//Initialise;
var fill = new OrderEvent(order);
try
{
//If its cancelled don't need anymore checks:
if (order.Status == OrderStatus.Canceled) return fill;
//Depending on the resolution, return different data types:
var marketData = security.GetLastData();
decimal marketDataMinPrice = 0;
decimal marketDataMaxPrice = 0;
if (marketData.DataType == MarketDataType.TradeBar)
{
marketDataMinPrice = ((TradeBar)marketData).Low;
marketDataMaxPrice = ((TradeBar)marketData).High;
}
else
{
marketDataMinPrice = marketData.Value;
marketDataMaxPrice = marketData.Value;
}
//-> Valid Live/Model Order:
if (order.Direction == OrderDirection.Buy)
{
//Buy limit seeks lowest price
if (marketDataMinPrice < order.Price)
{
order.Status = OrderStatus.Filled;
}
}
else if (order.Direction == OrderDirection.Sell)
{
//Sell limit seeks highest price possible
if (marketDataMaxPrice > order.Price)
{
order.Status = OrderStatus.Filled;
}
}
//Fill price
if (order.Status == OrderStatus.Filled || order.Status == OrderStatus.PartiallyFilled)
{
fill.FillQuantity = order.Quantity;
fill.FillPrice = order.Price;
fill.Status = order.Status;
}
}
catch (Exception err)
{
Log.Error("Forex.ForexTransactionModel.LimitFill(): " + err.Message);
}
return fill;
}
示例2: LimitFill
/// <summary>
/// Check if the price MarketDataed to our limit price yet:
/// </summary>
/// <param name="security">Asset we're working with</param>
/// <param name="order">Limit order in market</param>
/// <returns>OrderEvent packet with the full or partial fill information</returns>
public virtual OrderEvent LimitFill(Security security, Order order)
{
//Initialise;
var fill = new OrderEvent(order);
try {
//If its cancelled don't need anymore checks:
if (fill.Status == OrderStatus.Canceled) return fill;
//Calculate the model slippage: e.g. 0.01c
var slip = GetSlippageApproximation(security, order);
//Depending on the resolution, return different data types:
var marketData = security.GetLastData();
decimal marketDataMinPrice = 0;
decimal marketDataMaxPrice = 0;
if (marketData.DataType == MarketDataType.TradeBar)
{
marketDataMinPrice = ((TradeBar)marketData).Low;
marketDataMaxPrice = ((TradeBar)marketData).High;
}
else
{
marketDataMinPrice = marketData.Value;
marketDataMaxPrice = marketData.Value;
}
//-> Valid Live/Model Order:
switch (order.Direction)
{
case OrderDirection.Buy:
//Buy limit seeks lowest price
if (marketDataMinPrice < order.Price)
{
order.Status = OrderStatus.Filled;
order.Price = Math.Round(security.Price, 3);
order.Price += slip;
}
break;
case OrderDirection.Sell:
//Sell limit seeks highest price possible
if (marketDataMaxPrice > order.Price)
{
order.Status = OrderStatus.Filled;
order.Price = Math.Round(security.Price, 3);
order.Price -= slip;
}
break;
}
//Set fill:
if (order.Status == OrderStatus.Filled || order.Status == OrderStatus.PartiallyFilled)
{
//Assuming 100% fill in models:
fill.FillQuantity = order.Quantity;
fill.FillPrice = order.Price;
fill.Status = order.Status;
}
}
catch (Exception err)
{
Log.Error("Equity.EquityTransactionModel.LimitFill(): " + err.Message);
}
return fill;
}
示例3: GetSlippageApproximation
/// <summary>
/// Get the slippage approximation for this order
/// </summary>
/// <returns>Decimal value of the slippage approximation</returns>
/// <seealso cref="Order"/>
public virtual decimal GetSlippageApproximation(Security security, Order order)
{
//Return 0 by default
decimal slippage = 0;
//For FOREX, the slippage is the Bid/Ask Spread for Tick, and an approximation for the
switch (security.Resolution)
{
case Resolution.Minute:
case Resolution.Second:
//Get the last data packet:
var lastBar = (TradeBar) security.GetLastData();
//Assume slippage is 1/10,000th of the price
slippage = lastBar.Value*0.0001m;
break;
case Resolution.Tick:
var lastTick = (Tick) security.GetLastData();
switch (order.Direction)
{
case OrderDirection.Buy:
//We're buying, assume slip to Asking Price.
slippage = Math.Abs(order.Price - lastTick.AskPrice);
break;
case OrderDirection.Sell:
//We're selling, assume slip to the bid price.
slippage = Math.Abs(order.Price - lastTick.BidPrice);
break;
}
break;
}
return slippage;
}