コード例 #1
0
        public async Task <List <TradeSingle> > GetCompletedTrades()
        {
            var deserializer = new JsonResponseDeserializer();
            var info         = new ResponseDeserializerInfo();
            var tradeRes     = await _mfl.GetRecentTrade();

            var jsonString = await tradeRes.Content.ReadAsStringAsync();

            try //Single
            {
                var tradeSingle = deserializer.Deserialize <TradeTransactionSingle>(jsonString, tradeRes, info)
                                  .transactions.transaction;
                return(new List <TradeSingle> {
                    tradeSingle
                });
            }
            catch (Exception) { Console.WriteLine("not a single trade"); }

            try //multi
            {
                return(deserializer.Deserialize <TradeTransactionMulti>(jsonString, tradeRes, info)
                       .transactions.transaction);
            }
            catch (Exception) { return(null); }
        }
コード例 #2
0
 public async Task <List <TradeSingle> > GetCompletedTrades()
 {
     try
     {
         return((await _mfl.GetRecentTrade()).transactions.transaction);
     }
     catch (Exception) { return(null); }
 }
コード例 #3
0
        public async Task PostCompletedTradeToGroup()
        {
            var deserializer = new JsonResponseDeserializer();
            var info         = new ResponseDeserializerInfo();
            var tradeRes     = await _mfl.GetRecentTrade();

            var strForBot  = "";
            var jsonString = await tradeRes.Content.ReadAsStringAsync();

            var owner1  = "";
            var owner2  = "";
            var assets1 = "";
            var assets2 = "";

            try
            {
                //Single
                var tradeSingle = deserializer.Deserialize <TradeTransactionSingle>(jsonString, tradeRes, info)
                                  .transactions.transaction;
                DateTime tenMinAgo = DateTime.Now.AddMinutes(-11);
                var      tradeTime = DateTimeOffset.FromUnixTimeSeconds(Int64.Parse(tradeSingle.timestamp));
                // check if trade was not in the last 10 minutes to bail early
                if (tradeTime < tenMinAgo)
                {
                    return;
                }
                owners.TryGetValue(Int32.Parse(tradeSingle.franchise), out owner1);
                owners.TryGetValue(Int32.Parse(tradeSingle.franchise2), out owner2);
                strForBot += $"{_rumor.GetSources()}{owner1} and {owner2} have completed a trade. \n";

                var multiplePlayers1 = _rumor.CheckForMultiplePlayers(tradeSingle.franchise1_gave_up);
                var multiplePlayers2 = _rumor.CheckForMultiplePlayers(tradeSingle.franchise2_gave_up);
                assets1 = multiplePlayers1 ? await _rumor.ListTradeInfoWithMultiplePlayers(tradeSingle.franchise1_gave_up) : await _rumor.ListTradeInfoWithSinglePlayer(tradeSingle.franchise1_gave_up);

                assets2 = multiplePlayers2 ? await _rumor.ListTradeInfoWithMultiplePlayers(tradeSingle.franchise2_gave_up) : await _rumor.ListTradeInfoWithSinglePlayer(tradeSingle.franchise2_gave_up);

                strForBot += $"{owner1} sends: \n{assets1} \n{owner2} sends: \n{assets2}";

                await BotPost(strForBot);

                return;
            }
            catch (Exception e) { Console.WriteLine("not a single trade"); }

            try
            {
                //Multiple
                var multiTrade = deserializer.Deserialize <TradeTransactionMulti>(jsonString, tradeRes, info)
                                 .transactions.transaction;
                var tenMinAgo = DateTime.Now.AddMinutes(-11);
                foreach (var trade in multiTrade)
                {
                    var tradeTime = DateTimeOffset.FromUnixTimeSeconds(Int64.Parse(trade.timestamp));
                    // check if trade was not in the last 10 minutes to bail early
                    if (tradeTime >= tenMinAgo)
                    {
                        owners.TryGetValue(Int32.Parse(trade.franchise), out owner1);
                        owners.TryGetValue(Int32.Parse(trade.franchise2), out owner2);
                        strForBot += $"{_rumor.GetSources()}{owner1} and {owner2} have completed a trade. \n";

                        var multiplePlayers1 = _rumor.CheckForMultiplePlayers(trade.franchise1_gave_up);
                        var multiplePlayers2 = _rumor.CheckForMultiplePlayers(trade.franchise2_gave_up);
                        assets1 = multiplePlayers1 ? await _rumor.ListTradeInfoWithMultiplePlayers(trade.franchise1_gave_up) : await _rumor.ListTradeInfoWithSinglePlayer(trade.franchise1_gave_up);

                        assets2 = multiplePlayers2 ? await _rumor.ListTradeInfoWithMultiplePlayers(trade.franchise2_gave_up) : await _rumor.ListTradeInfoWithSinglePlayer(trade.franchise2_gave_up);

                        strForBot += $"{owner1} sends: \n{assets1} \n{owner2} sends: \n{assets2}";

                        await BotPost(strForBot);
                    }
                }
            }
            catch (Exception e) { Console.WriteLine("not a multi trade"); }
        }