Example #1
0
        private static void MarketUnpairedSierraOrders(InstrumentConversion instrumentConversion, List <SierraOrder> sierraOrders, List <PairedOrder> pairedOrders, OAOrders oaOrders)
        {
            SierraOrderFacade sierraChartOrderFacade = new SierraOrderFacade();

            List <Task> tasks = new List <Task>();

            foreach (SierraOrder sierraOrder in sierraOrders)
            {
                SierraOrderEntity sierraOrderEntity = sierraChartOrderFacade.LoadByColumn(SierraOrderFacade.GetPropertyName <SierraOrderEntity>(x => x.SierraOrderId), sierraOrder.InternalOrderID);

                if (sierraOrderEntity == null && // objednavka nebyla nikdy pouzita
                    sierraOrder.IsOrder && // Neni to SL ani PT
                    pairedOrders.Find(x => x.sierraOrder.InternalOrderID == sierraOrder.InternalOrderID) == null)    // neni to sparovana objednavka
                {
                    OAOrder oaOrder = new OAOrder();
                    oaOrders.Add(oaOrder);

                    Task task = Task.Run(() =>
                    {
                        MarketUnpairedSierraOrder(instrumentConversion, sierraOrder, oaOrder);
                    });
                    tasks.Add(task);
                }
            }
            Task.WaitAll(tasks.ToArray());
        }
Example #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;
            }
        }