Exemplo n.º 1
0
        public void SetUnits(int userId, int entityId, int units)
        {
            List <SqlParameter> prms = new List <SqlParameter> {
                new SqlParameter("@USERID", userId),
                new SqlParameter("@ENTITYID", entityId),
                new SqlParameter("@UNITS", units)
            };

            DBUtility.ExecuteQuery(opts.ConnectionString, "spUpdateUserUnits", prms);
        }
Exemplo n.º 2
0
 public void MarginTransfer(Order newOrder, int userId, int entityId, IContractCall contract, Guid orderId)
 {
     //SHORT SELL: FOR EVERY 1 UNIT LETS TRANSFER $100 INTO THEIR MARGIN ACCOUNT
     if (newOrder.TradeTypeId == (int)TradeType.ShortSell)
     {
         double        transferAmount = Convert.ToDouble(newOrder.Quantity) * 100D;
         Task <string> txResult       = contract.TransferMargin(newOrder.PublicKey, newOrder.PublicKey, transferAmount, (int)MarginMove.BalanceToMargin, opts.GasAmount);
         txResult.Wait();
         var result = txResult.Result;
         //INSERT INTO DATABASE
         List <SqlParameter> prms = new List <SqlParameter>
         {
             new SqlParameter("@ORDERID", orderId),
             new SqlParameter("@USERID", userId),
             new SqlParameter("@PUBLICKEY", newOrder.PublicKey),
             new SqlParameter("@ENTITYID", entityId),
             new SqlParameter("@TRADETYPEID", newOrder.TradeTypeId),
             new SqlParameter("@PRICE", newOrder.Price),
             new SqlParameter("@QUANTITY", newOrder.Quantity),
             new SqlParameter("@TXHASH", result),
         };
         DBUtility.ExecuteQuery(opts.ConnectionString, "spInsertMargin", prms);
     }
 }
Exemplo n.º 3
0
        public static void LoadTrends(string sqlConnectionString, string twitterConsumerKey, string twitterConsumerSecret, string twitterAccessToken, string twitterAccessTokenSecret, Action <string> LogError)
        {
            var request = new RestRequest("1.1/trends/place.json", Method.GET);

            request.AddQueryParameter("id", "23424977");
            request.AddQueryParameter("result_type", "popular");

            var client = new RestClient("https://api.twitter.com")
            {
                Authenticator = OAuth1Authenticator.ForProtectedResource(
                    twitterConsumerKey,
                    twitterConsumerSecret,
                    twitterAccessToken,
                    twitterAccessTokenSecret)
            };

            IRestResponse response  = client.Execute(request);
            var           content   = response.Content; // raw content as string
            dynamic       stuff     = JsonConvert.DeserializeObject(content);
            string        startTime = DBUtility.ExecuteScalar(sqlConnectionString, "SELECT FORMAT(GETDATE() , 'M/d/yy HH:mm')").ToString();

            bool updatesMade = false;

            foreach (JObject item in stuff)
            {
                foreach (var trend in item["trends"])
                {
                    string trendName = "";
                    double?score     = 0;

                    try
                    {
                        int volume = 0;
                        Int32.TryParse(trend["tweet_volume"].ToString(), out volume);
                        List <SqlParameter> sparams = new List <SqlParameter>();

                        trendName = trend["name"].ToString();
                        var tweets = GetTweetsAsync(trendName, 10, twitterConsumerKey, twitterConsumerSecret, twitterAccessToken, twitterAccessTokenSecret);

                        if (tweets == null || volume == 0)
                        {
                            continue;
                        }

                        score = GetVaderSentAvgAsync(tweets.Result).Result;

                        sparams.Add(new SqlParameter("@NAME", trendName));
                        sparams.Add(new SqlParameter("@URL", trend["url"].ToString()));
                        sparams.Add(new SqlParameter("@TWEETVOLUME", volume));
                        sparams.Add(new SqlParameter("@AVGSENTIMENT", score));
                        sparams.Add(new SqlParameter("@USERENTRY", false));
                        sparams.Add(new SqlParameter("@DATE", startTime));
                        DBUtility.ExecuteQuery(sqlConnectionString, "spInsertTrend", sparams);
                        updatesMade = true;
                    }
                    catch (Exception e)
                    {
                        LogError($"Trend:{trendName} Score:{score} {e.ToString()}");
                    }
                }
            }

            // UPDATES WERE MADE LETS ZERO OUT ORPHANED TRENDS
            if (updatesMade)
            {
                var dt = DBUtility.GetDataTable(sqlConnectionString, "spSelectOrphanedTrends", new List <SqlParameter> {
                    new SqlParameter("@LOADTIME", startTime)
                });
                foreach (DataRow dr in dt.Rows)
                {
                    List <SqlParameter> sqlp = new List <SqlParameter>();
                    sqlp.Add(new SqlParameter("@NAME", dr["Name"].ToString()));
                    sqlp.Add(new SqlParameter("@URL", dr["URL"].ToString()));
                    sqlp.Add(new SqlParameter("@TWEETVOLUME", Convert.ToInt32(0)));
                    sqlp.Add(new SqlParameter("@AVGSENTIMENT", Convert.ToInt32(0)));
                    sqlp.Add(new SqlParameter("@USERENTRY", true));
                    sqlp.Add(new SqlParameter("@DATE", startTime));
                    DBUtility.ExecuteQuery(sqlConnectionString, "spInsertTrend", sqlp);
                }
            }
        }