示例#1
0
 public Instrument(Models.TdAmeritrade.Account.Instrument instrument)
 {
     AssetType   = instrument.AssetType;
     Description = instrument.Description;
     Cusip       = instrument.Cusip;
     Exchange    = instrument.Exchange;
     Symbol      = instrument.Symbol;
     Updated     = DateTime.UtcNow;
 }
示例#2
0
        public static async Task <Instrument> GetInstrumentAsync(StocksDbContext stocksDbContext, Dictionary <string, string> settings, Models.TdAmeritrade.Account.Instrument instrument, CancellationToken cancellationToken = default)
        {
            Instrument ins;
            IReadOnlyCollection <Models.TdAmeritrade.Account.Instrument> instruments;
            JsonSerializerOptions jsonSerializerOptions;
            string json;

            jsonSerializerOptions = new();
            jsonSerializerOptions.PropertyNameCaseInsensitive = true;

            try
            {
                ins = stocksDbContext.Instrument.Single(x => x.Symbol == instrument.Symbol && x.Cusip == instrument.Cusip && x.AssetType == instrument.AssetType);
            }

            catch
            {
                json = await Requester.SendRequestAsync(Enums.HttpVerb.Get, $"{settings["InstrumentsUri"]}/{instrument.Cusip}?apikey={settings["ApiKey"]}", null, cancellationToken);

                instruments = JsonSerializer.Deserialize <IReadOnlyCollection <Models.TdAmeritrade.Account.Instrument> >(json, jsonSerializerOptions);
                ins         = new Instrument(instruments.Single());
            }

            return(ins);
        }