Esempio n. 1
0
        private static async void MarketUnpairedSierraOrder(InstrumentConversion instrumentConversion, SierraOrder sierraOrder, OAOrder oaOrder)
        {
            SierraOrderFacade sierraChartOrderFacade = new SierraOrderFacade();

            OAOrder oaMarketOrder = new OAOrder();

            oaMarketOrder.Instrument = instrumentConversion.OandaInstrumentName;
            oaMarketOrder.Units      = sierraOrder.BuySell == BSE_BUY ? sierraOrder.OrderQuantity : -sierraOrder.OrderQuantity;
            oaMarketOrder.Id         = await SvpOandaV20.Instance.CreateMarketOrder(InstrumentConversion.SierraChartAccountId, oaMarketOrder.Instrument, oaMarketOrder.Units);

            SierraOrderEntity sierraChartOrderEntity = new SierraOrderEntity();

            sierraChartOrderEntity.SierraOrderId        = sierraOrder.InternalOrderID;
            sierraChartOrderEntity.OandaOrderId         = oaMarketOrder.Id;
            sierraChartOrderEntity.SierraInstrumentName = instrumentConversion.SierraInstrumentName;
            sierraChartOrderEntity.SierraPrice          = sierraOrder.AvgFillPrice;
            sierraChartOrderFacade.Save(sierraChartOrderEntity);

            oaOrder.Id         = oaMarketOrder.Id;
            oaOrder.Units      = oaMarketOrder.Units;
            oaOrder.Instrument = instrumentConversion.OandaInstrumentName;
        }
Esempio n. 2
0
        private static async void ModifyOandaOrder(InstrumentConversion instrumentConversion, long marketOrderId, SierraOrder sierraOrder, double sierraOrderSLPrice, double sierraOrderPTPrice)
        {
            try
            {
                if (sierraOrder == null)
                {
                    Log.WriteMessage("ModifyOandaOrder(), sierraOrder == null");
                }
                SierraOrderFacade sierraChartOrderFacade = new SierraOrderFacade();
                SierraOrderEntity sierraOrderEntity      = sierraChartOrderFacade.LoadByColumn(SierraOrderFacade.GetPropertyName <SierraOrderEntity>(x => x.SierraOrderId), sierraOrder.InternalOrderID);
                if (sierraOrderEntity == null)
                {
                    Log.WriteMessage("ModifyOandaOrder(), sierraOrderEntity == null");
                }

                if (sierraOrderEntity.SierraPT != sierraOrderPTPrice || sierraOrderEntity.SierraSL != sierraOrderSLPrice)
                {
                    if (sierraOrderEntity.OandaPrice == 0)
                    {
                        //sierraOrderEntity.OandaPrice = await SvpOandaV20.Instance.GetActualPrice(InstrumentConversion.SierraChartAccountId, instrumentConversion.OandaInstrumentName);
                        Trade trade = await SvpOandaV20.Instance.GetMarketOrder(InstrumentConversion.SierraChartAccountId, marketOrderId);

                        sierraOrderEntity.OandaPrice = trade.price;
                    }

                    double compensation = (sierraOrder.BuySell == BSE_BUY ? -instrumentConversion.Compensation : instrumentConversion.Compensation);

                    OAOrder newOAMarketOrder = new OAOrder();
                    newOAMarketOrder.Id         = sierraOrderEntity.OandaOrderId;
                    newOAMarketOrder.Instrument = instrumentConversion.OandaInstrumentName;
                    double sl;
                    if (sierraOrderSLPrice != 0)
                    {
                        sl = sierraOrder.AvgFillPrice - sierraOrderSLPrice;
                    }
                    else
                    {
                        sl = instrumentConversion.SL;
                    }
                    newOAMarketOrder.SL = sierraOrderEntity.OandaPrice - /*(sierraOrder.BuySell == BSE_BUY ? sl : -sl)*/ sl + compensation;

                    double pt;
                    if (sierraOrderPTPrice != 0)
                    {
                        pt = sierraOrderPTPrice - sierraOrder.AvgFillPrice;
                        newOAMarketOrder.PT = sierraOrderEntity.OandaPrice + /*(sierraOrder.BuySell == BSE_BUY ? pt : -pt)*/ pt + compensation;
                    }

                    await SvpOandaV20.Instance.ModifyMarketOrder(InstrumentConversion.SierraChartAccountId, newOAMarketOrder);

                    sierraOrderEntity.SierraPT = sierraOrderPTPrice;
                    sierraOrderEntity.SierraSL = sierraOrderSLPrice;
                    sierraChartOrderFacade.Save(sierraOrderEntity);
                }
            }
            catch (Exception ex)
            {
                Log.WriteException(ex);
                throw;
            }
        }