Exemplo n.º 1
0
        private static void ObserverScenario()
        {
            var joao    = new Observer("João");
            var eduardo = new Observer("Eduardo");
            var bill    = new Observer("Bill");

            var amazon    = new StockExchange("Amazon", NextDecimal());
            var microsoft = new StockExchange("Microsoft", NextDecimal());

            amazon.Subscribe(joao);
            amazon.Subscribe(eduardo);

            microsoft.Subscribe(eduardo);
            microsoft.Subscribe(bill);

            Console.WriteLine("");
            Console.WriteLine("------------------");
            Console.WriteLine("");

            for (int i = 0; i < 5; i++)
            {
                amazon.Value    = NextDecimal();
                microsoft.Value = NextDecimal();

                if (i == 1)
                {
                    amazon.UnSubscribe(eduardo);
                }
            }
        }
Exemplo n.º 2
0
 public DataViewModel()
 {
     this.StockExchange = new ObservableCollection <DataModel>();
     StockExchange.Add(new DataModel()
     {
         Quaterly = "Qua1", Price = 6, Stock = 4, Volume = 5
     });
     StockExchange.Add(new DataModel()
     {
         Quaterly = "Qua2", Price = 10, Stock = 10, Volume = 4
     });
     StockExchange.Add(new DataModel()
     {
         Quaterly = "Qua3", Price = 6, Stock = 2, Volume = 5
     });
     StockExchange.Add(new DataModel()
     {
         Quaterly = "Qua4", Price = 1, Stock = 8, Volume = 2
     });
     StockExchange.Add(new DataModel()
     {
         Quaterly = "Qua5", Price = 5, Stock = 6, Volume = 4
     });
     StockExchange.Add(new DataModel()
     {
         Quaterly = "Qua6", Price = 3, Stock = 8, Volume = 1
     });
 }
        public void DeleteStockExchange(string sid)
        {
            StockExchange stockExchange = context.StockExchanges.SingleOrDefault(s => s.StockExchangeId == sid);

            context.StockExchanges.Remove(stockExchange);
            context.SaveChanges();
        }
Exemplo n.º 4
0
        public bool AddStockExchange(StockExchange stockExchange)
        {
            context.StockExchange.Add(stockExchange);
            int RowsAffected = context.SaveChanges();

            return(RowsAffected > 0);
        }
        public async Task SendExchangeData(WebSocket socket, StockExchange member)
        {
            if (socket.State != WebSocketState.Open)
            {
                return;
            }

            var sendStock = JsonConvert.SerializeObject(new StockExchange
            {
                Symbol   = member.Symbol,
                Volume   = member.Volume,
                Price    = member.Price,
                DateTime = member.DateTime
            });

            Monitor.Enter(socket);

            try
            {
                await socket.SendAsync(buffer : new ArraySegment <byte>(array: Encoding.ASCII.GetBytes(sendStock),
                                                                        offset: 0,
                                                                        count: sendStock.Length),
                                       messageType : WebSocketMessageType.Text,
                                       endOfMessage : true,
                                       cancellationToken : CancellationToken.None);
            }
            finally
            {
                Monitor.Exit(socket);
            }
        }
        public IActionResult Post([FromBody] StockExchange ex)
        {
            ClaimsIdentity identity = HttpContext.User.Identity as ClaimsIdentity;
            string         role     = identity.FindFirst("Role").Value;

            if (role == "Admin")
            {
                var res = _repo.addNewExchange(ex);
                if (res)
                {
                    return(Ok(new Response {
                        StatusCode = "Success", Message = "Exchange added successfully"
                    }));
                }
                else
                {
                    return(BadRequest(new Response {
                        StatusCode = "Failed", Message = "Exchange adding unsuccessful"
                    }));
                }
            }
            else
            {
                return(Unauthorized(new Response
                {
                    StatusCode = "Failed",
                    Message = "Exchange Creation Unsuccessful. Only Admins can be allowed"
                }));
            }
        }
