public void InsertHierarchyMarket(HierarchyMarket marketItem)
 {
     try
     {
         using (var context = new IgContext())
         {
             context.HierarchyMarkets.Add(marketItem);
             context.SaveChanges();
         }
     }
     catch (Exception e)
     {
         Console.WriteLine(e);
         throw;
     }
 }
예제 #2
0
 private IgPublicApiData.BrowseModel LoadMarket(HierarchyMarket market)
 {
     return(new IgPublicApiData.BrowseModel
     {
         Model = new IgPublicApiData.InstrumentModel
         {
             Bid = market.bid,
             Offer = market.offer,
             High = market.high,
             Low = market.low,
             InstrumentName = market.instrumentName,
             Epic = market.epic,
             NetChange = market.netChange,
             PctChange = market.percentageChange,
             StreamingPricesAvailable = market.streamingPricesAvailable
         }
     });
 }
예제 #3
0
        public async Task GetOmxStocksFillHierarchyMarketTableExpectNoErrors()
        {
            if (IgRestService.GetConversationContext() == null)
            {
                await IgRestService.Authenticate(_conversationContext, _identifier, _password);
            }

            List <HierarchyMarket> marketList = new List <HierarchyMarket>();

            IG.Data.DataOperations dataOperations = new IG.Data.DataOperations();
            dataOperations.DeleteAllHierarchyNodes();
            List <HierarchyNode> nodeList = dataOperations.GetAllHierarchyNodes();

            foreach (var node in nodeList)
            {
                if (node.Id > 0)
                {
                    try
                    {
                        var instrumentNode = await IgRestService.GetHierarchyMarket(node.Id.ToString());

                        if (instrumentNode != null && instrumentNode.StatusCode == HttpStatusCode.OK)
                        {
                            System.Diagnostics.Debug.WriteLine(instrumentNode.Response.markets[0].instrumentName);
                            HierarchyMarket temp = new HierarchyMarket();
                            if (instrumentNode.Response.markets[0].bid != null)
                            {
                                temp.Bid = instrumentNode.Response.markets[0].bid;
                            }
                            if (instrumentNode.Response.markets[0].delayTime != null)
                            {
                                temp.DelayTime = instrumentNode.Response.markets[0].delayTime;
                            }
                            if (instrumentNode.Response.markets[0].epic != null)
                            {
                                temp.Epic = instrumentNode.Response.markets[0].epic;
                            }
                            if (instrumentNode.Response.markets[0].expiry != null)
                            {
                                temp.Expiry = instrumentNode.Response.markets[0].expiry;
                            }
                            if (instrumentNode.Response.markets[0].high != null)
                            {
                                temp.High = instrumentNode.Response.markets[0].high;
                            }
                            if (instrumentNode.Response.markets[0].instrumentName != null)
                            {
                                temp.InstrumentName = instrumentNode.Response.markets[0].instrumentName;
                            }
                            if (instrumentNode.Response.markets[0].instrumentType != null)
                            {
                                temp.InstrumentType = instrumentNode.Response.markets[0].instrumentType;
                            }
                            if (instrumentNode.Response.markets[0].lotSize != null)
                            {
                                temp.LotSize = instrumentNode.Response.markets[0].lotSize;
                            }
                            if (instrumentNode.Response.markets[0].low != null)
                            {
                                temp.Low = instrumentNode.Response.markets[0].low;
                            }
                            if (instrumentNode.Response.markets[0].marketStatus != null)
                            {
                                temp.MarketStatus = instrumentNode.Response.markets[0].marketStatus;
                            }
                            if (instrumentNode.Response.markets[0].netChange != null)
                            {
                                temp.NetChange = instrumentNode.Response.markets[0].netChange;
                            }
                            if (instrumentNode.Response.markets[0].offer != null)
                            {
                                temp.Offer = instrumentNode.Response.markets[0].offer;
                            }
                            if (instrumentNode.Response.markets[0].otcTradeable != null)
                            {
                                temp.OtcTradeable = instrumentNode.Response.markets[0].otcTradeable;
                            }
                            if (instrumentNode.Response.markets[0].percentageChange != null)
                            {
                                temp.PercentageChange = instrumentNode.Response.markets[0].percentageChange;
                            }
                            if (instrumentNode.Response.markets[0].scalingFactor != null)
                            {
                                temp.ScalingFactor = instrumentNode.Response.markets[0].scalingFactor;
                            }
                            if (instrumentNode.Response.markets[0].streamingPricesAvailable != null)
                            {
                                temp.StreamingPricesAvailable = instrumentNode.Response.markets[0].streamingPricesAvailable;
                            }
                            if (instrumentNode.Response.markets[0].updateTime != null)
                            {
                                temp.UpdateTime = instrumentNode.Response.markets[0].updateTime;
                            }
                            if (node.Id != null)
                            {
                                temp.HierarchyNodeId = node.Id;
                            }


                            dataOperations.InsertHierarchyMarket(temp);
                            Thread.Sleep(1000);
                        }
                        else
                        {
                            System.Diagnostics.Debug.WriteLine(node.Id.ToString() + "  " + instrumentNode.StatusCode);
                        }
                    }
                    catch (Exception e)
                    {
                        System.Diagnostics.Debug.WriteLine(e);
                        throw;
                    }
                }
            }

            //System.Diagnostics.Debug.WriteLine("Count=" + marketList.Count);
        }