internal static void Display(SymbolPrice price) { lock (ConsoleSync) { Console.WriteLine($" {price.Symbol.PadLeft(8)}: {price.Value}"); } }
//Metodo que retorna os ultimos 25 preços obtidos public List <SymbolPrice> SelectLastPrices() { //Instancia ViewModel List <SymbolPrice> listSymbolPrice = new List <SymbolPrice>(); //selecionar os últimos 25 preços cadastrados var listSymbolSelect = db_UzzoBinance.SymbolPrice .Select(SP => SP) .OrderByDescending(SP => SP.dateAndTimePrice) .Take(25) .ToList(); foreach (var item in listSymbolSelect) { SymbolPrice columnSymbolPrice = new SymbolPrice(); columnSymbolPrice.symbol = item.symbol; columnSymbolPrice.bidPrice = item.bidPrice; columnSymbolPrice.askPrice = item.askPrice; columnSymbolPrice.dateAndTimePrice = item.dateAndTimePrice; listSymbolPrice.Add(columnSymbolPrice); } //Retorna o resultado da seleção return(listSymbolPrice); }
public void Properties() { var symbol = Symbol.BTC_USDT; const decimal value = 1.2345m; var price = new SymbolPrice(symbol, value); Assert.Equal(symbol, price.Symbol); Assert.Equal(value, price.Value); }
private static List <IslemListe> StratejiSonucHesapla(SymbolPrice coin, TimeInterval periyot, int emaUzunluk, double yuzde, List <MostDLL.Most> mostListe, List <double> iftsListe, List <decimal> macdListe) { List <IslemListe> islemListe = new List <IslemListe>(); var sgIslemSay = 0; var sgPozisyon = "SAT"; for (int i = 4; i < mostListe.Count; i++) { var itemMost = mostListe[i]; if (itemMost.MostDurum == "AL") { if (sgPozisyon == "SAT") { var iftsOnay = iftsListe[i - 1] >= -0.5 && iftsListe[i - 2] < -0.5 && iftsListe[i - 3] < -0.5; var macdOnay = macdListe[i - 1] > 0; if (iftsOnay && macdOnay) { sgIslemSay++; sgPozisyon = "AL"; } } } else { if (sgPozisyon == "AL") { sgPozisyon = "SAT"; } } DateTime utc = itemMost.Bar.DateTime.UtcDateTime; islemListe.Add(new IslemListe { Sembol = coin.Symbol, MostParametreleri = "(" + emaUzunluk + "," + yuzde * 100 + ")", Periyot = periyot.GetDescription(), AcilisZamani = utc.ToLocalTime(), Durum = sgPozisyon, EmaDeger = itemMost.EmaDegeri, Fiyat = itemMost.Bar.Open, MostDeger = itemMost.MostDegeri, IslemSayisi = sgIslemSay, Bar = itemMost.Bar }); } //Son işlemi sat durumuna geçip o anda eğer al durumunda ise kar oranını hesaba dahil ediyoruz if (islemListe.Count > 0) { islemListe.Last().Durum = "SAT"; } return(islemListe); }
public virtual string Serialize(SymbolPrice symbolPrice) { Throw.IfNull(symbolPrice, nameof(symbolPrice)); var jObject = new JObject { new JProperty(KeySymbol, symbolPrice.Symbol), new JProperty(KeyPrice, symbolPrice.Value) }; return(jObject.ToString(Formatting.None)); }
/// <summary> /// Get the current price for the given symbol /// </summary> /// <param name="symbol">Asset symbol e.g.ETHBTC</param> /// <returns>The price. Double.</returns> public static double GetOnePrice(string symbol) { var symbolPrices = GetAllPrices(); SymbolPrice symbolPrice = (from sym in symbolPrices where sym.Symbol == symbol select sym).FirstOrDefault(); if (symbolPrice == null) { throw new ApplicationException($"No symbol, {symbol}, exists"); } return(symbolPrice.Price); }
private void UpdatePriceChange(SymbolPrice sp) { var symbol = sp.Symbol; if (!_htStocks.ContainsKey(symbol)) { return; } var stock = _htStocks[symbol]; _htStocks[symbol] = new Stock(symbol, stock.Quantity, sp.Price); OnValueChanged(stock); }
public void Serialization() { var symbol = Symbol.BTC_USDT; const decimal value = 1.2345m; var price = new SymbolPrice(symbol, value); var json = JsonConvert.SerializeObject(price); price = JsonConvert.DeserializeObject <SymbolPrice>(json); Assert.Equal(symbol, price.Symbol); Assert.Equal(value, price.Value); }
public void Equality() { var symbol = Symbol.BTC_USDT; const decimal value = 1.2345m; var price = new SymbolPrice(symbol, value); var serializer = new SymbolPriceSerializer(); var json = serializer.Serialize(price); var other = serializer.Deserialize(json); Assert.True(price.Equals(other)); }
public async Task <string> SearchPrice() { try { SearchPrice obj_SearchPrice = new SearchPrice(); //Utilizando HttClient para a chamada da requisição using (var httpClient = new HttpClient()) { httpClient.DefaultRequestHeaders.Accept.Clear(); httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); //Realizando o post para criação de uma nova ordem na Binance HttpResponseMessage httpResponse = httpClient.GetAsync($"{_configuration.GetSection("Binance:SymbolPrice").Value}{"BTCUSDT"}").Result; var varReceiveStream = await httpResponse.Content.ReadAsStringAsync(); //Serealizando o retorno em um objeto do tipo Model SeachPrice dynamic objReturn = Newtonsoft.Json.JsonConvert.DeserializeObject <SearchPrice>(varReceiveStream); if (objReturn != null) { //Inserindo Preço de Compra e Preço de Venda da Criptomoeda no banco de dados var var_InsertSymbolPrice = new SymbolPrice { symbol = objReturn.symbol, bidPrice = Convert.ToDecimal(objReturn.bidPrice), //Compra askPrice = Convert.ToDecimal(objReturn.askPrice), //Venda dateAndTimePrice = DateTime.Now }; db_UzzoBinance.Add(var_InsertSymbolPrice); db_UzzoBinance.SaveChanges(); //Retirar o Tracked da tabela para que seja possivel instanciar a mesma novamente db_UzzoBinance.Entry(var_InsertSymbolPrice).State = EntityState.Detached; } } return(obj_SearchPrice.lastId.ToString()); } catch (Exception ex) { throw ex.InnerException; } }
private async void SimulateChanges(Random random) { while (!_cts.Token.IsCancellationRequested) { await Task.Delay(20); for (var i = 0; i < 2; i++) { var index = random.Next(0, _allSymbols.Count); var symbol = _allSymbols[index]; var price = random.NextDouble() * 100; var symbolPrice = _htPrices[symbol] = new SymbolPrice(symbol, price); var handler = PriceChanged; handler?.Invoke(null, symbolPrice); } } }
void oecClient_OnPriceChanged(OEC.API.Contract Contract, OEC.API.Price Price) { Symbol symbol = GetSymbolFromContract(Contract); if (symbol != null) { Trace.WriteLine(Contract.ToString() + " Price (" + symbol.ToString() + ")"); SymbolPrice symbolPrice = null; if (!_symbolPrices.TryGetValue(symbol, out symbolPrice)) { symbolPrice = new SymbolPrice(); symbolPrice.symbol = symbol; symbolPrice.TotalVol = Price.TotalVol; _symbolPrices[symbol] = symbolPrice; } TickData data; if (symbolPrice.AskPrice != Price.AskPrice || symbolPrice.AskSize != Price.AskVol) { symbolPrice.AskPrice = Price.AskPrice; symbolPrice.AskSize = Price.AskVol; data = new TickData(); data.time = Price.LastDateTime; data.tickType = TickType.Ask; data.price = Price.AskPrice; data.size = (UInt64)Price.AskVol; if (tickListener != null) { tickListener(symbol, data); } } if (symbolPrice.BidPrice != Price.BidPrice || symbolPrice.BidSize != Price.BidVol) { symbolPrice.BidPrice = Price.BidPrice; symbolPrice.BidSize = Price.BidVol; data = new TickData(); data.time = Price.LastDateTime; data.tickType = TickType.Bid; data.price = Price.BidPrice; data.size = (UInt64)Price.BidVol; if (tickListener != null) { tickListener(symbol, data); } } if (symbolPrice.TotalVol != Price.TotalVol || symbolPrice.LastPrice != Price.LastPrice) { data = new TickData(); data.time = Price.LastDateTime; data.tickType = TickType.Trade; data.price = Price.LastPrice; if (symbolPrice.TotalVol > Price.TotalVol) { data.size = 0; } else { data.size = (UInt64)(Price.TotalVol - symbolPrice.TotalVol); } symbolPrice.LastPrice = Price.LastPrice; symbolPrice.TotalVol = Price.TotalVol; if (tickListener != null) { tickListener(symbol, data); } } //data = new TickData(); //data.time = DateTime.Now; //data.tickType = TickType.LastSize; //data.value = Price.LastVol; //if (tickListener != null) //{ // tickListener(symbol, data); //} if (symbolPrice.LowPrice != Price.LowPrice) { symbolPrice.LowPrice = Price.LowPrice; data = new TickData(); data.time = Price.LastDateTime; data.tickType = TickType.LowPrice; data.price = Price.LowPrice; if (tickListener != null) { tickListener(symbol, data); } } if (symbolPrice.HighPrice != Price.HighPrice) { symbolPrice.HighPrice = Price.HighPrice; data = new TickData(); data.time = Price.LastDateTime; data.tickType = TickType.HighPrice; data.price = Price.HighPrice; if (tickListener != null) { tickListener(symbol, data); } } //data = new TickData(); //data.time = DateTime.Now; //data.tickType = TickType.OpenPrice; //data.value = Price.OpenPrice; //if (tickListener != null) //{ // tickListener(symbol, data); //} //data = new TickData(); //data.time = DateTime.Now; //data.tickType = TickType.AskSize; //data.value = Price.AskVol; //if (tickListener != null) //{ // tickListener(symbol, data); //} //data = new TickData(); //data.time = DateTime.Now; //data.tickType = TickType.BidSize; //data.value = Price.BidVol; //if (tickListener != null) //{ // tickListener(symbol, data); //} //data = new TickData(); //data.time = DateTime.Now; //data.tickType = TickType.Change; //data.value = Price.Change; //if (tickListener != null) //{ // tickListener(symbol, data); //} } else { //Trace.WriteLine(Contract.ToString() + " Price (unwatched)"); } }
private void ProcessSecurityPriceRequest(IModel channel, BasicDeliverEventArgs msg) { try { logger.Log(LogLevel.Info, $"Processing SecurityPriceRequest {msg.BasicProperties.MessageId}"); using (var session = sessionFactory.OpenSession()) { var requestFromQueue = msg.GetMessage <SecurityPriceRequest>(); string requestFromQueueSymbol = requestFromQueue.Symbol?.ToUpper(); DateTime requestFromQueueNavDate = requestFromQueue.NavDate; string requestFromQueueMessageId = requestFromQueue.MessageId; string securityPriceRequestLog = $"[SecurityPriceRequest: NavDate {requestFromQueueNavDate}, Symbol {requestFromQueueSymbol}, MessageId {requestFromQueueMessageId}]"; logger.Log(LogLevel.Info, securityPriceRequestLog); Request requestFromDb = requestService.GetOrCreateRequest(session, requestFromQueue, RequestType.SecurityPriceRequest, requestFromQueueNavDate); Entities.Security security = securityService.GetSecurityBySymbol(session, requestFromQueueSymbol); if (security == null) { logger.Log(LogLevel.Info, $"{securityPriceRequestLog}: missing Security with Symbol {requestFromQueueSymbol}"); requestService.SetRequestStatus(session, requestFromDb, RequestStatus.Error); channel.SendNack(msg.DeliveryTag); return; } if (requestFromDb.RequestStatus == RequestStatus.Done) { logger.Log(LogLevel.Info, $"{securityPriceRequestLog}: already processed with success, see Request {requestFromDb.RequestId}"); logger.Log(LogLevel.Info, $"{securityPriceRequestLog}: retrieving SecurityPrice with same nav date and symbol"); SecurityPrice securityPrice = securityPriceService.GetSecurityPriceBySymbol(session, requestFromQueueSymbol, requestFromQueueNavDate.Date); if (securityPrice != null) { logger.Log(LogLevel.Info, $"{securityPriceRequestLog}: sending SecurityPrice Id: {securityPrice.SecurityPriceId}, NavDate: {securityPrice.NavDate}, Symbol: {securityPrice.Security.Symbol}, OpenPrice: {securityPrice.OpenPrice}, ClosePrice: {securityPrice.ClosePrice}"); PublishSecurityPrice(channel, securityPrice, requestFromQueue.MessageId); channel.SendAck(msg.DeliveryTag); logger.Log(LogLevel.Info, $"{securityPriceRequestLog}: sent SecurityPrice Id: {securityPrice.SecurityPriceId}, NavDate: {securityPrice.NavDate}, Symbol: {securityPrice.Security.Symbol}, OpenPrice: {securityPrice.OpenPrice}, ClosePrice: {securityPrice.ClosePrice}"); return; } requestService.SetRequestStatus(session, requestFromDb, RequestStatus.Error); channel.SendNack(msg.DeliveryTag); return; } logger.Log(LogLevel.Info, $"{securityPriceRequestLog}: retrieving SecurityPrice from IEXCloud for NavDate {requestFromQueueNavDate}"); SymbolPrice symbolPrice = iexCloudRequestManager.GetSymbolPrice(requestFromQueueSymbol); logger.Log(LogLevel.Info, $"{securityPriceRequestLog}: SecurityPrice from IEXCloud retrived - Symbol: {symbolPrice.symbol}, OpenPrice: {symbolPrice.open}, ClosePrice: {symbolPrice.close} "); logger.Log(LogLevel.Info, $"{securityPriceRequestLog}: Saving SecurityPrice from IEXCloud"); SecurityPrice dbSecurityPrice = SaveSecurityPrice(session, symbolPrice, security, requestFromQueueNavDate); logger.Log(LogLevel.Info, $"{securityPriceRequestLog}: SecurityPrice Id: {dbSecurityPrice.SecurityPriceId} saved"); logger.Log(LogLevel.Info, $"{securityPriceRequestLog}: Sending SecurityPrice Id: {dbSecurityPrice.SecurityPriceId}, NavDate: {dbSecurityPrice.NavDate}, Symbol: {dbSecurityPrice.Security.Symbol}, OpenPrice: {dbSecurityPrice.OpenPrice}, ClosePrice: {dbSecurityPrice.ClosePrice} on {Queues.SecurityPriceResponseQueue}"); PublishSecurityPrice(channel, dbSecurityPrice, requestFromQueue.MessageId); logger.Log(LogLevel.Info, $"{securityPriceRequestLog}: SecurityPrice Id: {dbSecurityPrice.SecurityPriceId} on {Queues.SecurityPriceResponseQueue} sent"); requestService.SetRequestStatus(session, requestFromDb, RequestStatus.Done); channel.SendAck(msg.DeliveryTag); } } catch (JsonException jsonException) { logger.Log(LogLevel.Error, jsonException, jsonException.Message); channel.SendAck(msg.DeliveryTag); } catch (Exception exception) { logger.Log(LogLevel.Error, exception, exception.Message); channel.SendNack(msg.DeliveryTag); } }
private Entities.SecurityPrice SaveSecurityPrice(ISession session, SymbolPrice symbolPrice, Entities.Security security, DateTime navDate) { SecurityPrice securityPrice = securityPriceBuilder.BuildSecurityPrice(security, symbolPrice.open ?? 0, symbolPrice.close ?? 0, navDate); return(securityPriceService.SaveSecurityPrice(session, securityPrice)); }