Exemple #1
0
        async Task <string> CheckUserStock(MySqlCommand cmd, UserCommandType command)
        {
            cmd.CommandText = "get_user_stock";

            cmd.Parameters.AddWithValue("@pUserId", command.username);
            cmd.Parameters["@pUserId"].Direction = ParameterDirection.Input;
            cmd.Parameters.AddWithValue("@pStock", command.stockSymbol);
            cmd.Parameters["@pStock"].Direction = ParameterDirection.Input;
            cmd.Parameters.Add("@pStockAmount", DbType.Int32);
            cmd.Parameters["@pStockAmount"].Direction = ParameterDirection.Output;

            await cmd.ExecuteNonQueryAsync().ConfigureAwait(false);

            if (cmd.Parameters["@pStockAmount"].Value == DBNull.Value)
            {
                return(LogErrorEvent(command, "User does not exist or does not have this stock"));
            }
            if (Convert.ToInt32(cmd.Parameters["@pStockAmount"].Value) < command.funds)
            {
                return(LogErrorEvent(command, "Insufficient user stocks"));
            }

            command.fundsSpecified = false;
            return(await SellTriggerTimer.StartOrUpdateTimer(command).ConfigureAwait(false));;
        }
Exemple #2
0
        protected override async Task <string> DataReceived(UserCommandType command)
        {
            try
            {
                command.fundsSpecified = true;
                var msg = await SellTriggerTimer.StartOrUpdateTimer(command).ConfigureAwait(false);

                if (msg == null)
                {
                    return($"Trigger amount set successfully for stock {command.stockSymbol}");
                }
                return(LogErrorEvent(command, msg));
            }
            catch (Exception ex)
            {
                LogDebugEvent(command, ex.Message);
                return(LogErrorEvent(command, "Error processing command."));
            }
        }