本文整理汇总了C#中QuantConnect.Orders.LimitOrder类的典型用法代码示例。如果您正苦于以下问题:C# LimitOrder类的具体用法?C# LimitOrder怎么用?C# LimitOrder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
LimitOrder类属于QuantConnect.Orders命名空间,在下文中一共展示了LimitOrder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ClientCancelsLimitOrder
public void ClientCancelsLimitOrder()
{
var orderedResetEvent = new ManualResetEvent(false);
var canceledResetEvent = new ManualResetEvent(false);
var ib = _interactiveBrokersBrokerage;
ib.OrderStatusChanged += (sender, orderEvent) =>
{
if (orderEvent.Status == OrderStatus.Submitted)
{
orderedResetEvent.Set();
}
if (orderEvent.Status == OrderStatus.Canceled)
{
canceledResetEvent.Set();
}
};
// try to sell a single share at a ridiculous price, we'll cancel this later
var order = new LimitOrder(Symbol, -buyQuantity, 100000, DateTime.UtcNow, null, Type);
_orders.Add(order);
ib.PlaceOrder(order);
orderedResetEvent.WaitOneAssertFail(2500, "Limit order failed to be submitted.");
Thread.Sleep(500);
ib.CancelOrder(order);
canceledResetEvent.WaitOneAssertFail(2500, "Canceled event did not fire.");
var openOrders = ib.GetOpenOrders();
var cancelledOrder = openOrders.FirstOrDefault(x => x.BrokerId.Contains(order.BrokerId[0]));
Assert.IsNull(cancelledOrder);
}
示例2: PerformsLimitFillSell
public void PerformsLimitFillSell()
{
var model = new SecurityTransactionModel();
var order = new LimitOrder(Symbol, -100, 101.5m, Noon, type: SecurityType.Equity);
var config = CreateTradeBarConfig(Symbol);
var security = new Security(SecurityExchangeHoursTests.CreateUsEquitySecurityExchangeHours(), config, 1);
security.SetMarketPrice(Noon, new IndicatorDataPoint(Symbol, Noon, 101m));
var fill = model.LimitFill(security, order);
Assert.AreEqual(0, fill.FillQuantity);
Assert.AreEqual(0, fill.FillPrice);
Assert.AreEqual(OrderStatus.None, fill.Status);
Assert.AreEqual(OrderStatus.None, order.Status);
security.SetMarketPrice(Noon, new TradeBar(Noon, Symbol, 102m, 103m, 101m, 102.3m, 100));
fill = model.LimitFill(security, order);
// this fills worst case scenario, so it's at the limit price
Assert.AreEqual(order.Quantity, fill.FillQuantity);
Assert.AreEqual(Math.Max(order.LimitPrice, security.Low), fill.FillPrice);
Assert.AreEqual(OrderStatus.Filled, fill.Status);
Assert.AreEqual(OrderStatus.Filled, order.Status);
}
示例3: PerformsLimitFillSell
public void PerformsLimitFillSell()
{
var model = new ForexTransactionModel();
var order = new LimitOrder(Symbol, -100, 101.5m, DateTime.Now, type: SecurityType.Forex);
var config = CreateTradeBarDataConfig(SecurityType.Forex, Symbol);
var security = new Security(SecurityExchangeHours.AlwaysOpen, config, 1);
security.SetLocalTimeKeeper(TimeKeeper.GetLocalTimeKeeper(TimeZones.NewYork));
security.SetMarketPrice(new IndicatorDataPoint(Symbol, DateTime.Now, 101m));
var fill = model.LimitFill(security, order);
Assert.AreEqual(0, fill.FillQuantity);
Assert.AreEqual(0, fill.FillPrice);
Assert.AreEqual(OrderStatus.None, fill.Status);
Assert.AreEqual(OrderStatus.None, order.Status);
security.SetMarketPrice(new TradeBar(DateTime.Now, Symbol, 102m, 103m, 101m, 102.3m, 100));
fill = model.LimitFill(security, order);
// this fills worst case scenario, so it's at the limit price
Assert.AreEqual(order.Quantity, fill.FillQuantity);
Assert.AreEqual(Math.Max(order.LimitPrice, security.Low), fill.FillPrice);
Assert.AreEqual(OrderStatus.Filled, fill.Status);
Assert.AreEqual(OrderStatus.Filled, order.Status);
}
示例4: PerformsLimitFillSell
public void PerformsLimitFillSell()
{
var model = new SecurityTransactionModel();
var order = new LimitOrder(Symbol, -100, 101.5m, DateTime.Now, type: SecurityType.Equity);
var config = new SubscriptionDataConfig(typeof(TradeBar), SecurityType.Equity, Symbol, Resolution.Minute, true, true, true, true, false, 0);
var security = new Security(config, 1);
security.SetMarketPrice(DateTime.Now, new IndicatorDataPoint(Symbol, DateTime.Now, 101m));
var fill = model.LimitFill(security, order);
Assert.AreEqual(0, fill.FillQuantity);
Assert.AreEqual(0, fill.FillPrice);
Assert.AreEqual(OrderStatus.None, fill.Status);
Assert.AreEqual(OrderStatus.None, order.Status);
security.SetMarketPrice(DateTime.Now, new TradeBar(DateTime.Now, Symbol, 102m, 103m, 101m, 102.3m, 100));
fill = model.LimitFill(security, order);
// this fills worst case scenario, so it's at the limit price
Assert.AreEqual(order.Quantity, fill.FillQuantity);
Assert.AreEqual(Math.Max(order.LimitPrice, security.Low), fill.FillPrice);
Assert.AreEqual(OrderStatus.Filled, fill.Status);
Assert.AreEqual(OrderStatus.Filled, order.Status);
}
示例5: ConvertOrder
/// <summary>
/// Converts an FXCM order to a QuantConnect order.
/// </summary>
/// <param name="fxcmOrder">The FXCM order</param>
private Order ConvertOrder(ExecutionReport fxcmOrder)
{
Order order;
if (fxcmOrder.getOrdType() == OrdTypeFactory.LIMIT)
{
order = new LimitOrder
{
LimitPrice = Convert.ToDecimal(fxcmOrder.getPrice())
};
}
else if (fxcmOrder.getOrdType() == OrdTypeFactory.MARKET)
{
order = new MarketOrder();
}
else if (fxcmOrder.getOrdType() == OrdTypeFactory.STOP)
{
order = new StopMarketOrder
{
StopPrice = Convert.ToDecimal(fxcmOrder.getPrice())
};
}
else
{
throw new NotSupportedException("FxcmBrokerage.ConvertOrder(): The FXCM order type " + fxcmOrder.getOrdType() + " is not supported.");
}
var securityType = _symbolMapper.GetBrokerageSecurityType(fxcmOrder.getInstrument().getSymbol());
order.Symbol = _symbolMapper.GetLeanSymbol(fxcmOrder.getInstrument().getSymbol(), securityType, Market.FXCM);
order.Quantity = Convert.ToInt32(fxcmOrder.getOrderQty() * (fxcmOrder.getSide() == SideFactory.BUY ? +1 : -1));
order.Status = ConvertOrderStatus(fxcmOrder.getFXCMOrdStatus());
order.BrokerId.Add(fxcmOrder.getOrderID());
order.Duration = ConvertDuration(fxcmOrder.getTimeInForce());
order.Time = FromJavaDate(fxcmOrder.getTransactTime().toDate());
return order;
}
示例6: PerformsLimitFillBuy
public void PerformsLimitFillBuy()
{
var model = new ForexTransactionModel();
var security = CreateSecurity();
var order = new LimitOrder(Symbols.USDJPY, 100, 101.5m, DateTime.Now, type: SecurityType.Forex);
security.SetLocalTimeKeeper(TimeKeeper.GetLocalTimeKeeper(TimeZones.NewYork));
security.SetMarketPrice(new IndicatorDataPoint(Symbols.USDJPY, DateTime.Now, 102m));
var fill = model.LimitFill(security, order);
Assert.AreEqual(0, fill.FillQuantity);
Assert.AreEqual(0, fill.FillPrice);
Assert.AreEqual(OrderStatus.None, fill.Status);
security.SetMarketPrice(new TradeBar(DateTime.Now, Symbols.USDJPY, 102m, 103m, 101m, 102.3m, 100));
fill = model.LimitFill(security, order);
// this fills worst case scenario, so it's at the limit price
Assert.AreEqual(order.Quantity, fill.FillQuantity);
Assert.AreEqual(Math.Min(order.LimitPrice, security.High), fill.FillPrice);
Assert.AreEqual(OrderStatus.Filled, fill.Status);
}
示例7: PerformsLimitFillBuy
public void PerformsLimitFillBuy()
{
var model = new SecurityTransactionModel();
var order = new LimitOrder(Symbols.SPY, 100, 101.5m, Noon);
var config = CreateTradeBarConfig(Symbols.SPY);
var security = new Security(SecurityExchangeHoursTests.CreateUsEquitySecurityExchangeHours(), config, new Cash(CashBook.AccountCurrency, 0, 1m), SymbolProperties.GetDefault(CashBook.AccountCurrency));
security.SetLocalTimeKeeper(TimeKeeper.GetLocalTimeKeeper(TimeZones.NewYork));
security.SetMarketPrice(new IndicatorDataPoint(Symbols.SPY, Noon, 102m));
var fill = model.LimitFill(security, order);
Assert.AreEqual(0, fill.FillQuantity);
Assert.AreEqual(0, fill.FillPrice);
Assert.AreEqual(OrderStatus.None, fill.Status);
security.SetMarketPrice(new TradeBar(Noon, Symbols.SPY, 102m, 103m, 101m, 102.3m, 100));
fill = model.LimitFill(security, order);
// this fills worst case scenario, so it's at the limit price
Assert.AreEqual(order.Quantity, fill.FillQuantity);
Assert.AreEqual(Math.Min(order.LimitPrice, security.High), fill.FillPrice);
Assert.AreEqual(OrderStatus.Filled, fill.Status);
}
示例8: CreateOrder
/// <summary>
/// Creates an order of the correct type
/// </summary>
private static Order CreateOrder(OrderType orderType, JObject jObject)
{
Order order;
switch (orderType)
{
case OrderType.Market:
order = new MarketOrder();
break;
case OrderType.Limit:
order = new LimitOrder {LimitPrice = jObject["LimitPrice"].Value<decimal>()};
break;
case OrderType.StopMarket:
order = new StopMarketOrder
{
StopPrice = jObject["StopPrice"].Value<decimal>()
};
break;
case OrderType.StopLimit:
order = new StopLimitOrder
{
LimitPrice = jObject["LimitPrice"].Value<decimal>(),
StopPrice = jObject["StopPrice"].Value<decimal>()
};
break;
case OrderType.MarketOnOpen:
order = new MarketOnOpenOrder();
break;
case OrderType.MarketOnClose:
order = new MarketOnCloseOrder();
break;
default:
throw new ArgumentOutOfRangeException();
}
return order;
}
示例9: ValidateLimitOrders
public void ValidateLimitOrders()
{
var oanda = (OandaBrokerage)Brokerage;
var symbol = Symbol;
var quotes = oanda.GetRates(new List<string> { new OandaSymbolMapper().GetBrokerageSymbol(symbol) });
// Buy Limit order below market
var limitPrice = Convert.ToDecimal(quotes[0].bid - 0.5);
var order = new LimitOrder(symbol, 1, limitPrice, DateTime.Now);
Assert.IsTrue(oanda.PlaceOrder(order));
// update Buy Limit order with no changes
Assert.IsTrue(oanda.UpdateOrder(order));
// move Buy Limit order above market
order.LimitPrice = Convert.ToDecimal(quotes[0].ask + 0.5);
Assert.IsTrue(oanda.UpdateOrder(order));
}
示例10: LimitOrder
/// <summary>
/// Send a limit order to the transaction handler:
/// </summary>
/// <param name="symbol">String symbol for the asset</param>
/// <param name="quantity">Quantity of shares for limit order</param>
/// <param name="limitPrice">Limit price to fill this order</param>
/// <param name="tag">String tag for the order (optional)</param>
/// <returns>Order id</returns>
public int LimitOrder(string symbol, int quantity, decimal limitPrice, string tag = "")
{
var error = PreOrderChecks(symbol, quantity, OrderType.Limit);
if (error < 0)
{
return error;
}
var order = new LimitOrder(symbol, quantity, limitPrice, Time, tag, Securities[symbol].Type);
//Add the order and create a new order Id.
return Transactions.AddOrder(order);
}
示例11: Clone
/// <summary>
/// Creates a deep-copy clone of this order
/// </summary>
/// <returns>A copy of this order</returns>
public override Order Clone()
{
var order = new LimitOrder {LimitPrice = LimitPrice};
CopyTo(order);
return order;
}
示例12: GetOpenOrders
public void GetOpenOrders()
{
var ib = _interactiveBrokersBrokerage;
var orderEventFired = new ManualResetEvent(false);
ib.OrderStatusChanged += (sender, args) =>
{
if (args.Status == OrderStatus.Submitted)
{
orderEventFired.Set();
}
};
var order = new LimitOrder(Symbols.USDJPY, buyQuantity, 0.01m, DateTime.UtcNow);
_orders.Add(order);
ib.PlaceOrder(order);
orderEventFired.WaitOne(1500);
Thread.Sleep(250);
var openOrders = ib.GetOpenOrders();
Assert.AreNotEqual(0, openOrders.Count);
}
示例13: ClientUpdatesLimitOrder
public void ClientUpdatesLimitOrder()
{
int id = 0;
var ib = _interactiveBrokersBrokerage;
bool filled = false;
ib.OrderStatusChanged += (sender, args) =>
{
if (args.Status == OrderStatus.Filled)
{
filled = true;
}
};
const decimal limitPrice = 10000m;
var order = new LimitOrder(Symbols.USDJPY, -buyQuantity, limitPrice, DateTime.UtcNow) {Id = ++id};
_orders.Add(order);
ib.PlaceOrder(order);
var stopwatch = Stopwatch.StartNew();
while (!filled && stopwatch.Elapsed.TotalSeconds < 10)
{
//Thread.MemoryBarrier();
Thread.Sleep(1000);
order.LimitPrice = order.LimitPrice/2;
ib.UpdateOrder(order);
}
Assert.IsTrue(filled);
}
示例14: ClientPlacesLimitOrder
public void ClientPlacesLimitOrder()
{
bool orderFilled = false;
var manualResetEvent = new ManualResetEvent(false);
var ib = _interactiveBrokersBrokerage;
decimal price = 100m;
decimal delta = 85.0m; // if we can't get a price then make the delta huge
ib.OrderStatusChanged += (sender, orderEvent) =>
{
if (orderEvent.Status == OrderStatus.Filled)
{
orderFilled = true;
manualResetEvent.Set();
}
price = orderEvent.FillPrice;
delta = 0.02m;
};
// get the current market price, couldn't get RequestMarketData to fire tick events
int id = 0;
Order order = new MarketOrder(Symbols.USDJPY, buyQuantity, DateTime.UtcNow) { Id = ++id };
_orders.Add(order);
ib.PlaceOrder(order);
manualResetEvent.WaitOne(2000);
manualResetEvent.Reset();
// make a box around the current price +- a little
order = new LimitOrder(Symbols.USDJPY, buyQuantity, price - delta, DateTime.UtcNow, null) { Id = ++id };
_orders.Add(order);
ib.PlaceOrder(order);
order = new LimitOrder(Symbols.USDJPY, -buyQuantity, price + delta, DateTime.UtcNow, null) { Id = ++id };
_orders.Add(order);
ib.PlaceOrder(order);
manualResetEvent.WaitOne(1000);
var orderFromIB = AssertOrderOpened(orderFilled, ib, order);
Assert.AreEqual(OrderType.Limit, orderFromIB.Type);
}
示例15: LimitFill
/// <summary>
/// Default limit order fill model in the base security class.
/// </summary>
/// <param name="asset">Security asset we're filling</param>
/// <param name="order">Order packet to model</param>
/// <returns>Order fill information detailing the average price and quantity filled.</returns>
/// <seealso cref="StopMarketFill(Security, StopMarketOrder)"/>
/// <seealso cref="MarketFill(Security, MarketOrder)"/>
public virtual OrderEvent LimitFill(Security asset, LimitOrder order)
{
//Initialise;
var utcTime = asset.LocalTime.ConvertToUtc(asset.Exchange.TimeZone);
var orderFee = GetOrderFee(asset, order);
var fill = new OrderEvent(order, utcTime, orderFee);
try
{
//If its cancelled don't need anymore checks:
if (order.Status == OrderStatus.Canceled) return fill;
//Get the range of prices in the last bar:
decimal minimumPrice;
decimal maximumPrice;
DataMinMaxPrices(asset, out minimumPrice, out maximumPrice);
//-> Valid Live/Model Order:
switch (order.Direction)
{
case OrderDirection.Buy:
//Buy limit seeks lowest price
if (minimumPrice < order.LimitPrice)
{
//Set order fill:
fill.Status = OrderStatus.Filled;
// fill at the worse price this bar or the limit price, this allows far out of the money limits
// to be executed properly
fill.FillPrice = Math.Min(maximumPrice, order.LimitPrice);
}
break;
case OrderDirection.Sell:
//Sell limit seeks highest price possible
if (maximumPrice > order.LimitPrice)
{
fill.Status = OrderStatus.Filled;
// fill at the worse price this bar or the limit price, this allows far out of the money limits
// to be executed properly
fill.FillPrice = Math.Max(minimumPrice, order.LimitPrice);
}
break;
}
// assume the order completely filled
if (fill.Status == OrderStatus.Filled) fill.FillQuantity = order.Quantity;
}
catch (Exception err)
{
Log.Error("SecurityTransactionModel.LimitFill(): " + err.Message);
}
return fill;
}