Example #1
0
        public double GetInstrumentPrice(Account A, string Symbol)
        {
            string URL = "/api/v1/instrument/active";

            BitMEXApi Api = new BitMEXApi(A.APIKey, A.SecretKey);

            string Result = Api.QueryNonv1("GET", URL, null, true, true);

            Result = JsonHelper.FormatJson(Result);
            Result = Result.Remove(0, 1);


            string[] InstrumentList = Result.Split('}');

            foreach (string s in InstrumentList)
            {
                string str1 = s.Remove(0, 1);
                string str2 = str1.Insert(str1.Length - 1, "}");
                try
                {
                    var settings = new JsonSerializerSettings
                    {
                        NullValueHandling     = NullValueHandling.Ignore,
                        MissingMemberHandling = MissingMemberHandling.Ignore
                    };

                    instrument I = new instrument();
                    I = JsonConvert.DeserializeObject <instrument>(str2, settings);

                    if (I.symbol == Symbol)
                    {
                        Console.WriteLine(I.markPrice);
                        return(I.markPrice);
                    }
                }
                catch (Exception E)
                {
                    Console.WriteLine("Error: " + E.Message + " " + E.Source);
                }
            }
            return(0.0f);
        }
Example #2
0
        private void TrackPrice()
        {
            instrument I               = new instrument();
            bool       Tracking        = true;
            double     MarkPrice       = I.GetInstrumentPrice(A, this.comboBox_RecentTradesSymbol.Text);
            int        IncreaseCounter = 0;
            int        DecreaseCounter = 0;

            Console.WriteLine("Starting Mark Price: " + MarkPrice + " - Getting price trend please wait 20-30s");

            while (Tracking)
            {
                string Symbol = this.comboBox_RecentTradesSymbol.Text; //change to combobox

                double OldMarkPrice = MarkPrice;
                MarkPrice = I.GetInstrumentPrice(A, Symbol);
                if (MarkPrice > OldMarkPrice) //increase
                {
                    IncreaseCounter += 1;
                }

                if (MarkPrice < OldMarkPrice)
                {
                    DecreaseCounter += 1;
                }

                if (IncreaseCounter >= 20 || DecreaseCounter >= 20)
                {
                    if (IncreaseCounter > DecreaseCounter)
                    {
                        Console.WriteLine("Trend Increasing.");

                        //write to file: csv for input to AI program
                        using (System.IO.StreamWriter file =
                                   new System.IO.StreamWriter(@"C:\Users\pello\OneDrive\Desktop\BTC.csv", true))
                        {
                            file.WriteLine("{0},{1},{2},{3}", DateTime.Now, MarkPrice, "UP", MarkPrice + 5);
                        }

                        DecreaseCounter = 0;
                        IncreaseCounter = 0;
                    }
                    else if (DecreaseCounter > IncreaseCounter)
                    {
                        using (System.IO.StreamWriter file =
                                   new System.IO.StreamWriter(@"C:\Users\pello\OneDrive\Desktop\BTC.csv", true))
                        {
                            file.WriteLine("{0},{1},{2},{3}", DateTime.Now, MarkPrice, "DOWN", MarkPrice - 5);
                        }
                        Console.WriteLine("Trend Decreasing");
                        DecreaseCounter = 0;
                        IncreaseCounter = 0;
                    }
                }

                Thread.Sleep(1000);

                if (A.AutoTrading)
                {
                    //place shit order here
                    Transaction T = new Transaction();

                    if (IncreaseCounter > DecreaseCounter) //buy
                    {
                        //check open positions, we need to switch sides

                        if (T.CreateTransaction(A, true, 222, Transaction.OrderTypes.Limit, Convert.ToDecimal(MarkPrice), Symbol, "Buy"))
                        {
                            Console.WriteLine("Bought 222 contracts.");
                        }
                    }
                    else if (DecreaseCounter > IncreaseCounter) //sell
                    {
                        //check open positions, we need to switch sides


                        T.CreateTransaction(A, true, 222, Transaction.OrderTypes.Limit, Convert.ToDecimal(MarkPrice), Symbol, "Sell");
                        Console.WriteLine("Sold 222 contracts.");
                    }

                    DecreaseCounter = 0;
                    IncreaseCounter = 0;
                }
            }
        }
Example #3
0
        private void button2_Click_1(object sender, EventArgs e)
        {
            instrument inst = new instrument();

            inst.GetInstrumentPrice(A, this.comboBox_RecentTradesSymbol.Text);
        }