Exemplo n.º 7
0
        private void btnGetdata_Click(object sender, EventArgs e)
        {
            Actions actions = new Actions();

            UI.Data.DB       db         = new UI.Data.DB();
            List <StockInfo> stockInfos = new List <StockInfo>();



            StockExchange stock_exchange = db.GetAllStockExchanges().First();//change to loop later
            Node          node           = db.GetNodeFromConfig();



            stockInfos = db.GetSymbolsForNode(stock_exchange.stockExchange_Name, node);//get all symbols for this node
            //prgIncrement = stockInfos.Count;
            //prgIncrement = 100 / prgIncrement;
            Console.WriteLine("Started at " + DateTime.Now);

            int icount = 0;

            foreach (StockInfo stockinfo in stockInfos)
            {
                icount++;
                try
                {
                    bool result_processing = false;
                    result_processing = actions.ProcessRules(stockinfo, stock_exchange);



                    // prgStocks.Value += 1;


                    DataGridViewRow grdFetchStatus_row = (DataGridViewRow)grdFetchStatus.Rows[0].Clone();
                    grdFetchStatus_row.Cells[0].Value = stockinfo.stock_symbol;
                    Console.WriteLine(icount + ")  " + stockinfo.stock_symbol + "   " + "Done !");

                    if (result_processing)
                    {
                        grdFetchStatus_row.Cells[1].Value = "Y";
                    }
                    else
                    {
                        grdFetchStatus_row.Cells[1].Value = "X";
                    }
                    grdFetchStatus.Rows.Add(grdFetchStatus_row);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(stockinfo.stock_symbol + "   " + "ERR at button click !");
                    DataGridViewRow grdFetchStatus_row = (DataGridViewRow)grdFetchStatus.Rows[0].Clone();
                    grdFetchStatus_row.Cells[0].Value = stockinfo.stock_symbol;
                    grdFetchStatus_row.Cells[1].Value = "F";
                    grdFetchStatus.Rows.Add(grdFetchStatus_row);
                }
            }

            Console.WriteLine("Completed at " + DateTime.Now);
        }
