示例#1
0
        public async Task <IActionResult> Default([FromServices] KyubeyContext db, [FromServices] ITokenRepository _tokenRepository, string id, CancellationToken cancellationToken)
        {
            var token = await db.Tokens
                        .Include(x => x.Curve)
                        .SingleOrDefaultAsync(x => x.Id == id &&
                                              x.Status == TokenStatus.Active, cancellationToken);

            if (token == null)
            {
                return(Prompt(x =>
                {
                    x.Title = SR["Token not found"];
                    x.Details = SR["The token {0} is not found", id];
                    x.StatusCode = 404;
                }));
            }

            ViewBag.Otc = await db.Otcs.SingleOrDefaultAsync(x => x.Id == id, cancellationToken);

            ViewBag.Bancor = await db.Bancors.SingleOrDefaultAsync(x => x.Id == id, cancellationToken);

            ViewBag.Curve     = token.Curve;
            ViewBag.TokenInfo = _tokenRepository.GetOne(id);

            return(View(await db.Tokens.SingleAsync(x => x.Id == id && x.Status == TokenStatus.Active, cancellationToken)));
        }
示例#2
0
        public async Task <IActionResult> WordingAsync(
            string id,
            GetBaseRequest request,
            [FromServices] KyubeyContext db,
            [FromServices] TokenRepositoryFactory tokenRepositoryFactory,
            CancellationToken cancellationToken)
        {
            var dbToken = await db.Tokens.FirstOrDefaultAsync(x => x.Id == id && x.Status == TokenStatus.Active, cancellationToken);

            if (dbToken == null)
            {
                return(ApiResult(404, "not found this token"));
            }
            var tokenRepository = await tokenRepositoryFactory.CreateAsync(request.Lang);

            var banners = tokenRepository.GetTokenIncubationBannereRelativePaths(id, request.Lang).Select(x => $"/token_assets/" + x).ToList();

            var updates = tokenRepository.GetTokenIncubatorUpdates(id, request.Lang)?.OrderBy(x => x.Time)?.OrderByDescending(x => x.Time).ToList();

            var response = new GetWordingResponse()
            {
                TokenId     = id,
                Description = tokenRepository.GetTokenDescription(id, request.Lang),
                Detail      = tokenRepository.GetTokenIncubationDetail(id, request.Lang),
                Updates     = updates,
                Sliders     = banners
            };

            return(ApiResult(response));
        }
