Esempio n. 1
0
        public static double GetAvgPrice(FakePOrder o1, FakePOrder o2)
        {
            double value = (o1.AvgContractPrice * o1.ContractedCount) + (o2.AvgContractPrice * o2.ContractedCount);
            long count = o1.ContractedCount + o2.ContractedCount;

            return value / count;
        }
Esempio n. 2
0
        public void GetFakeSignedContractedCountTest()
        {
            String elwCode = GetFirstElwCode(100);
            ElwInfo ei = ElwUtil.GetElwInfo(elwCode);
            long elwCountOfOneOption = ElwOptionUtil.GetElwCountOfOneOption(elwCode);
            Account simAccountElw = AccountManager.Ins().CreateSimSpotAccount();
            RawMarketData rmdElw = RmdManager.Ins().GetData(elwCode);
            double elwPrice = 10;
            long elwCount = 3000;
            SetAsValidValue(rmdElw, TradingDirection.Long, elwPrice);

            Account simAccountFO = AccountManager.Ins().CreateSimFOAccount();
            String optionCode = ElwOptionUtil.ToOptionCode(elwCode);
            KospiOptionInfo koi = OptionUtil.GetKOI(optionCode);
            Detail.ProductType pt = OptionUtil.ConvertToDetailProductType(koi.CallPut);
            RawMarketData rmdOption = RmdManager.Ins().GetData(optionCode);
            double optionPrice = 0.1;
            SetAsValidValue(rmdOption, TradingDirection.Short, optionPrice);

            {
                POrder elwOrder = new POrder(TradingDirection.Long, elwCode, elwCount, elwPrice, simAccountElw, rmdElw);
                Assert.AreEqual(elwOrder.IsInputValidated, true);
                List<FakePOrder> arr = new List<FakePOrder>();

                {
                    FakePOrder fElwOrder = new FakePOrder(elwOrder);
                    arr.Add(fElwOrder);

                    long expected = 0;
                    long actual;
                    actual = ElwOptionUtil.GetFakeSignedContractedCount(arr);
                    Assert.AreEqual(expected, actual);

                    arr.Remove(fElwOrder);
                }

                elwOrder.Update(elwOrder.ReqCount, elwPrice, true);

                {
                    FakePOrder fElwOrder = new FakePOrder(elwOrder);
                    arr.Add(fElwOrder);

                    long expected = 3000;
                    long actual;
                    actual = ElwOptionUtil.GetFakeSignedContractedCount(arr);
                    Assert.AreEqual(expected, actual);

                    arr.Remove(fElwOrder);
                }
            }

            {
                POrder elwOrder = new POrder(TradingDirection.Short, elwCode, elwCount, elwPrice, simAccountElw, rmdElw);
                Assert.AreEqual(elwOrder.IsInputValidated, true);
                List<FakePOrder> arr = new List<FakePOrder>();

                {
                    FakePOrder fElwOrder = new FakePOrder(elwOrder);
                    arr.Add(fElwOrder);

                    long expected = 0;
                    long actual;
                    actual = ElwOptionUtil.GetFakeSignedContractedCount(arr);
                    Assert.AreEqual(expected, actual);

                    arr.Remove(fElwOrder);
                }

                elwOrder.Update(elwOrder.ReqCount, elwPrice, true);

                {
                    FakePOrder fElwOrder = new FakePOrder(elwOrder);
                    arr.Add(fElwOrder);

                    long expected = -3000;
                    long actual;
                    actual = ElwOptionUtil.GetFakeSignedContractedCount(arr);
                    Assert.AreEqual(expected, actual);

                    arr.Remove(fElwOrder);
                }
            }
        }
Esempio n. 3
0
        public static FakePOrder MergeFakePOrders(FakePOrder o1, FakePOrder o2)
        {
            double avgPrice = GetAvgPrice(o1, o2);

            List<FakePOrder> arr = new List<FakePOrder>();
            arr.Add(o1);
            arr.Add(o2);

            long signedContractedCount = ElwOptionUtil.GetFakeSignedContractedCount(arr);
            long unsignedContractedCount = Math.Abs(signedContractedCount);

            TradingDirection ls = TradingDirection.Long;

            if (signedContractedCount > 0)
            {
            }
            else if (signedContractedCount < 0)
            {
                ls = TradingDirection.Short;
            }
            else
            {
                return null;
            }

            RawMarketData rmd = RmdManager.Ins().GetData(o1.Code);

            FakePOrder o = new FakePOrder(
                ls,
                o1.Code,
                unsignedContractedCount,
                unsignedContractedCount,
                0,
                o1.OrderNumber,
                avgPrice,
                o1.AccountName,
                rmd);

            return o;
        }