public SweepUnit_OE( POrder goalOrder, Account accountFO, Account accountSpot, OptionTribe ot, ISweeper parent, Boolean bConservativeOptionPolicyOn, int muteSec) { ID = SweepUnitIDManager.NextID++; _parent = parent; GoalOrder = goalOrder; RealOrders = new List<POrder>(); _ot = ot; _mute = new Timer(muteSec, ""); // 2초 _candidateCodes = ElwOptionUtil.GetSameCandidateCodes(goalOrder.Code); _accountSpot = accountSpot; _accountFO = accountFO; _bConservativeOptionPolicyOn = bConservativeOptionPolicyOn; if (!RequestInitOrder()) { GoalOrder.Free(); } _State = State._1_MuteFewSecs; ShowState(); }
ElwArbSweepUnit EnterPosition_Raw( ElwInfo elwInfo, String elwCode, TradingDirection elwLS, long elwEnterCount, double elwPrice, RawMarketData rmdElw, TradingDirection optionLS, long optionEnterCount, double optionPrice, RawMarketData rmdOption) { POrder optionOrder = null; POrder elwOrder = null; try { { // ELW Long // 우선 ELW Long을 진행하도록 한다. Detail.ProductType pt = ProductUtil.Ins().GetProductType(elwCode); if (pt != Detail.ProductType.ELW) { logger.Error( "CRITICAL ERROR!!! 엄청 무서운 일이 벌어졌다. ELW가 아닌 {0} 종목이 {1} 가격에 {2} 개 사려고 했다.", elwCode, elwPrice, elwEnterCount); Util.KillWithNotice("error"); _bFinish = true; return null; } else { // ELW 롱 elwOrder = new POrder(elwLS, elwCode, elwEnterCount, elwPrice, _elwAccount, rmdElw); elwOrder.AddComment("EAE.EnterPosition_Raw.elwOrder"); elwOrder.Free(); if (!POrderLegalManager.Ins().IsLegalOrder(elwOrder, false)) { return null; } } } { // 옵션 숏 // 그럴리 없겠지만 무서우니까 최종적으로 확인을 한번 더 해보자. Detail.ProductType pt = ProductUtil.Ins().GetProductType(_KospiOptionInfo.Code); if (pt != Detail.ProductType.CallOption && pt != Detail.ProductType.PutOption) { logger.Error( "CRITICAL ERROR!!! 엄청 무서운 일이 벌어졌다. 옵션도 아닌 {0} 종목이 {1} 가격에 {2} 개 사려고 했다.", _KospiOptionInfo.Code, optionPrice, optionEnterCount); Util.KillWithNotice("CRITICAL ERROR!!!"); _bFinish = true; return null; } else { optionOrder = new POrder(optionLS, _KospiOptionInfo.Code, optionEnterCount, optionPrice, _optionAccount, rmdOption); optionOrder.AddComment("EAE.EnterPosition_Raw.optionOrder"); optionOrder.Free(); if (!POrderLegalManager.Ins().IsLegalOrder(optionOrder, false)) { return null; } } } if (optionOrder != null && elwOrder != null) { ElwArbSweepUnit eos = new ElwArbSweepUnit( _KospiOptionInfo, elwInfo, _optionAccount, optionOrder, _elwAccount, elwOrder, _parent, MonitoringEndDate); return eos; } else { logger.Error("Unexpected"); Util.KillWithNotice("Unexpected"); } } catch (System.Exception ex) { logger.Error(ex.ToString()); Util.KillWithNotice(ex.ToString()); } return null; }
public ElwArbSweepUnit( KospiOptionInfo koi, ElwInfo elwInfo, Account optionAccount, POrder optionOrder, Account elwAccount, POrder elwOrder, STR_ElwArb parent, DateTime dtEnd) { try { KOI = koi; CurID = ++ID_GENERATOR; OptionAccount = optionAccount; OptionOrderGoal = optionOrder; OptionOrderGoal.AddComment("EOS Constructor"); ElwAccount = elwAccount; ElwOrderGoal = elwOrder; ElwOrderGoal.AddComment("EOS Constructor"); _elwInfo = elwInfo; OptionOrdersReal = new List<POrder>(); ElwOrdersReal = new List<POrder>(); _state = State._1_MuteFewSecs; Key = String.Format("{0};{1}", OptionOrderGoal.Code, ElwOrderGoal.Code); ShowState(); _mute = new Timer(ENTER_POSITION_MUTE, ""); RequestInitOrder(ElwOrderGoal, ElwOrdersReal); _parent = parent; _parent.IncreaseEnteredArbCount(KOI.Code, OptionOrderGoal.ReqCount); _dtEnd = dtEnd; IsBodySweepQuickly = false; } catch (System.Exception ex) { logger.Error(ex.ToString()); Util.KillWithNotice(ex.ToString()); } finally { ElwAccount.DiffFastExactPossibleShortCount(ElwOrderGoal.Code, "ElwOptionSweeper 생성자"); OptionOrderGoal.Free(); optionOrder.Free(); ElwOrderGoal.Free(); elwOrder.Free(); } }
public void SyncWithMaxCompletePercent(double maxCompletePercent) { if (_State != State._1_MuteFewSecsForInitOrders) { return; } Trace.Assert(maxCompletePercent >= 0 && maxCompletePercent <= 100); double diffPercent = maxCompletePercent - GetPercent_AttemptOfTarget(); if (diffPercent <= 0) { // 이미 max complete percent보다 많이 시도한 상태이다. return; } long attempCount = POrderUtil.GetSignedMaxPossibleExposureCount(this.RealOrders); Trace.Assert(attempCount * this.CurSignedTargetCount >= 0); long newEnterAttemptCount = (long)((maxCompletePercent * this.CurSignedTargetCount) / 100) - attempCount; if (newEnterAttemptCount == 0) { return; } Trace.Assert(newEnterAttemptCount * this.CurSignedTargetCount >= 0); // newEnterAttempCount만큼 매매를 한다. if (this.RealOrders.Count >= 4) { // 4개 이상 내는 것은 이상하다. logger.Warn(String.Format("RealOrders.Count >= 4")); return; } LongShortCount lsc = new LongShortCount(newEnterAttemptCount); RawMarketData rmdClone = RmdManager.Ins().GetDataClone(this.Code); POrder o = new POrder(lsc.LongShort, this.Code, (long)lsc.Count, this.InitEnterPrice, this.AccountFO, rmdClone); o.AddComment("SweepUnit_FO.SyncWithMaxCompletePErcent"); if (o.ReqCount > 0) { RequestOrder_Raw(o, RealOrders); } else { o.Free(); } }
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; }
public void SyncWithTargetOptionExposure(long targetOptionExposure) { try { if (_State != State._1_MuteFewSecs) { return; } double multipliedTargetOptionExposure = Math.Abs(targetOptionExposure) * _multiplier; double exposure = GetPossibleOptionExposure(); double remainTargetOption = multipliedTargetOptionExposure - exposure; long remainTargetOptionCount = (long)remainTargetOption; logger.Info( "[key({3}) SyncWithTOE] {0:n} + {1:n} = {2:n}", multipliedTargetOptionExposure, exposure, remainTargetOption, ID); if ((remainTargetOption > 0 && GoalOrder.LongShort == TradingDirection.Long) || (remainTargetOption < 0 && GoalOrder.LongShort == TradingDirection.Short)) { long reqCount = ElwOptionUtil.ConvertFOCountToReal(GoalOrder.Code, Math.Abs(remainTargetOptionCount)); if (reqCount > GoalOrder.ReqCount) { logger.Error("ReqCount({0:n}) > GoalCount({1:n})", reqCount, GoalOrder.ReqCount); Util.KillWithNotice("ReqCount > GoalCount"); return; } if (RealOrders.Count >= 4) { // 4개 이상 내는 것은 이상하다. logger.Warn(String.Format("RealOrders.Count >= 4")); return; } POrder o = new POrder( GoalOrder.LongShort, GoalOrder.Code, reqCount, GoalOrder.ReqPrice, GoalOrder.TargetAccount, GoalOrder.RMDClone); o.AddComment("SweepUnit_OE.SyncWithTargetOptionExposure"); if (o.ReqCount > 0) { RequestOrder_Raw(o, RealOrders); } else { o.Free(); } } } catch (System.Exception ex) { logger.Error(ex.ToString()); Util.KillWithNotice(ex.ToString()); } }