public static string Convert(OpenQuant.API.InstrumentType value) { switch (value) { case OpenQuant.API.InstrumentType.Stock: return "CS"; case OpenQuant.API.InstrumentType.Futures: return "FUT"; case OpenQuant.API.InstrumentType.Option: return "OPT"; case OpenQuant.API.InstrumentType.FutOpt: return "FOP"; case OpenQuant.API.InstrumentType.Bond: return "TBOND"; case OpenQuant.API.InstrumentType.Index: return "IDX"; case OpenQuant.API.InstrumentType.ETF: return "ETF"; case OpenQuant.API.InstrumentType.FX: return "FOR"; case OpenQuant.API.InstrumentType.MultiLeg: return "MLEG"; case OpenQuant.API.InstrumentType.Commodity: return "CMDTY"; default: throw new ArgumentException(string.Format("Unknown InstrumentType - {0}", value)); } }
public override OpenQuant.API.Trade FilterTrade(OpenQuant.API.Trade trade, string symbol) { _trades[symbol] = trade; // 在这之前可以做自己的过滤 Trade t = trade; if (filter != null) { t = filter.FilterTrade(trade, symbol); } if (t != null) { EmitTrade(symbol, Clock.Now, t.Price, t.Size); } else { return null; } Trade t1, t2; if (_trades.TryGetValue("IF1306", out t1) && _trades.TryGetValue("IF1307", out t2)) { EmitTrade("IF1306-IF1307", Clock.Now, t1.Price - t2.Price, 0); EmitTrade("IF1306-IF1307*2", Clock.Now, t1.Price - t2.Price * 2.0, 0); } // 注意,这个地方一定要返回null // 这实际上是让插件内部的Emit不调用 return null; }
public static void Init() { Currency.Converter = new DefaultCurrencyConverter(); foreach (SmartQuant.Instruments.Instrument sq_instrument in SmartQuant.Instruments.InstrumentManager.Instruments) { OpenQuant.AddInstrument(sq_instrument); } SmartQuant.Instruments.InstrumentManager.InstrumentAdded += new InstrumentEventHandler(OpenQuant.SQInstrumentManager_InstrumentAdded); SmartQuant.Instruments.InstrumentManager.InstrumentRemoved += new InstrumentEventHandler(OpenQuant.SQInstrumentManager_InstrumentRemoved); foreach (SmartQuant.Instruments.Portfolio sq_portfolio in PortfolioManager.Portfolios) { OpenQuant.AddPortfolio(sq_portfolio); } PortfolioManager.PortfolioAdded += new PortfolioEventHandler(OpenQuant.SQ_PortfolioManager_PortfolioAdded); OpenQuant.InitOrders(); OrderManager.NewOrder += new OrderEventHandler(OpenQuant.SQ_OrderManager_NewOrder); OrderManager.OrderRemoved += new OrderEventHandler(OpenQuant.SQ_OrderManager_OrderRemoved); OrderManager.OrderListUpdated += new EventHandler(OpenQuant.SQ_OrderManager_OrderListUpdated); }
public void placeOrder(DecisionData data, OpenQuant.API.OrderSide side, double qty, double limit) { double price = data.bar.Close; String msg = "Placing order: side: " + side.ToString() + " amt: " + price.ToString() + " Limit: " + limit.ToString() + " Qty: " + qty.ToString(); System.Console.WriteLine(msg); if(side == OpenQuant.API.OrderSide.Buy) { data.strategy.buyOrder = data.strategy.LimitOrder(OpenQuant.API.OrderSide.Buy, qty, limit); data.strategy.buyOrder.Send(); } else { data.strategy.sellOrder = data.strategy.LimitOrder(OpenQuant.API.OrderSide.Sell, qty, limit); data.strategy.sellOrder.Send(); } }
public override Quote FilterQuote(OpenQuant.API.Quote quote, string symbol) { // 接收所有报价 return quote; }
protected override void HandlePartiallyFilledQuantity(OpenQuant.API.Order order) { LoggingUtility.WriteInfoFormat(this, "ORDER PARTIALLY FILLED: Filled Qty={0}, Avg. Fill Price={1:c}", order.CumQty, order.AvgPrice); RemainingQuantity = Convert.ToInt32(order.LeavesQty); FilledQuantity = Convert.ToInt32(order.CumQty); }
private SpiderBar ConvertBar(OpenQuant.API.Bar originalBar) { SpiderBar spiderBar = new SpiderBar() { IsComplete = originalBar.IsComplete, Open = originalBar.Open, High = originalBar.High, Low = originalBar.Low, Close = originalBar.Close, BeginTime = originalBar.BeginTime, EndTime = originalBar.EndTime, Size = originalBar.Size, Volume = originalBar.Volume }; return spiderBar; }
private SpiderQuote ConvertQuote(OpenQuant.API.Quote originalQuote) { SpiderQuote spiderQuote = new SpiderQuote() { DateTime = originalQuote.DateTime, Ask = originalQuote.Ask, Bid = originalQuote.Bid, AskSize = originalQuote.AskSize, BidSize = originalQuote.BidSize }; return spiderQuote; }
internal void SetUserCommand(OpenQuant.API.UserCommand command) { try { foreach (Strategy strategy in this.strategies.Values) strategy.OnUserCommand(command); } catch (Exception ex) { this.EmitError(ex); } }
public static void Init() { FreeQuant.Instruments.Currency.Converter = new DefaultCurrencyConverter(); foreach (FreeQuant.Instruments.Instrument fq_instrument in FreeQuant.Instruments.InstrumentManager.Instruments) { OpenQuant.AddInstrument(fq_instrument); } FreeQuant.Instruments.InstrumentManager.InstrumentAdded += (e) => { OpenQuant.AddInstrument(e.Instrument); }; FreeQuant.Instruments.InstrumentManager.InstrumentRemoved += (e) => { OpenQuant.RemoveInstrument(e.Instrument); }; foreach (FreeQuant.Instruments.Portfolio sq_portfolio in PortfolioManager.Portfolios) { OpenQuant.AddPortfolio(sq_portfolio); } PortfolioManager.PortfolioAdded += (e) => { OpenQuant.AddPortfolio(e.Portfolio); }; OpenQuant.InitOrders(); OrderManager.NewOrder += (e) => { Order order; if (Map.FQ_OQ_Order.ContainsKey(e.Order)) { order = Map.FQ_OQ_Order[e.Order] as Order; } else { order = new Order(e.Order); Map.OQ_FQ_Order[order] = e.Order; Map.FQ_OQ_Order[e.Order] = order; } OpenQuant.orders.Add(order); }; OrderManager.OrderRemoved += (e) => { Order order = Map.FQ_OQ_Order[e.Order] as Order; OpenQuant.orders.Remove(order); Map.FQ_OQ_Order.Remove(e.Order); Map.OQ_FQ_Order.Remove(order); }; OrderManager.OrderListUpdated += (sender, e) => { OpenQuant.orders.Clear(); Map.OQ_FQ_Order.Clear(); Map.FQ_OQ_Order.Clear(); foreach (SingleOrder order1 in OrderManager.Orders.All) { Order order2 = new Order(order1); OpenQuant.orders.Add(order2); Map.OQ_FQ_Order[order2] = order1; Map.FQ_OQ_Order[order1] = order2; } }; }
private static void SQ_PortfolioManager_PortfolioAdded(PortfolioEventArgs args) { OpenQuant.AddPortfolio(args.Portfolio); }
private static void SQInstrumentManager_InstrumentRemoved(InstrumentEventArgs args) { OpenQuant.RemoveInstrument(args.Instrument); }
private static void SQInstrumentManager_InstrumentAdded(InstrumentEventArgs args) { OpenQuant.AddInstrument(args.Instrument); }
public static PutOrCall Convert(OpenQuant.API.PutCall value) { switch (value) { case OpenQuant.API.PutCall.Put: return (PutOrCall)0; case OpenQuant.API.PutCall.Call: return (PutOrCall)1; default: throw new ArgumentException(string.Format("Unknown PutCall - {0}", value)); } }
public static FreeQuant.FIX.TimeInForce Convert(OpenQuant.API.TimeInForce value) { switch (value) { case OpenQuant.API.TimeInForce.Day: return (FreeQuant.FIX.TimeInForce)1; case OpenQuant.API.TimeInForce.GTC: return (FreeQuant.FIX.TimeInForce)2; case OpenQuant.API.TimeInForce.OPG: return (FreeQuant.FIX.TimeInForce)3; case OpenQuant.API.TimeInForce.IOC: return (FreeQuant.FIX.TimeInForce)4; case OpenQuant.API.TimeInForce.FOK: return (FreeQuant.FIX.TimeInForce)5; case OpenQuant.API.TimeInForce.GTX: return (FreeQuant.FIX.TimeInForce)6; case OpenQuant.API.TimeInForce.GTD: return (FreeQuant.FIX.TimeInForce)7; case OpenQuant.API.TimeInForce.ATC: return (FreeQuant.FIX.TimeInForce)8; case OpenQuant.API.TimeInForce.GFS: return (FreeQuant.FIX.TimeInForce)9; default: throw new ArgumentException(string.Format("Unknown TimeInForce - {0}", value)); } }