Example #1
0
        public async Task <ServiceResponse <DbOrder> > SaveTransaction(double boughtFor, string buyId, string baseCoin, string targetCoin, double changeToSell, string sessionId, double stack, string stock)
        {
            using (var db = new CoinbotContext($"Data Source={_dbPath}"))
            {
                var order = new Order
                {
                    BuyId        = buyId,
                    Id           = Guid.NewGuid().ToString(),
                    BaseCoin     = baseCoin,
                    TargetCoin   = targetCoin,
                    BoughtFor    = boughtFor,
                    ChangeToSell = changeToSell,
                    ToSellFor    = boughtFor * (changeToSell + 1),
                    InsertedAt   = DateTime.Now,
                    SessionId    = sessionId,
                    Stack        = stack,
                    Stock        = stock.ToLowerInvariant(),
                    Bought       = false
                };

                db.Orders.Add(order);

                await db.SaveChangesAsync();

                return(new ServiceResponse <DbOrder>(0, _mapper.Map <DbOrder>(order), "Transaction saved to database"));
            }
        }
Example #2
0
        public async Task <ServiceResponse> TransactionOrderFinalized(string transactionId, double quantity)
        {
            using (var db = new CoinbotContext($"Data Source={_dbPath}"))
            {
                var item = db.Orders.FirstOrDefault(x => x.Id == transactionId);

                item.Sold         = true;
                item.UpdatedAt    = DateTime.Now;
                item.QuantitySold = quantity;

                await db.SaveChangesAsync();

                return(new ServiceResponse(0, "Sell transaction altered in database"));
            }
        }
Example #3
0
        public async Task <ServiceResponse> TransactionOrderPlaced(string transactionId, string sellId, double?soldFor = null)
        {
            using (var db = new CoinbotContext($"Data Source={_dbPath}"))
            {
                var item = db.Orders.FirstOrDefault(x => x.Id == transactionId);

                item.SellOrderPlaced = true;
                item.UpdatedAt       = DateTime.Now;
                item.SellId          = sellId;
                item.SoldFor         = soldFor != null ? soldFor : item.ToSellFor;

                await db.SaveChangesAsync();

                return(new ServiceResponse(0, "Transaction written to database"));
            }
        }
Example #4
0
        public async Task <ServiceResponse> SaveTick(string baseCoin, string targetCoin, string stock, double ask, double bid, double last, string sessionId)
        {
            using (var db = new CoinbotContext($"Data Source={_dbPath}"))
            {
                var result = db.Ticks.Add(new Tick {
                    Ask        = ask,
                    Bid        = bid,
                    Last       = last,
                    InsertedAt = DateTime.Now,
                    Stock      = stock.ToLowerInvariant(),
                    BaseCoin   = baseCoin,
                    TargetCoin = targetCoin,
                    SessionId  = sessionId
                });

                await db.SaveChangesAsync();

                return(new ServiceResponse(0, "Saved tick to database"));
            }
        }