示例#3
0
        public void PollIboActions(IConfiguration config, KyubeyContext db, ITokenRepository tokenRepository)
        {
            try
            {
                var tokens = db.Tokens
                             .Where(x => x.HasIncubation)
                             .ToList();

                foreach (var x in tokens)
                {
                    var token = tokenRepository.GetOne(x.Id);
                    if (token.Incubation == null ||
                        token.Basic == null ||
                        token.Basic.Contract == null ||
                        string.IsNullOrEmpty(token.Basic.Contract.Transfer))
                    {
                        continue;
                    }
                    TryHandleIboActionAsync(config, db, x.Id, tokenRepository).Wait();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }
示例#4
0
        public async Task <IActionResult> BuyData(
            [FromServices] KyubeyContext db,
            [FromServices] IConfiguration config,
            double?min,
            double?max,
            string id,
            CancellationToken token)
        {
            var orders = await db.DexBuyOrders
                         .Where(x => x.TokenId == id)
                         .OrderByDescending(x => x.UnitPrice)
                         .Take(15)
                         .ToListAsync();

            var totalMax = 0.0;

            if (orders.Count > 0)
            {
                totalMax = await db.DexBuyOrders
                           .Where(x => x.TokenId == id)
                           .Select(x => x.Bid)
                           .MaxAsync(token);
            }

            var ret = orders
                      .Select(x => new
            {
                unit     = x.UnitPrice,
                amount   = x.Ask,
                total    = x.Bid,
                totalMax = totalMax
            });

            return(Json(ret));
        }
示例#5
0
        private async Task TryHandleIboActionAsync(
            IConfiguration config, KyubeyContext db,
            string tokenId, ITokenRepository tokenRepository)
        {
            while (true)
            {
                var actions = await LookupIboActionAsync(config, db, tokenId, tokenRepository);

                foreach (var act in actions)
                {
                    Console.WriteLine($"Handling action log {act.account_action_seq} {act.action_trace.act.name}");
                    var blockTime = TimeZoneInfo.ConvertTimeToUtc(Convert.ToDateTime(act.block_time + 'Z'));
                    switch (act.action_trace.act.name)
                    {
                    case "transfer":
                        var token = tokenRepository.GetOne(tokenId);
                        await HandleRaiseLogAsync(db, act.action_trace.act.data, blockTime, tokenId, token.Basic.Contract.Transfer);

                        break;

                    default:
                        continue;
                    }
                }

                if (actions.Count() < 100)
                {
                    break;
                }
            }
        }
示例#6
0
        private async Task CalculateOTCAsync(IConfiguration config, KyubeyContext db)
        {
            using (var txClient = new HttpClient {
                BaseAddress = new Uri(config["TransactionNodeBackup"])
            })
            {
                foreach (var x in await db.Otcs.ToListAsync())
                {
                    try
                    {
                        var last = await db.MatchReceipts
                                   .Where(y => y.TokenId == x.Id)
                                   .LastOrDefaultAsync();

                        var last24 = await db.MatchReceipts
                                     .Where(y => y.TokenId == x.Id)
                                     .Where(y => y.Time < DateTime.UtcNow.AddDays(-1))
                                     .LastOrDefaultAsync();

                        if (last == null)
                        {
                            continue;
                        }

                        var price   = last.UnitPrice;
                        var price24 = last24?.UnitPrice;

                        try
                        {
                            using (var kClient = new HttpClient {
                                BaseAddress = new Uri(config["Kdata"])
                            })
                            {
                                Console.WriteLine($"Uploading {x.Id} data...");
                                using (await kClient.PostAsJsonAsync($"/api/Candlestick", new
                                {
                                    values = new[] {
                                        new
                                        {
                                            catalog = "kyubey-dex-" + x.Id,
                                            price = price,
                                            utcTime = DateTime.UtcNow
                                        }
                                    }
                                })) { }
                            }
                        }
                        catch { }

                        x.Price  = price;
                        x.Change = price / (price24 ?? 1.0) - 1.0;
                        await db.SaveChangesAsync();
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.ToString());
                    }
                }
            }
        }
示例#7
0
        public async Task <IActionResult> GetCurrentDelegate([FromServices] KyubeyContext db, string account, CancellationToken cancellationToken)
        {
            var buy = await db.DexBuyOrders.Where(x => x.Account == account).ToListAsync(cancellationToken);

            var sell = await db.DexSellOrders.Where(x => x.Account == account).ToListAsync(cancellationToken);

            var ret = new List <GetCurrentOrdersResponse>();

            ret.AddRange(buy.Select(x => new GetCurrentOrdersResponse
            {
                Id     = x.Id,
                Symbol = x.TokenId,
                Type   = "buy",
                Amount = x.Ask,
                Price  = x.UnitPrice,
                Total  = x.Bid,
                Time   = x.Time
            }));

            ret.AddRange(sell.Select(x => new GetCurrentOrdersResponse
            {
                Id     = x.Id,
                Symbol = x.TokenId,
                Type   = "sell",
                Amount = x.Bid,
                Price  = x.UnitPrice,
                Total  = x.Ask,
                Time   = x.Time
            }));

            return(ApiResult(ret.OrderByDescending(x => x.Time)));
        }
示例#8
0
        public async Task <IActionResult> Javascript([FromServices] KyubeyContext db, string id, CancellationToken cancellationToken)
        {
            var token = await db.Bancors
                        .SingleAsync(x => x.Id == id, cancellationToken);

            return(Content(token.TradeJavascript, "application/x-javascript"));
        }
示例#9
0
 public TokenAPIRopository(INodeServices node, KyubeyContext db, ITokenRepository tokenRepository, IConfiguration config)
 {
     _node            = node;
     _db              = db;
     _tokenRepository = tokenRepository;
     _config          = config;
 }
示例#10
0
        public async Task <IActionResult> Dex([FromServices] KyubeyContext db, [FromServices] ITokenRepository _tokenRepository, string token = null, CancellationToken cancellationToken = default)
        {
            var tokenStaticInfoList = _tokenRepository.GetAll();

            if (token != null)
            {
                token = token.ToUpper();
            }
            ViewBag.SearchToken = token;
            var ret    = new List <TokenDisplay>();
            var tokens = await DB.Tokens.ToListAsync(cancellationToken);

            foreach (var x in tokens)
            {
                if (!x.HasDex && !x.HasContractExchange)
                {
                    continue;
                }

                var t = new TokenDisplay
                {
                    Id                 = x.Id,
                    Name               = x.Name,
                    Protocol           = x.CurveId ?? SR["Unknown"],
                    ExchangeInDex      = x.HasDex,
                    ExchangeInContract = x.HasContractExchange
                };

                ret.Add(t);
            }

            return(View(ret));
        }
示例#11
0
        private async Task HandleBuyReceiptAsync(KyubeyContext db, ActionDataWrap data, DateTime time)
        {
            try
            {
                var token = data.data.ask.Split(' ')[1];
                var order = await db.DexBuyOrders.SingleOrDefaultAsync(x => x.Id == data.data.id && x.TokenId == token);

                if (order != null)
                {
                    db.DexBuyOrders.Remove(order);
                    await db.SaveChangesAsync();
                }
                order = new DexBuyOrder
                {
                    Id        = data.data.id,
                    Account   = data.data.account,
                    Ask       = Convert.ToDouble(data.data.ask.Split(' ')[0]),
                    Bid       = Convert.ToDouble(data.data.bid.Split(' ')[0]),
                    UnitPrice = data.data.unit_price / 10000.0,
                    Time      = time,
                    TokenId   = token
                };
                db.DexBuyOrders.Add(order);
                await db.SaveChangesAsync();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }
示例#12
0
        public async Task <IActionResult> GetFavorite([FromServices] KyubeyContext db, string account, CancellationToken cancellationToken)
        {
            var last = await db.MatchReceipts
                       .OrderByDescending(x => x.Time)
                       .GroupBy(x => x.TokenId)
                       .Select(x => new
            {
                TokenId = x.Key,
                Last    = x.FirstOrDefault()
            })
                       .ToListAsync(cancellationToken);

            var last24 = await db.MatchReceipts
                         .Where(y => y.Time < DateTime.UtcNow.AddDays(-1))
                         .OrderByDescending(x => x.Time)
                         .GroupBy(x => x.TokenId)
                         .Select(x => new
            {
                TokenId = x.Key,
                Last    = x.FirstOrDefault()
            })
                         .ToListAsync(cancellationToken);

            var lastUnitPrice = last.Select(x => new
            {
                id     = x.TokenId,
                price  = x.Last?.UnitPrice,
                change = (x.Last?.UnitPrice == null ||
                          last24?.FirstOrDefault(l => l.TokenId == x.TokenId)?.Last?.UnitPrice == null ||
                          last24?.FirstOrDefault(l => l.TokenId == x.TokenId)?.Last?.UnitPrice == 0)
                ? 0 : ((x.Last?.UnitPrice / last24?.FirstOrDefault(l => l.TokenId == x.TokenId)?.Last?.UnitPrice) - 1)
            });

            var tokendUnitPriceResult = (await db.Tokens.Where(x => x.Status == TokenStatus.Active).ToListAsync(cancellationToken)).Select(x => new
            {
                id     = x.Id,
                price  = lastUnitPrice.FirstOrDefault(o => o.id == x.Id)?.price ?? 0,
                change = lastUnitPrice.FirstOrDefault(o => o.id == x.Id)?.change ?? 0
            }).ToList();

            var favorite = await db.Favorites
                           .Where(x => x.Account == account)
                           .ToListAsync(cancellationToken);

            var responseData = new List <GetFavoriteResponse> {
            };

            responseData.AddRange(tokendUnitPriceResult.Select(
                                      x => new GetFavoriteResponse
            {
                Symbol    = x.id,
                UnitPrice = x.price,
                Change    = x.change,
                Favorite  = favorite.Exists(y => y.TokenId == x.id)
            }
                                      ));

            return(ApiResult(responseData));
        }
示例#13
0
        public async Task <IActionResult> Candlestick([FromServices] KyubeyContext db, GetCandlestickRequest request, CancellationToken token)
        {
            var ticks = new TimeSpan(0, 0, request.Period);
            var begin = new DateTime(request.Begin.Ticks / ticks.Ticks * ticks.Ticks).ToUniversalTime();
            var end   = new DateTime(request.End.Ticks / ticks.Ticks * ticks.Ticks).ToUniversalTime();

            var data = await db.MatchReceipts
                       .Where(x => x.TokenId == request.Id)
                       .Where(x => x.Time < end)
                       .OrderBy(x => x.Time)
                       .GroupBy(x => x.Time >= begin ? x.Time.Ticks / ticks.Ticks * ticks.Ticks : 0)
                       .Select(x => new GetCandlestickResponse
            {
                Time    = new DateTime(x.Key),
                Min     = x.Select(y => y.UnitPrice).Min(),
                Max     = x.Select(y => y.UnitPrice).Max(),
                Opening = x.Select(y => y.UnitPrice).FirstOrDefault(),
                Closing = x.OrderByDescending(y => y.Time).Select(y => y.UnitPrice).FirstOrDefault(),
                Volume  = x.Count()
            })
                       .ToListAsync(token);

            if (data.Count <= 1)
            {
                return(ApiResult(data.Where(x => x.Time >= begin).OrderBy(x => x.Time)));
            }

            //repair data by ticks
            for (var i = begin; i < end; i = i.Add(ticks))
            {
                if (data.Any(x => x.Time == i))
                {
                    continue;
                }
                var prev = data
                           .Where(x => x.Time < i)
                           .OrderBy(x => x.Time)
                           .LastOrDefault();
                if (prev == null)
                {
                    continue;
                }
                data.Add(new GetCandlestickResponse
                {
                    Min     = prev.Closing,
                    Max     = prev.Closing,
                    Closing = prev.Closing,
                    Opening = prev.Closing,
                    Time    = i,
                    Volume  = 0
                });
            }

            var responseData = data.Where(x => x.Time >= begin).OrderBy(x => x.Time).ToList();

            responseData.ForEach(x => x.Time = x.Time.ToLocalTime());

            return(ApiResult(responseData));
        }
        void UpdateRaisedSeq(string token, int seq, KyubeyContext db)
        {
            var rowId = $"incubator_{token}_seq";
            var row   = db.Constants.FirstOrDefault(x => x.Id == rowId);

            row.Value = seq.ToString();
            db.SaveChanges();
        }
示例#15
0
        public async Task <IActionResult> OTC([FromServices] KyubeyContext db, CancellationToken cancellationToken)
        {
            var tokens = await db.Otcs
                         .Include(x => x.Token)
                         .Where(x => x.Status == Status.Active)
                         .OrderByDescending(x => x.Token.Priority)
                         .ToListAsync(cancellationToken);

            return(View(tokens));
        }
示例#16
0
        private async Task TryHandleDexActionAsync(IConfiguration config, KyubeyContext db)
        {
            while (true)
            {
                var actions = await LookupDexActionAsync(config, db);

                if (actions != null)
                {
                    foreach (var act in actions)
                    {
                        Console.WriteLine($"Handling action log {act.account_action_seq} {act.action_trace.act.name}");
                        var blockTime = TimeZoneInfo.ConvertTimeToUtc(Convert.ToDateTime(act.block_time + 'Z'));
                        switch (act.action_trace.act.name)
                        {
                        case "sellmatch":
                            await HandleSellMatchAsync(db, act.action_trace.act.data, blockTime);

                            break;

                        case "buymatch":
                            await HandleBuyMatchAsync(db, act.action_trace.act.data, blockTime);

                            break;

                        case "sellreceipt":
                            await HandleSellReceiptAsync(db, act.action_trace.act.data, blockTime);

                            break;

                        case "buyreceipt":
                            await HandleBuyReceiptAsync(db, act.action_trace.act.data, blockTime);

                            break;

                        case "cancelbuy":
                            await HandleCancelBuyAsync(db, act.action_trace.act.data, blockTime);

                            break;

                        case "cancelsell":
                            await HandleCancelSellAsync(db, act.action_trace.act.data, blockTime);

                            break;

                        default:
                            continue;
                        }
                    }
                }
                if (actions == null || actions.Count() < 100)
                {
                    break;
                }
            }
        }
示例#17
0
        public FavoriteTokenTests()
        {
            client = new CleosClient();
            config = JsonConvert.DeserializeObject <Config>(File.ReadAllText("config.json"));
            client.CreateWalletAsync("default", "/home/cleos-net/wallet/wallet.key").Wait();
            client.ImportPrivateKeyToWalletAsync(config.PrivateKey, "default").Wait();
            var builder = new DbContextOptionsBuilder();

            builder.UseMySql(config.MySql);
            db = new KyubeyContext(builder.Options);
        }
        async Task HandleRaiseCountAsync(KyubeyContext db, string token, DateTime startTime, DateTime endTime)
        {
            var currentRaisedSum = db.RaiseLogs.Where(x => x.TokenId == token && x.Timestamp >= startTime && x.Timestamp <= endTime).Select(x => x.Amount).Sum();
            var row = db.Tokens.FirstOrDefault(x => x.Id == token);

            if (row != null)
            {
                row.Raised = (decimal)currentRaisedSum;
                await db.SaveChangesAsync();
            }
        }
示例#19
0
        public async Task <IActionResult> Holders(
            [FromServices] KyubeyContext db,
            [FromServices] ITokenRepository _tokenRepository,
            string id,
            CancellationToken cancellationToken)
        {
            var token = await db.Tokens
                        .Include(x => x.Curve)
                        .SingleOrDefaultAsync(x => x.Id == id &&
                                              x.Status == TokenStatus.Active, cancellationToken);

            ViewBag.Otc = await db.Otcs.SingleOrDefaultAsync(x => x.Id == id, cancellationToken);

            ViewBag.Bancor = await db.Bancors.SingleOrDefaultAsync(x => x.Id == id, cancellationToken);

            if (token == null)
            {
                return(Prompt(x =>
                {
                    x.Title = SR["Token not found"];
                    x.Details = SR["The token {0} is not found", id];
                    x.StatusCode = 404;
                }));
            }
            var tokenInfo = _tokenRepository.GetOne(id);
            var cancel    = new CancellationTokenSource();

            cancel.CancelAfter(5000);
            try
            {
                using (var client = new HttpClient()
                {
                    BaseAddress = new Uri("https://cache.togetthere.cn")
                })
                    using (var resposne = await client.GetAsync($"/token/distributed/{tokenInfo.Basic.Contract.Transfer}/{token.Id}"))
                    {
                        var dic = await resposne.Content.ReadAsAsync <IDictionary <string, double> >();

                        ViewBag.Holders = dic.Select(x => new Holder
                        {
                            account = x.Key,
                            amount  = x.Value.ToString("0.0000") + " " + token.Id
                        })
                                          .Take(20)
                                          .ToList();
                    }
            }
            catch (TaskCanceledException)
            {
            }

            return(View(await db.Tokens.SingleAsync(x => x.Id == id && x.Status == TokenStatus.Active, cancellationToken)));
        }
示例#20
0
        public async Task <IActionResult> Icon([FromServices] KyubeyContext db, string id, CancellationToken cancellationToken)
        {
            var token = await db.Tokens.SingleAsync(x => x.Id == id && x.Status == TokenStatus.Active, cancellationToken);

            if (token.Icon == null || token.Icon.Length == 0)
            {
                return(File(System.IO.File.ReadAllBytes(Path.Combine("wwwroot", "img", "null.png")), "image/png", "icon.png"));
            }
            else
            {
                return(File(token.Icon, "image/png", "icon.png"));
            }
        }
示例#21
0
        public async Task <IActionResult> Pair([FromServices] KyubeyContext db, [FromServices] ITokenRepository _tokenRepository, string token, CancellationToken cancellationToken)
        {
            if (token != null)
            {
                token = token.ToUpper();
            }
            var otcTokens = _tokenRepository.GetAll().Select(x => x.Id).ToList();

            var last = await db.MatchReceipts
                       .Where(x => otcTokens.Contains(x.TokenId))
                       .Where(y => y.TokenId == token || token == null)
                       .GroupBy(x => x.TokenId)
                       .Select(x => new
            {
                TokenId = x.Key,
                Last    = x.LastOrDefault()
            })
                       .ToListAsync();



            var last24 = await db.MatchReceipts
                         .Where(x => otcTokens.Contains(x.TokenId))
                         .Where(y => y.TokenId == token || token == null)
                         .Where(y => y.Time < DateTime.UtcNow.AddDays(-1))
                         .GroupBy(x => x.TokenId)
                         .Select(x => new
            {
                TokenId = x.Key,
                Last    = x.LastOrDefault()
            })
                         .ToListAsync();



            var rOrdinal = last.Select(x => new
            {
                id     = x.TokenId,
                price  = x.Last?.UnitPrice ?? 0,
                change = (x.Last?.UnitPrice ?? 0) / (last24?.FirstOrDefault(l => l.TokenId == x.TokenId)?.Last?.UnitPrice - 1)
            });

            var r = db.Tokens.Where(x => x.Status == TokenStatus.Active).ToList().Select(x => new
            {
                id     = x.Id,
                price  = rOrdinal.FirstOrDefault(o => o.id == x.Id)?.price ?? 0,
                change = rOrdinal.FirstOrDefault(o => o.id == x.Id)?.change ?? 0
            });

            return(Json(r));
        }
示例#22
0
 private async Task CalculateOTCAsync(IConfiguration config, KyubeyContext db)
 {
     using (var txClient = new HttpClient {
         BaseAddress = new Uri(config["TransactionNode"])
     })
     {
         foreach (var x in await db.Otcs.ToListAsync())
         {
             try
             {
                 using (var tableResponse1 = await txClient.PostAsJsonAsync("/v1/chain/get_table_rows", new
                 {
                     code = "eosotcbackup",
                     scope = "eosio.token",
                     table = "order",
                     json = true,
                     limit = 65535
                 }))
                     using (var tableResponse2 = await txClient.PostAsJsonAsync("/v1/chain/get_table_rows", new
                     {
                         code = "eosotcbackup",
                         scope = x.Token.Contract,
                         table = "order",
                         json = true,
                         limit = 65535
                     }))
                     {
                         var rows1 = JsonConvert.DeserializeObject <OrderTable>((await tableResponse1.Content.ReadAsStringAsync()))
                                     .rows
                                     .Where(y => y.bid.quantity.EndsWith(x.Id) && y.bid.contract == x.Token.Contract)
                                     .Where(y => y.ask.quantity.EndsWith("EOS") && y.ask.quantity == "eosio.token");
                         var rows2 = JsonConvert.DeserializeObject <OrderTable>((await tableResponse2.Content.ReadAsStringAsync()))
                                     .rows
                                     .Where(y => y.ask.quantity.EndsWith(x.Id) && y.ask.contract == x.Token.Contract)
                                     .Where(y => y.bid.quantity.EndsWith("EOS") && y.bid.contract == "eosio.token");
                         x.Transactions = rows1.Count() + rows2.Count();
                         if (rows1.Count() > 0)
                         {
                             x.PriceMin = rows1.Min(y => Convert.ToDouble(y.ask.quantity.Split(' ')[0]) / Convert.ToDouble(y.bid.quantity.Split(' ')[0]));
                             x.PriceMax = rows1.Max(y => Convert.ToDouble(y.ask.quantity.Split(' ')[0]) / Convert.ToDouble(y.bid.quantity.Split(' ')[0]));
                         }
                         await db.SaveChangesAsync();
                     }
             }
             catch (Exception ex)
             {
                 Console.WriteLine(ex.ToString());
             }
         }
     }
 }
示例#23
0
        public async Task <IActionResult> ContractPrice(
            [FromServices] KyubeyContext db,
            [FromServices] IConfiguration config,
            string id,
            CancellationToken token)
        {
            var bancor = await db.Bancors.SingleOrDefaultAsync(x => x.Id == id);

            return(Json(new
            {
                BuyPrice = bancor.BuyPrice,
                SellPrice = bancor.SellPrice
            }));
        }
示例#24
0
        public async Task <IActionResult> RecentTransactionRecord([FromServices] KyubeyContext db, string symbol, CancellationToken token)
        {
            var responseData = await db.MatchReceipts
                               .Where(x => x.TokenId == symbol)
                               .OrderByDescending(x => x.Time)
                               .Take(21)
                               .ToListAsync(token);

            return(ApiResult(responseData.Take(20).Select(x => new GetRecentTransactionResponse
            {
                UnitPrice = x.UnitPrice,
                Amount = (x.IsSellMatch ? x.Bid : x.Ask),
                Time = x.Time,
                Growing = x.UnitPrice > (responseData.FirstOrDefault(g => g.Time < x.Time)?.UnitPrice ?? x.UnitPrice)
            }), new { symbol = symbol }));
        }
示例#25
0
        private async Task HandleCancelBuyAsync(KyubeyContext db, ActionDataWrap data, DateTime time)
        {
            try
            {
                var order = await db.DexBuyOrders.SingleOrDefaultAsync(x => x.Id == data.id && x.TokenId == data.symbol);

                if (order != null)
                {
                    db.DexBuyOrders.Remove(order);
                    await db.SaveChangesAsync();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }
        async Task HandleRaiseLogAsync(KyubeyContext db, int seq, string token, string account, string from, string to, decimal quantity, DateTime time)
        {
            var row = db.RaiseLogs.Where(x => x.TokenId == token && x.Seq == seq).FirstOrDefault();

            if (row == null && from != account && to == account)
            {
                db.RaiseLogs.Add(new RaiseLog
                {
                    Account   = from,
                    Amount    = (double)quantity,
                    Timestamp = time,
                    TokenId   = token,
                    Seq       = seq
                });
                await db.SaveChangesAsync();
            }
        }
示例#27
0
        public async Task <IActionResult> Index([FromServices] KyubeyContext db, [FromServices] ITokenRepository _tokenRepository)
        {
            var tokenInfoList = _tokenRepository.GetAll().ToList();
            var dbIncubations = await db.Tokens.Where(x => x.HasIncubation && x.Status == TokenStatus.Active).ToListAsync();

            var tokens = dbIncubations.OrderByDescending(x => x.Priority).Select(x => new TokenHandlerListViewModel()
            {
                Id             = x.Id,
                BannerSrc      = TokenTool.GetTokenIncubatorBannerUri(x.Id, _tokenRepository.GetTokenIncubationBannerPaths(x.Id, currentCulture).FirstOrDefault()),
                CurrentRaised  = Convert.ToDecimal(db.RaiseLogs.Where(y => y.TokenId == x.Id && y.Account.Length == 12).Select(y => y.Amount).Sum()),
                Introduction   = _tokenRepository.GetTokenIncubationDescription(x.Id, currentCulture),
                ShowGoExchange = true,
                TargetCredits  = tokenInfoList.FirstOrDefault(s => s.Id == x.Id)?.Incubation?.Goal ?? 0
            }).ToList();

            return(View(tokens));
        }
示例#28
0
        public async Task <IActionResult> Banner([FromServices] KyubeyContext db, string id, string fileName, CancellationToken cancellationToken)
        {
            var token = await db.Tokens.SingleAsync(x => x.Id == id && x.Status == TokenStatus.Active, cancellationToken);

            if (token == null)
            {
                return(NotFound());
            }
            var filePath = Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "Tokens", id, "slides", fileName + ".png");

            if (!System.IO.File.Exists(filePath))
            {
                return(File(System.IO.File.ReadAllBytes(Path.Combine("wwwroot", "img", "null.png")), "image/png", "icon.png"));
            }
            else
            {
                return(File(System.IO.File.ReadAllBytes(filePath), "image/png"));
            }
        }
示例#29
0
        public async Task <IActionResult> Javascript([FromServices] KyubeyContext db, string id, CancellationToken cancellationToken)
        {
            var token = await db.Tokens.SingleAsync(x => x.Id == id && x.Status == TokenStatus.Active, cancellationToken);

            if (token == null)
            {
                return(NotFound());
            }
            var filePath = Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "Tokens", id, "contract_exchange", "exchange.js");

            if (!System.IO.File.Exists(filePath))
            {
                return(NotFound());
            }
            else
            {
                return(File(System.IO.File.ReadAllBytes(filePath), "application/x-javascript"));
            }
        }
        int GetOrCreateRaisedSeq(string token, KyubeyContext db)
        {
            var rowId  = $"incubator_{token}_seq";
            var seqRow = db.Constants.Where(x => x.Id == rowId).FirstOrDefault();

            if (seqRow == null)
            {
                var newRow = new Constant()
                {
                    Id    = rowId,
                    Value = "0"
                };

                db.Constants.Add(newRow);
                db.SaveChanges();
                return(0);
            }
            return(Convert.ToInt32(seqRow.Value));
        }