static void Main(string[] args) { //create order book OrderBook orderBook = new OrderBook(); //create position book PositionBook posBook = new PositionBook(); //assign reference to respective books orderBook.PBook = posBook; posBook.OBook = orderBook; //create order Order order = new Order(); //update order book ThreadPool.QueueUserWorkItem(new WaitCallback(orderBook.Add), order); //update position service ThreadPool.QueueUserWorkItem(new WaitCallback(posBook.UpdateOrder), order); Console.ReadLine(); }
public override void OptionPositionQuery(QueryPara param, List <PositionBook> positionbook) { try { if (!islogon()) { return; } #region packer CT2Packer packer = new CT2Packer(2); packer.BeginPack(); packer.AddField("user_token", Convert.ToSByte('S'), 512, 4); packer.AddField("account_code", Convert.ToSByte('S'), 32, 4); packer.AddField("combi_no", Convert.ToSByte('S'), 8, 4); packer.AddField("stock_code", Convert.ToSByte('S'), 16, 4); packer.AddStr(this.token); packer.AddStr(param.fundcode); packer.AddStr(param.portfolio); packer.AddStr(param.securitycode); packer.EndPack(); #endregion int retcode = this.sendpacker(OptionFunction.PositionQuery, packer, false); #region unpacker CT2UnPacker unpacker = getCallbackData(retcode); if (unpacker != null) { //更新持仓 positionbook.Clear(); while (unpacker.IsEOF() == 0) { PositionBook pbook = new PositionBook(); pbook.code = unpacker.GetStr("stock_code"); int pflag = unpacker.GetInt("position_flag"); if (pflag == 1) { pbook.positiondirection = PostionDerection.LONG; } else { pbook.positiondirection = PostionDerection.SHORT; } pbook.volume = unpacker.GetInt("enable_amount"); //可能存在volume<=0的bug,所以筛选出为正的 if (pbook.volume > 0) { positionbook.Add(pbook); } unpacker.Next(); } } else { MessageManager.GetInstance().Add(MessageType.Error, string.Format("持仓查询失败:{0}", param.securitycode)); } #endregion } catch (Exception ex) { throw ex; } }