void RequestInitOrder(POrder goalOrder, List<POrder> realOrders) { POrder o = new POrder(goalOrder); o.AddComment(String.Format("EOS#({0}), GoalOrder", CurID)); o.SetAsLegalPrice(); o.ConvertOverPriceToInRMDPriceIfNotZero(); POrderUtil.RequestOrder(o, realOrders); }
public void TestPOrderLegalData() { string code = "201EC260"; RawMarketData rmd = new RawMarketData(code, Detail.ProductType.CallOption); rmd.BidPrice1 = 0.81000001F; rmd.BidCount1 = 1000; rmd.AskPrice1 = 0.81999999F; rmd.AskCount1 = 1000; Account simAccount = AccountManager.Ins().CreateSimFOAccount(); POrder o0 = new POrder(TradingDirection.Long, code, 1, 0.81, simAccount, rmd); POrderLegalManager.Ins().Add(o0); { POrder o2 = new POrder(TradingDirection.Long, code, 1, 0.81, simAccount, rmd); Boolean success = POrderLegalManager.Ins().Remove(o2); Assert.AreEqual(success, false); } { POrder o = new POrder(TradingDirection.Short, code, 1, 0.8099998, simAccount, rmd); POrder_Accessor oAccessor = new POrder_Accessor(o); oAccessor.ReqPrice = 0.810006; Boolean legal = POrderLegalManager.Ins().IsLegalOrder(o, false); Assert.AreEqual(legal, false); o.SetAsLegalPrice(); legal = POrderLegalManager.Ins().IsLegalOrder(o, false); Assert.AreEqual(legal, true); Util.LogOutCriticalError("\t\t # Non exist code search 1 permitted."); Boolean success = POrderLegalManager.Ins().Remove(o); Assert.AreEqual(success, false); POrderLegalManager.Ins().Add(o); POrder o2 = new POrder(TradingDirection.Short, code, 1, 0.8099998, simAccount, rmd); success = POrderLegalManager.Ins().Remove(o2); Assert.AreEqual(success, false); // test reverse { POrder o3 = new POrder(TradingDirection.Long, code, 1, 0.83, simAccount, rmd); POrder_Accessor oAccessor3 = new POrder_Accessor(o3); oAccessor3.ReqPrice = 0.83; legal = POrderLegalManager.Ins().IsLegalOrder(o3, false); Assert.AreEqual(legal, false); POrderLegalManager.Ins().Remove(o3); } POrderLegalManager.Ins().Remove(o2); POrderLegalManager.Ins().Remove(o); } POrderLegalManager.Ins().Remove(o0); }
void ReqOrderStepBehindPart(POrder goal, List<POrder> real, double targetExposurePercent, RawMarketData rmd) { double curExposurePercent = GetCurExposurePercent(goal, real); double diffExposure = targetExposurePercent - curExposurePercent; if (diffExposure <= 0) { return; } long goalCount = POrderUtil.GetSignedReqCount(goal); long reqCount = (long)(Math.Round(diffExposure * goalCount / 100, 0)); long curCount = POrderUtil.GetSignedMaxPossibleExposureCount(real); if (Math.Abs(goalCount) < Math.Abs(reqCount + curCount)) { //reqCount = goalCount - curCount; logger.Error("({0}, {1}, {2})", reqCount, goalCount, curCount); Util.KillWithNotice("error"); return; } if (reqCount != 0) { reqCount = Math.Abs(reqCount); if (goal.TargetAccount.LineType == Account.OrderLineType.StockSpotLine) { reqCount = ElwUtil.RoundElwCount(reqCount); } POrder o = new POrder( goal.LongShort, goal.Code, reqCount, goal.ReqPrice, goal.TargetAccount, rmd); o.AddComment(String.Format("EOS#({0}), StepBehindPart, {1}", CurID, o.Code)); o.SetAsLegalPrice(); o.ConvertOverPriceToInRMDPriceIfNotZero(); POrderUtil.RequestOrder(o, real); } }
public Boolean RequestOrder(POrder order) { try { order.SetAsLegalPrice(); if (!IsValidPT(order)) { return false; } if (!IsValidOrder(order)) { logger.Error("It is not valid order"); logger.Error(order.ToString()); Util.KillWithNotice(order.ToString()); return false; } order.RoundReqPrice(); if (AccountManager.Ins().IsSingleShotWeaponMode) { if (AccountManager.Ins().IsBulletEmpty()) { SoundManager.Ins().PlayAlertSound(); DialogResult dr = MessageBox.Show(null, order.ToString(), "SingleWeaponMode, Do you want reload bullets?", MessageBoxButtons.YesNoCancel); if (dr == DialogResult.Yes) { AccountManager.Ins().ReloadBullet(); } else { logger.Error("Cancel Order(Single Weapon Mode)"); Util.KillWithNotice("Cancel Order(Single Weapon Mode)"); return false; } } AccountManager.Ins().DecreaseBullet(); } if (this.Hts.SendOrder(order)) { //// 주문을 한다. _requestOrders.Add(order); POrderLegalManager.Ins().Add(order); POrderBidAskCountManager.Ins().Register(order); logger.Debug("Request: {0}", order.ToString()); order.IsAllocatedYetRequestOrFree = false; return true; } logger.Error("Fail order"); Util.KillWithNotice("Fail order"); return false; } catch (System.Exception ex) { logger.Error(ex.ToString()); Util.KillWithNotice(ex.ToString()); } return false; }
public static Boolean RequestOrder(POrder order, List<POrder> container) { try { order.SetAsLegalPrice(); Boolean bSuccess = true; bSuccess = order.TargetAccount.RequestOrder(order); if (!bSuccess) { logger.Error(order.ToString()); Util.KillWithNotice(order.ToString()); SoundManager.Ins().PlayExceptionSound(); } else { if (container != null) { // 성공했으면 담는다. container.Add(order); } } return bSuccess; } catch (System.Exception ex) { logger.Error(ex.ToString()); Util.KillWithNotice(ex.ToString()); } return false; }
// 주문을 하고 정해놓은 컨테이너에 담는 역할을 수행한다. void RequestOrder_Raw(POrder order, List<POrder> container) { try { order.SetAsLegalPrice(); order.ConvertOverPriceToInRMDPriceIfNotZero(); Boolean bSuccess = true; if (order.TargetAccount.LineType == Account.OrderLineType.StockSpotLine) { Trace.Assert(false); } else if (order.TargetAccount.LineType == Account.OrderLineType.FutureOptionSpreadLine) { bSuccess = order.TargetAccount.RequestOrder(order); } else { logger.Error("{0} unsupported ProductType", order.TargetAccount.LineType); Util.KillWithNotice("unsupported ProductType"); Trace.Assert(false); } if (!bSuccess) { logger.Error(order.ToString()); Util.KillWithNotice(order.ToString()); _State = State._0_Exception; SoundManager.Ins().PlayExceptionSound(); ShowState(); } else { // 성공했으면 담는다. container.Add(order); } } catch (System.Exception ex) { logger.Error(ex.ToString()); Util.KillWithNotice(ex.ToString()); } }
Boolean MakeOrder_Raw(RawMarketData rmd, long remainCount100k, Dictionary<String, long> blocksLB, ref List<POrder> newOrders, ref String log) { if (remainCount100k == 0) { log += "remainCount100k == 0"; return true; } long signedRealCount = ElwOptionUtil.Convert100KToRealCount(rmd.Code, remainCount100k); if (signedRealCount == 0 || remainCount100k - ElwOptionUtil.ConvertRealToCount100k(rmd.Code, signedRealCount) != 0) { log += String.Format("signRealCount({0}) remainCount100k({1}) code({2})|", signedRealCount, remainCount100k, rmd.Code); return false; } long reqCount = Math.Abs(signedRealCount); TradingDirection ls = TradingDirection.Long; if (signedRealCount < 0) { ls = TradingDirection.Short; if (!blocksLB.ContainsKey(rmd.Code)) { log += String.Format("[22], {0}|", rmd.Code); return false; } if (blocksLB[rmd.Code] < Math.Abs(signedRealCount)) { log += String.Format("[23] BlockLB[{2}]({0}) < signedRealCount({1})", blocksLB[rmd.Code], signedRealCount, rmd.Code); return false; } reqCount = Math.Abs(signedRealCount); long tmp = ProductUtil.Ins().RoundProductCount(Math.Abs(reqCount), rmd.DPT); if (tmp != reqCount) { logger.Error("tmp({0}) != reqCount({1}) in MakeOrder_Raw", tmp, reqCount); Util.KillWithNotice("tmp != reqCount in MakeOrder_Raw"); } } Account account = _accountFO; if (rmd.DPT == Detail.ProductType.ELW || rmd.DPT == Detail.ProductType.Stock) { account = _accountSpot; } double price = ProductUtil.Ins().GetMidPrice(rmd); price = AdjustPrice(ls, rmd, price); POrder o = new POrder(ls, rmd.Code, reqCount, price, account, rmd); o.AddComment("SweepUnit_OE.MakeOrder_Raw"); log += String.Format("[23], {0}|", o.ToString()); if (o.ReqCount > 0) { // 여기서 Reserve하고 법적 문제가 있는지 확인한다. o.SetAsLegalPrice(); o.ConvertOverPriceToInRMDPriceIfNotZero(); log += String.Format("[24], {0}|", o.ToString()); newOrders.Add(o); } else { o.Free(); log += String.Format("[24], ReqCount <= 0"); return false; } long ret = remainCount100k - ElwOptionUtil.ConvertRealToCount100k(rmd.Code, signedRealCount); if (ret != 0) { logger.Error( "CRITICAL ERROR!!! in MakeOrder_Raw ret != 0 ret({0}), remainCount100k({1}), signedRealCount({2}), Code({3})", ret, remainCount100k, signedRealCount, rmd.Code); Util.KillWithNotice("CRITICAL ERROR!!! in MakeOrder_Raw"); return false; } return true; }
void RequestOrder_Raw(POrder order, List<POrder> container) { try { order.SetAsLegalPrice(); order.ConvertOverPriceToInRMDPriceIfNotZero(); Boolean bSuccess = true; bSuccess = order.TargetAccount.RequestOrder(order); if (!bSuccess) { logger.Error("{0} order error", order.ToString()); Util.KillWithNotice("order error"); _State = State._0_Exception; SoundManager.Ins().PlayExceptionSound(); ShowState(); } else { // 성공했으면 담는다. container.Add(order); } } catch (System.Exception ex) { logger.Error(ex.ToString()); Util.KillWithNotice(ex.ToString()); } }