Ejemplo n.º 1
0
        private void AddHistoricRow(BetResult b)
        {
            DataRow row = _dtHistoricBet.NewRow();

            row["Coin"]   = b.Coin;
            row["Profit"] = b.Profit;
            _dtHistoricBet.Rows.Add(row);
        }
Ejemplo n.º 2
0
        public static BetResult FromJSONDynamic(dynamic json, string coin)
        {
            BetResult s = new BetResult();

            s.Coin  = coin;
            s.BetID = json.BetID;
            s.Roll  = json.Roll;
            //s.UnderOver = json.UnderOver;
            //s.ClientSeed = json.ClientSeed;
            s.Target             = json.Target;
            s.Profit             = json.Profit;
            s.ServerSeed         = json.ServerSeed;
            s.NextServerSeedHash = json.NextServerSeedHash;
            return(s);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Place un pari avec les différents paramètres
        /// </summary>
        /// <param name="bet">Montant du pari</param>
        /// <param name="payout">Retour sur le pari</param>
        /// <param name="underOver">true : over target, false : under target</param>
        /// <param name="clientSeed">Graine pour le random</param>
        /// <param name="coin">Monnaie pour le pari</param>
        /// <param name="key">Clef d'accès API</param>
        /// <source>http://stackoverflow.com/questions/9145667/how-to-post-json-to-the-server</source>
        /// <returns>BetResult contenant la reponse du serveur ou null si exception</returns>
        private BetResult JsonPlaceBet(decimal bet, decimal payout, bool underOver,
                                       string coin, string key, string clientSeed = "somerandomseed")
        {
            string url            = "https://api.crypto-games.net/v1/placebet/" + coin + "/" + key;
            var    httpWebRequest = (HttpWebRequest)WebRequest.Create(url);

            httpWebRequest.ContentType = "application/json";
            httpWebRequest.Method      = "POST";

            string json = "";

            using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
            {
                json = new JavaScriptSerializer().Serialize(new
                {
                    Bet        = bet,
                    Payout     = payout,
                    UnderOver  = underOver,
                    ClientSeed = clientSeed
                });
                AddOutputLine("Bet placed : " + json);
                streamWriter.Write(json);
            }

            using (var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse())
                using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
                {
                    var result = streamReader.ReadToEnd();
                    //AddOutputLine($"Result bet brut : {result}");
                    dynamic resJson = System.Web.Helpers.Json.Decode(result);
                    try
                    {
                        BetResult b = BetResult.FromJSONDynamic(resJson, coin);
                        AddOutputLine($"Result: {b}");
                        AddHistoricRow(b);
                        RefreshGridViewHistoric();
                        return(b);
                    }
                    catch (Exception e)
                    {
                        AddOutputLine($"Result brut : {result}");
                        AddOutputLine($"EXCEPTION : {e.ToString()}");
                        return(null);
                    }
                }
        }