public async Task <ActionResult <PriceUpdate> > Post(PriceUpdate priceUpdate) { var eventToUpdate = await eventRepository.GetEventById(priceUpdate.EventId); eventToUpdate.Price = priceUpdate.Price; await eventRepository.SaveChanges(); //send integration event on to service bus PriceUpdatedMessage priceUpdatedMessage = new PriceUpdatedMessage { EventId = priceUpdate.EventId, Price = priceUpdate.Price }; try { await messageBus.PublishMessage(priceUpdatedMessage, "priceupdatedmessage"); } catch (Exception e) { Console.WriteLine(e); throw; } return(Ok(priceUpdate)); }
private static void Session_PriceUpdate(PriceUpdate priceUpdate) { INetQPublish p = new NetQPublish(); p.PublishMessage(""); Console.WriteLine($"Date: {priceUpdate.Updated} Ask: {priceUpdate.Ask} Bid: {priceUpdate.Bid}"); }
private static PriceUpdate CreateUpdateMessage(int levels) { var rnd = new Random(); var now = Timestamp.FromDateTime(DateTime.UtcNow); var update = new PriceUpdate { Timestamp = now, ClosingPrice = Math.Abs(rnd.NextDouble()), ClosingPriceTimestamp = now, LastPrice = Math.Abs(rnd.NextDouble()), LastPriceTimestamp = now, }; update.PriceUpdates.AddRange( Enumerable.Range(0, levels) .Select(i => new PriceUpdate.Types.Level { Level_ = i, Bid = new PriceUpdate.Types.Side { Price = Math.Abs(rnd.NextDouble()), Quantity = Math.Abs(rnd.Next()), NoOrders = Math.Abs(rnd.Next()), NoQuotes = Math.Abs(rnd.Next()), }, Ask = new PriceUpdate.Types.Side { Price = Math.Abs(rnd.NextDouble()), Quantity = Math.Abs(rnd.Next()), NoOrders = Math.Abs(rnd.Next()), NoQuotes = Math.Abs(rnd.Next()), }, })); return(update); }
public async Task Run([EventGridTrigger] EventGridEvent eventGridEvent, ILogger log) { log.LogInformation(eventGridEvent.Data.ToString()); var blobEvent = JsonConvert.DeserializeObject <BlobEventData>(eventGridEvent.Data.ToString()); if (blobEvent == null) { log.LogError("Could not parse blob event data from EventGrid event."); return; } var cred = new DefaultAzureCredential(); var blobClient = new BlobClient(new Uri(blobEvent.Url), cred); var response = await blobClient.DownloadAsync(); var blob = response.Value; var builder = new ServiceBusConnectionStringBuilder(Environment.GetEnvironmentVariable("SERVICE_BUS_CONNECTION_STRING")) { EntityPath = $"/{Environment.GetEnvironmentVariable("PRICE_UPDATE_QUEUE_NAME")}" }; var queueClient = new QueueClient(builder); var reader = new StreamReader(blob.Content); string line; while ((line = await reader.ReadLineAsync()) != null) { string[] words = line.Split(','); // There are better ways to parse CSV var productIdStr = words[0]; var newPriceStr = words[1]; int productId; decimal newPrice; if (!int.TryParse(productIdStr, out productId)) { log.LogError($"Could not get Item ID from line {line}."); continue; } if (!decimal.TryParse(newPriceStr, out newPrice)) { log.LogError($"Could not get New Price from line {line}."); continue; } var update = new PriceUpdate { ProductId = productId, NewPrice = newPrice }; var updateStr = JsonConvert.SerializeObject(update); var message = new Message(Encoding.UTF8.GetBytes(updateStr)); await queueClient.SendAsync(message); } }
private async Task ProcessMessageAsync(Message message, CancellationToken token) { var messageBody = Encoding.UTF8.GetString(message.Body); PriceUpdate priceUpdate = JsonConvert.DeserializeObject <PriceUpdate>(messageBody); await basketLinesRepository.UpdatePricesForIntegrationEvent(priceUpdate); await subscriptionClient.CompleteAsync(message.SystemProperties.LockToken); }
void OnPriceUpdate(PriceUpdate msg) { if (msg.id != id) { return; } UpgradePrice.text = "Cost " + msg.price.ToString() + " coins"; }
public async Task <IActionResult> Details(Event eventPriceUpdateViewModel) { PriceUpdate priceUpdate = new PriceUpdate() { EventId = eventPriceUpdateViewModel.EventId, Price = eventPriceUpdateViewModel.Price }; await eventCatalogService.UpdatePrice(priceUpdate); return(RedirectToAction("Index")); }
private static Quote Map(PriceUpdate priceUpdate) { var quote = new Quote( priceUpdate.AssetPairId, priceUpdate.Timestamp.ToDateTime(), decimal.Parse(priceUpdate.Ask, CultureInfo.InvariantCulture), decimal.Parse(priceUpdate.Bid, CultureInfo.InvariantCulture), LykkeExchange); return(quote); }
//private PriceUpdate _update; private void M_subscriber_Receive(string sUpdate) { // Update messages are sent to the client anytime one of the fields in the current fieldset are updated. //var x = "Q,@ESU17,2463.50,2,08:26:54.256829,43,170391,2463.25,116,2463.50,159,2460.25,2463.75,2456.50,2459.75,a,01,"; //m_updates.Enqueue(sUpdate); //cout(sUpdate); //return; var update = new PriceUpdate(sUpdate); //cout("{0} [{1}] {2}:{3}-{4}:{5}", _update.Symbol, _update.LastTradePrice, _update.BidSize, _update.Bid, _update.Ask, _update.AskSize); //if (!m_updatePriceRows.ContainsKey(_update.Symbol)) return; //var row = m_updatePriceRows[_update.Symbol]; //row.UpdateValues(_update); m_prices[update.Symbol] = update; //cout("SUB << {0}", _update.ToString()); if (update.Symbol.StartsWith("@VX")) { UpdateContango(); } /*else if (update.Symbol.StartsWith("@ES")) { var tes = GetTicker(m_es); if (!string.IsNullOrEmpty(tes)) cout(tes); } else if (update.Symbol.StartsWith("VIX.XO")) { var tvix = GetTicker(m_vix); if (!string.IsNullOrEmpty(tvix)) cout(tvix); PriceUpdate vix, vx; if (m_prices.TryGetValue("VIX.XO", out vix) && m_prices.TryGetValue(m_vxMonth[0], out vx)) { cout("VIX Discount: {0}", vix.LastTradePrice - vx.Mid); } }*/ //Main,RISK ind,,,,,,,[+< VIX.XO >][+<JYVIX.XO>] [+<GVZ.XO>] [+<TYX.XO>] /*else if (_update.Symbol.StartsWith("QHO") || _update.Symbol.StartsWith("GAS")) { }*/ // Price Update to Level 1 grid //if (row.NotifyGrids.Contains(m_priceGrid)) // m_priceGrid.UpdateRow(row); // Price Update to Spread grid //if (row.NotifyGrids.Contains(m_spreadGrid)) // UpdateSpreads(row); }
// Simple method to update the properties of the PriceRow //public void UpdateValues(double lastTradePrice, int lastTradeSize, double bid, int bidSize, double ask, int askSize, int totalVolume, double openPrice, double highPrice, double lowPrice, double closePrice) public void UpdateValues(PriceUpdate update) { this.LastTradePrice = update.LastTradePrice; this.LastTradeSize = update.LastTradeSize; this.Bid = update.Bid; this.BidSize = update.BidSize; this.Ask = update.Ask; this.AskSize = update.AskSize; this.TotalVolume = update.TotalVolume; this.OpenPrice = update.OpenPrice; this.HighPrice = update.HighPrice; this.LowPrice = update.LowPrice; this.ClosePrice = update.ClosePrice; }
/// <summary> /// Use this as subscription action. /// </summary> protected async void Tester(PriceUpdate priceUpdate) { if (priceUpdate.Price != -1) { Test(priceUpdate.Price); _price = priceUpdate.Price; } else { await _allSubscribed; _price = priceUpdate.Candlesticks.Last().close; Test(priceUpdate.Candlesticks); } OnPriceUpdate(); }
public void PriceUpdate(PriceUpdate update) { lock (lockTheEntireGraph) { var from = new ExchangeCurrency(update.Exchange, update.SourceCurrency); var to = new ExchangeCurrency(update.Exchange, update.DestinationCurrency); double weight = -Math.Log(update.Factor); var oldEdge = graph.Adj(from).Where(e => e.To().CompareTo(to) == 0).SingleOrDefault(); var newEdge = new Edge <ExchangeCurrency>(from, to, weight, update.Timestamp); if (oldEdge != null && oldEdge.TimeStamp < update.Timestamp) { graph.RemoveEdge(oldEdge); graph.AddEdge(newEdge); } else if (oldEdge == null) // add 1<-->1 edges by currency { graph.AddEdge(newEdge); foreach (var v in graph.Vertexes() .Where(v => v.Currency == update.SourceCurrency) .Where(v => v.CompareTo(from) != 0)) { if (!graph.HasEdgeBetween(v, from)) { graph.AddEdge(new Edge <ExchangeCurrency>(v, from, -Math.Log(1))); } if (!graph.HasEdgeBetween(from, v)) { graph.AddEdge(new Edge <ExchangeCurrency>(from, v, -Math.Log(1))); } } foreach (var v in graph.Vertexes() .Where(v => v.Currency == update.DestinationCurrency) .Where(v => v.CompareTo(to) != 0)) { if (!graph.HasEdgeBetween(v, to)) { graph.AddEdge(new Edge <ExchangeCurrency>(v, to, -Math.Log(1))); } if (!graph.HasEdgeBetween(to, v)) { graph.AddEdge(new Edge <ExchangeCurrency>(to, v, -Math.Log(1))); } } } } }
void OnPriceUpdate(PriceUpdate msg) { if (option == 2) { if (x == 1) { id = id + 1; } x = 0; } if (msg.id != id) { return; } print("Price for id:" + msg.id + " set!"); price = msg.price; CanHasUpgrade(); }
// Iterate through all contango values to see if the values have changed from those stored in m_contango[] private void UpdateContango() { PriceUpdate[] vx = new PriceUpdate[CONTANGO_COUNT]; bool updated = false; for (int i = 0; i < CONTANGO_COUNT; ++i) { if (m_prices.TryGetValue("@VX" + m_vxMonth[i], out vx[i]) && m_prices.TryGetValue("@VX" + m_vxMonth[i+1], out vx[i+1])) { var ctgo = GMath.Contango(vx[i].Mid, vx[i + 1].Mid); if (ctgo != m_contango[i]) { updated = true; m_contango[i] = ctgo; } } } if (updated) { var tes = GetTicker(m_es); if (!string.IsNullOrEmpty(tes)) cout(tes); /*var tvix = GetTicker(m_vix); if (!string.IsNullOrEmpty(tvix)) cout(tvix);*/ PriceUpdate puvix, puvx; if (m_prices.TryGetValue("VIX.XO", out puvix)) { cout("VIX: {0}", puvix.LastTradePrice); } if (m_prices.TryGetValue("VIX.XO", out puvix) && m_prices.TryGetValue(m_vxMonth[0], out puvx)) { cout("VIX Discount: {0}", puvix.LastTradePrice - puvx.Mid); } IEnumerable<string> ctgos = Enumerable.Range(0, CONTANGO_COUNT).Select(i => string.Format("{0}={1}", m_contangoMonth[i], m_contango[i])); string str = string.Join(" ", ctgos); cout("Contango: {0}\n", str); } }
private void M_subscriber_Receive(string sUpdate) { // Update messages are sent to the client anytime one of the fields in the current fieldset are updated. //var x = "Q,@ESU17,2463.50,2,08:26:54.256829,43,170391,2463.25,116,2463.50,159,2460.25,2463.75,2456.50,2459.75,a,01,"; //cout(sUpdate); _update = new PriceUpdate(sUpdate); //cout("{0} [{1}] {2}:{3}-{4}:{5}", _update.Symbol, _update.LastTradePrice, _update.BidSize, _update.Bid, _update.Ask, _update.AskSize); if (!m_updatePriceRows.ContainsKey(_update.Symbol)) return; var row = m_updatePriceRows[_update.Symbol]; row.UpdateValues(_update); // Price Update to Level 1 grid if (row.NotifyGrids.Contains(m_priceGrid)) m_priceGrid.UpdateRow(row); // Price Update to Spread grid if (row.NotifyGrids.Contains(m_spreadGrid)) UpdateSpreads(row); }
public async Task <PriceUpdate> UpdatePrice(PriceUpdate priceUpdate) { var response = await client.PostAsJson($"api/events/eventpriceupdate", priceUpdate); return(await response.ReadContentAs <PriceUpdate>()); }
/// <summary> /// Allows updating the aspects of a particular price line /// </summary> /// <param name="id"></param> /// <param name="priceUpdate"></param> public UpdateServicePriceLine(string id, PriceUpdate priceUpdate) : this(id) { Content = priceUpdate; }
static void M_prices_UpdatePrices(PriceUpdate update) { // Update messages are sent to the client anytime one of the fields in the current fieldset are updated. //var x = "Q,@ESU17,2463.50,2,08:26:54.256829,43,170391,2463.25,116,2463.50,159,2460.25,2463.75,2456.50,2459.75,a,01,"; m_updates.Update(update); //System.Console.WriteLine(update.ToString()); if (update.HasSymbolRoot("@NIY", "@NKD")) // update.Symbol.StartsWith("@NIY") || update.Symbol.StartsWith("@NKD")) { if (m_updates.HasUpdatesFor("niy", "nkd")) { decimal bid = m_updates["niy"].Bid - m_updates["nkd"].Ask; decimal ask = m_updates["niy"].Ask - m_updates["nkd"].Bid; System.Console.WriteLine("b:{0} a:{1} {2}:{3} {4}:{5}", bid, ask, m_updates["niy"].Bid, m_updates["niy"].Ask, m_updates["nkd"].Bid, m_updates["nkd"].Ask); } } if (update.HasSymbolRoot("QHG", "M.CU3=LX")) { if (m_updates.HasUpdatesFor("hg0", "hg1", "lme")) { decimal hg0 = m_updates["hg0"].Mid; decimal hg1 = m_updates["hg1"].Mid; decimal lme = m_updates["lme"].Mid; decimal spread = Math.Round((hg0 - (0.000454M * lme)) * 100, 2); System.Console.WriteLine("{0} {1} {2} spread:{3}", hg0, hg1, lme, spread); } } if (update.HasSymbolRoot("@VX")) { if (m_updates.HasUpdatesFor("vx0", "vx1", "vx2", "vx3", "vx4", "vx5")) { decimal vx0 = m_updates["vx0"].Mid; decimal vx1 = m_updates["vx1"].Mid; decimal vx2 = m_updates["vx2"].Mid; decimal vx3 = m_updates["vx3"].Mid; decimal vx4 = m_updates["vx4"].Mid; decimal vx5 = m_updates["vx5"].Mid; decimal contango1 = Contango(vx0, vx1); decimal contango2 = Contango(vx1, vx2); decimal contango3 = Contango(vx2, vx3); decimal contango4 = Contango(vx3, vx4); decimal contango5 = Contango(vx4, vx5); System.Console.WriteLine("{0}% {1}% {2}% {3}% {4}% vx0:{5} vx1:{6} vx2:{7} vx3:{8} vx4:{9} vx5:{10}", contango1, contango2, contango3, contango4, contango5, vx0, vx1, vx2, vx3, vx4, vx5); } else if (m_updates.HasUpdatesFor("vx0", "vx1", "vx2")) { decimal vx0 = m_updates["vx0"].Mid; decimal vx1 = m_updates["vx1"].Mid; decimal vx2 = m_updates["vx2"].Mid; decimal contango1 = Contango(vx0, vx1); decimal contango2 = Contango(vx1, vx2); System.Console.WriteLine("{0}% {1}% vx0:{2} vx1:{3} vx2:{4}", contango1, contango2, vx0, vx1, vx2); } } }
public void Update(Form frm, PriceUpdate pu) { Update(frm, pu.Bid, pu.BidSize, pu.Ask, pu.AskSize); }
public void Start() { _pricesReader.SubscribeToChanges(prices => { var tasks = new List <Task>(); foreach (var price in prices) { tasks.Add(_priceStream.WriteToStreamAsync(_mapper.Map <PriceUpdate>(price), price.AssetPairId)); } Task.WhenAll(tasks).GetAwaiter().GetResult(); }); _candlesReader.SubscribeToChanges(candles => { var tasks = new List <Task>(); foreach (var candle in candles) { var key = $"{candle.AssetPairId}_{candle.PriceType}_{candle.TimeInterval}"; tasks.Add(_candlesStream.WriteToStreamAsync(_mapper.Map <CandleUpdate>(candle), key)); } Task.WhenAll(tasks).GetAwaiter().GetResult(); }); _tickersReader.SubscribeToChanges(tickers => { var tasks = new List <Task>(); foreach (var ticker in tickers) { var priceEntity = _pricesReader.Get(PriceEntity.GetPk(), ticker.AssetPairId); var priceUpdate = new PriceUpdate { AssetPairId = ticker.AssetPairId, VolumeBase24H = ticker.VolumeBase.ToString(CultureInfo.InvariantCulture), VolumeQuote24H = ticker.VolumeQuote.ToString(CultureInfo.InvariantCulture), PriceChange24H = ticker.PriceChange.ToString(CultureInfo.InvariantCulture), Timestamp = Timestamp.FromDateTime(ticker.UpdatedDt.ToUniversalTime()) }; if (priceEntity != null) { priceUpdate.Ask = priceEntity.Ask.ToString(CultureInfo.InvariantCulture); priceUpdate.Bid = priceEntity.Bid.ToString(CultureInfo.InvariantCulture); } tasks.Add(_priceStream.WriteToStreamAsync(priceUpdate, priceUpdate.AssetPairId)); } Task.WhenAll(tasks).GetAwaiter().GetResult(); }); _orderbooksReader.SubscribeToChanges(orderbooks => { var tasks = new List <Task>(); foreach (var orderbook in orderbooks) { var item = _mapper.Map <Orderbook>(orderbook); item.Asks.AddRange(_mapper.Map <List <Orderbook.Types.PriceVolume> >(orderbook.Asks)); item.Bids.AddRange(_mapper.Map <List <Orderbook.Types.PriceVolume> >(orderbook.Bids)); tasks.Add(_orderbookStream.WriteToStreamAsync(item, orderbook.AssetPairId)); } Task.WhenAll(tasks).GetAwaiter().GetResult(); }); _sessionsReader.SubscribeToChanges(sessions => { }); Console.WriteLine("Stream services started."); }