コード例 #1
0
        private string UpdateHistorico(Papel papel, string saida)
        {
            try
            {
                JObject saidaJson = PapelService.RequestData(papel.Codigo);
                float   close     = (float)saidaJson["chart"]["result"][0]["indicators"]["quote"][0]["close"][0];
                float   high      = (float)saidaJson["chart"]["result"][0]["indicators"]["quote"][0]["high"][0];
                float   low       = (float)saidaJson["chart"]["result"][0]["indicators"]["quote"][0]["low"][0];
                float   open      = (float)saidaJson["chart"]["result"][0]["indicators"]["quote"][0]["open"][0];
                float   volume    = (float)saidaJson["chart"]["result"][0]["indicators"]["quote"][0]["volume"][0];
                double  timestamp = (double)saidaJson["chart"]["result"][0]["timestamp"][0];
                papel.ValorAtual = close;

                DateTime data = Utils.Utils.UnixTimeStampToDateTime(timestamp);
                papel.LastUpdate        = DateTime.Now;
                papel.LastUpdateMessage = "OK";
                Historico historico = GetHistoricoForPapel(papel, data);
                historico.Close  = close;
                historico.High   = high;
                historico.Open   = open;
                historico.Low    = low;
                historico.Volume = volume;

                saida += " OK";
            }
            catch (Exception e)
            {
                saida += " ERROR: " + e.ToString();
            }

            return(saida);
        }
コード例 #2
0
        internal bool CadastraPapel(out string err, int idUsuarioAtual, string codigo, string nome, int lotePadrao)
        {
            if (nome == "")
            {
                err = "Empty name";
                return(false);
            }
            if (codigo == "")
            {
                err = "Empty code";
                return(false);
            }
            if (lotePadrao <= 0)
            {
                err = "Lote padrao invalido";
                return(false);
            }
            codigo = codigo.ToUpper();
            nome   = nome.ToUpper();

            Papel papel = db.Papeis.Where(x => x.Codigo == codigo).FirstOrDefault();

            if (papel != null)
            {
                err = "Papel já existe";
                return(false);
            }
            papel            = new Papel();
            papel.Codigo     = codigo;
            papel.Nome       = nome;
            papel.LotePadrao = lotePadrao;
            papel.LastUpdate = DateTime.Now;

            try
            {
                JObject saidaJson = PapelService.RequestData(codigo);
            }
            catch (Exception)
            {
                err = "Erro ao validar a ação";
                return(false);
            }
            db.Papeis.Add(papel);
            db.SaveChanges();


            err = "";
            return(true);
        }