コード例 #1
0
ファイル: Services.cs プロジェクト: NunoJDCM/TDIN
        public string ActivateBuyOrder(string token, int id, int amount)
        {
            if (!Server.clients.ContainsKey(token))
            {
                return(NULL);
            }
            string username = (string)Server.clients[token];

            Console.WriteLine("ACTIVATE_BUY_ORDER " + username + " " + id + " " + amount);

            double quote = Database.GetQuotes(1)[0].value;

            int remaining = Server.DoBuyOrder(username, amount, quote);

            /* Order is kept in the database if it isn't fullfilled */
            if (remaining > 0)
            {
                dynamic res = Database.EditBuyOrder(id, remaining, 1);
                if (res == null)
                {
                    return(NULL);
                }
            }
            else if (remaining == 0)
            {
                dynamic res = Database.RemoveBuyOrder(id);
                if (res == null)
                {
                    return(NULL);
                }
            }
            return(JsonConvert.SerializeObject(new { remaining = remaining }));
        }
コード例 #2
0
ファイル: Services.cs プロジェクト: NunoJDCM/TDIN
        public string AddBuyOrder(string token, int amount)
        {
            if (!Server.clients.ContainsKey(token))
            {
                return(NULL);
            }
            string username = (string)Server.clients[token];

            Console.WriteLine("ADD_BUY_ORDER " + username + " " + amount);

            if (amount <= 0)
            {
                return(NULL);
            }

            dynamic user  = Database.GetUser(username);
            double  quote = Database.GetQuotes(1)[0].value;

            if (user == null)
            {
                return(JsonConvert.SerializeObject(user));
            }

            int remaining = Server.DoBuyOrder(username, amount, quote);

            /* Order is added to the database if it isn't fullfilled */
            if (remaining > 0)
            {
                dynamic res = Database.AddBuyOrder(username, remaining);
                if (res == null)
                {
                    return(NULL);
                }
            }
            return(JsonConvert.SerializeObject(new { remaining = remaining }));
        }