Example #1
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 #2
0
        private void button2_Click_1(object sender, EventArgs e)
        {
            instrument inst = new instrument();

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