/// <inheritdoc /> public void Execute(admin_zeegzagContext db) { var alias = ";" + _currencyShort + ";"; var currencyId = CachingService.CurrencyIdByName(_currencyShort, () => db.CurrencyT.FirstOrDefault(c => c.ShortName == _currencyShort || c.Alias.Contains(alias))?.Id); if (!currencyId.HasValue) { if (_isActive.GetValueOrDefault(true)) { //add new coin (since we do not call savechanges() immediately, we do not have id yet. So txfee will be updated on next turn) db.CurrencyT.Add(new CurrencyT() { Name = _currencyLong ?? _currencyShort, ShortName = _currencyShort, }); DatabaseService.EnqueueBroadcast(437907950, $"New coin is added to ZeegZag: {_currencyShort}", new InlineKeyboardMarkup(new InlineKeyboardButton[] { new InlineKeyboardUrlButton("Advertise here", "https://www.zeegzag.com"), })); } } else { //update txfee var borsaCurrency = db.BorsaCurrencyT .Where(bc => bc.BorsaId == _exchangeId && bc.ToCurrencyId == currencyId).ToList(); foreach (var bc in borsaCurrency) { bc.TxFee = _txFee; if (_isActive.HasValue) { bc.Disabled = !_isActive.Value; } } } }
public void Execute(admin_zeegzagContext db) { var usdtId = CachingService.CurrencyIdByName("USDT", () => db.CurrencyT.FirstOrDefault(c => c.ShortName == "USDT")?.Id); if (UsdConverters == null) { UsdConverters = db.BorsaCurrencyT .Where(bc => bc.FromCurrencyId == usdtId && (bc.ToCurrency.ShortName == "BTC" || bc.ToCurrency.ShortName == "ETH")) .ToList() .ToLookup(bc => bc.BorsaId, bc => bc); } var borsaId = _borsaCurrency.BorsaId; var fromId = _borsaCurrency.FromCurrencyId; var toId = _borsaCurrency.ToCurrencyId; //if has its own usd converter from this market if (db.BorsaCurrencyT.Any(bc => bc.BorsaId == borsaId && bc.FromCurrencyId == usdtId && bc.ToCurrencyId == toId && bc.AutoGenerated != true)) { return; } var converter = UsdConverters[_borsaCurrency.BorsaId].FirstOrDefault(bc => bc.ToCurrencyId == fromId); //USD-BTC == BTC-MCO //From-To == From-To if (converter == null) { return; } var rate = converter.Price; var price = _borsaCurrency.Price * rate; BorsaCurrencyT generated; var key = _borsaCurrency.BorsaId + "-" + _borsaCurrency.ToCurrencyId; if (Cache.ContainsKey(key)) { generated = Cache[key]; } else { generated = db.BorsaCurrencyT.FirstOrDefault(bc => bc.BorsaId == borsaId && bc.FromCurrencyId == usdtId && bc.ToCurrencyId == toId); if (generated == null) { generated = new BorsaCurrencyT() { BorsaId = _borsaCurrency.BorsaId, FromCurrencyId = usdtId.Value, ToCurrencyId = toId, AutoGenerated = true, }; try { db.BorsaCurrencyT.Add(generated); } catch (Exception e) { Console.WriteLine("Error on add: " + e); } Cache[key] = generated; } else { if (generated.LastUpdate.HasValue) { db.HistoryT.Add(new HistoryT() { BorsaCurrencyId = generated.Id, EntryDate = generated.LastUpdate.Value, Price = generated.Price, }); } } } generated.Price = price; generated.LastUpdate = DateTime.Now; }