Exemplo n.º 8
0
        public ActionResult DeleteConfirmed(int id)
        {
            StockExchange stockExchange = db.Stock.Find(id);

            db.Stock.Remove(stockExchange);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Exemplo n.º 9
0
        public void TestSplitOddAmount()
        {
            var stockExchange = new StockExchange();
            var bank          = new Bank(stockExchange, new MockUpCurrencyListing(), "USD");

            //Assert.AreEqual(money.NumericCode, 840);
            //Assert.AreEqual(money.MinorUnit, 2);
        }
Exemplo n.º 10
0
        public void TestExchangeRatesEquality()
        {
            var newRateA = StockExchange.ExchangeRate(DateTime.Now, "CHF", "USD", 2.0M);
            var newRateB = StockExchange.ExchangeRate(DateTime.Now, "CHF", "USD", 2.0M);

            Assert.IsTrue(newRateA.Equals(newRateB));
            Assert.IsFalse(newRateA.Equals(null));
        }
    public void Main()
    {
        StockExchange exchange = new StockExchange();

        exchange.Observe(new HistoricalArchiveStockObserver());
        exchange.Observe(new PriceDropStockObserver("NASDAQ", 10));
        exchange.Observe(new PriceDropStockObserver("DOW", 100));
    }
Exemplo n.º 12
0
        public void TestGetUser()
        {
            //Arrange
            int expected = 1;
            //Act
            StockExchange stockExchange = _service.GetSE(1);

            Assert.Equal(expected, stockExchange.Id);
        }
Exemplo n.º 13
0
        protected void AddDummyStock(string isin)
        {
            var company     = new Company("C");
            var stock       = new Stock(company, isin);
            var exchange    = new StockExchange("Xetra", "De", new Currency("Euro", "Euro"));
            var tradedStock = new TradedStock(stock, exchange);

            Interpreter.Context.Scope.Stock = new StockHandle(tradedStock);
        }
Exemplo n.º 14
0
 /// <summary>标的代码-标签新浪
 /// </summary>
 public string GetStockID_TagSina()
 {
     //区分期权标签
     if (StockType == typeStock.Option)
     {
         return(StockType.Get_Remark() + StockID);
     }
     return(StockExchange.ToString() + StockID);
 }
Exemplo n.º 15
0
        public void Awake()
        {
            StockExchange.StartExchange();
            Timer sTimer = new Timer();

            sTimer.Elapsed += new ElapsedEventHandler((object source, ElapsedEventArgs e) => { IntervalUpdate(); StockExchange.calculateExchange(); });
            sTimer.Interval = 1000; // 1000 ms is one second
            sTimer.Start();
        }
Exemplo n.º 16
0
        public static StockHandle CreateStockHandle(string companyName, string isin, string currency)
        {
            var company     = new Company(companyName);
            var stock       = new Stock(company, isin);
            var exchange    = new StockExchange("Xetra", "DE", new Currency(currency, currency));
            var tradedStock = new TradedStock(stock, exchange);

            return(new StockHandle(tradedStock));
        }
Exemplo n.º 17
0
 public ActionResult Edit([Bind(Include = "ID,Date,StockValue")] StockExchange stockExchange)
 {
     if (ModelState.IsValid)
     {
         db.Entry(stockExchange).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(stockExchange));
 }
Exemplo n.º 18
0
 public ActionResult Create([Bind(Include = "ID,Date,StockValue")] StockExchange stockExchange)
 {
     if (ModelState.IsValid)
     {
         db.Stock.Add(stockExchange);
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(stockExchange));
 }
Exemplo n.º 19
0
 public static void calculateExchange()
 {
     for (int i = 0; i < OrbList.Length; i++)
     {
         if (StockExchange.getRate(OrbList[i]) == 0)
         {
             OrbVals[i] = ((((i % OrbList.Length) + 1) * (float)Math.Round(Math.Pow(10, i))) + jMath.SumFloatArray(Count)) / Count[i];  // Takes a value made from the ranking spot,
         }
     }
 }
Exemplo n.º 20
0
        public static MarketQuote GetCurrentMarketData(string symbol, StockExchange exchange)
        {
            string      url_currentMarketData;
            MarketQuote marketQuote = new MarketQuote();

            //
            switch (exchange.stockExchange_Name)
            {
            case "NASDAQ":
                url_currentMarketData = "https://api.tdameritrade.com/v1/marketdata/" + symbol + "/quotes?apikey=8FBL4ZPB5OPNLAAM90FRWYFKAMYNIVKH";
                try
                {
                    HttpClient client = new HttpClient();

                    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                    HttpResponseMessage response = client.GetAsync(url_currentMarketData).Result;

                    if (response.IsSuccessStatusCode)
                    {
                        string  JSON    = response.Content.ReadAsStringAsync().Result;
                        JObject jobject = JObject.Parse(JSON);
                        JToken  jStock  = jobject[symbol];

                        marketQuote.openPrice  = (float)jStock["openPrice"];
                        marketQuote.closePrice = (float)jStock["closePrice"];

                        marketQuote.lastPrice = (float)jStock["lastPrice"];

                        marketQuote.highPrice = (float)jStock["highPrice"];
                        marketQuote.lowPrice  = (float)jStock["lowPrice"];

                        marketQuote.netChange         = (float)jStock["netChange"];
                        marketQuote.totalVolume       = (int)jStock["totalVolume"];
                        marketQuote.volatility        = (float)jStock["volatility"];
                        marketQuote.w52WkHigh         = (float)jStock["52WkHigh"];
                        marketQuote.w52WkLow          = (float)jStock["52WkLow"];
                        marketQuote.markPercentChange = (float)jStock["markPercentChangeInDouble"];
                    }

                    break;
                }
                catch (Exception ex)
                {
                    //log error
                    return(null);
                }


            default:
                break;
            }

            return(marketQuote);
        }
Exemplo n.º 21
0
        public List <StockExchange> GetAllStockExchanges()
        {
            StockExchange _StockExchange = new StockExchange();

            _StockExchange.stockExchange_Name = "NASDAQ";
            _StockExchange.stockExchange_ID   = 2;
            List <StockExchange> _StockExchanges = new List <StockExchange>();

            _StockExchanges.Add(_StockExchange);
            return(_StockExchanges);
        }
Exemplo n.º 22
0
        public void TestDeleteProduct()
        {
            int id = 2;

            _service.DeleteSE(id);

            //Act
            StockExchange stockExchange = _service.GetSE(id);

            Assert.Null(stockExchange);
        }
        public void TestCurrencyCultureFormatting()
        {
            var stockExchange = new StockExchange();
            var bank          = new Bank(stockExchange, new MockUpCurrencyListing(), "USD");

            Assert.AreEqual(bank.Dollar(100M).ToString(), "$100.00");
            Assert.AreEqual(bank.Pound(100M).ToString(), "£100.00");
            Assert.AreEqual(bank.Euro(100M).ToString(), "100,00 €");
            Assert.AreEqual(bank.Dong(100M).ToString(), "100,00 ₫");
            Assert.AreEqual(bank.Rial(100M).ToString(), "100/00ريال");
        }
Exemplo n.º 24
0
        public void TestGetExchangeRateOn()
        {
            var targetDate    = new DateTime(2012, 10, 5, 8, 0, 0);
            var stockExchange = new StockExchange();

            stockExchange.AddExchangeRate(StockExchange.ExchangeRate(targetDate.AddDays(-2), "CHF", "USD", 2.0M));
            stockExchange.AddExchangeRate(StockExchange.ExchangeRate(new DateTime(2012, 12, 7, 7, 0, 0), "CHF", "USD", 2.1M));
            stockExchange.AddExchangeRate(StockExchange.ExchangeRate(new DateTime(2013, 2, 8, 8, 0, 0), "CHF", "USD", 2.2M));
            Assert.AreEqual(stockExchange.GetExchangeRateOn("CHF", "USD", targetDate), StockExchange.ExchangeRate(targetDate.AddDays(-2), "CHF", "USD", 2.0M));
            Assert.AreEqual(stockExchange.GetExchangeRateOn("CHF", "CAD", targetDate), null);
        }
Exemplo n.º 25
0
        public void TestAddExchangeRates()
        {
            var fixedNow = DateTime.Now;
            var newRate  = StockExchange.ExchangeRate(fixedNow, "CHF", "USD", 2.0M);

            Assert.AreEqual(newRate, StockExchange.ExchangeRate(fixedNow, "CHF", "USD", 2.0M));

            var offsetRate = StockExchange.ExchangeRate(DateTime.Now, "CHF", "USD", 2.1M);

            Assert.AreNotEqual(newRate, offsetRate);
        }
        private void UpdateStockItem(StockExchange stock)
        {
            var addedStock = StockDatas.FirstOrDefault(item => item.Symbol == stock.Symbol);

            if (addedStock != null)
            {
                int index = StockDatas.IndexOf(addedStock);
                StockDatas[index].Price    = stock.Price;
                StockDatas[index].Volume   = stock.Volume;
                StockDatas[index].DateTime = stock.DateTime;
            }
        }
Exemplo n.º 27
0
 public IActionResult AddUser(StockExchange stockExchange)
 {
     try
     {
         service.AddStockExchange(stockExchange);
         return(Ok());
     }
     catch (Exception ex)
     {
         return(StatusCode(500, ex.Message));
     }
 }
 public IActionResult Post(StockExchange stockExchange)
 {
     if (ModelState.IsValid)
     {
         var isAdded = se_service.Add(stockExchange);
         if (isAdded)
         {
             return(Created("StockExchange", stockExchange));
         }
     }
     return(BadRequest(ModelState));
 }
Exemplo n.º 29
0
 public Orb(string nameJ)
 {
     foreach (string nameK in Names)
     {
         if (nameK == nameJ)
         {
             Name  = nameK;
             value = StockExchange.getRate(nameK);
             StockExchange.incCount(nameK);
         }
     }
 }
 public IActionResult Post([FromBody] StockExchange stock)
 {
     if (ModelState.IsValid)
     {
         var isAdded = repository.add(stock);
         if (isAdded)
         {
             return(Created("StockExchange", stock));
         }
     }
     return(BadRequest(ModelState));
 }
Exemplo n.º 31
0
 public Stock(StockExchange stockExchange, String ticker)
 {
     this.StockExchange = stockExchange;
     this.Ticker = ticker;
 }
 public MockStock(string ticker, StockExchange stockexchange, int basePrice)
     : base(stockexchange, ticker)
 {
     _basePrice = basePrice;
 }