public MainWindow()
        {
            InitializeComponent();
            pauseTradingBtt.IsEnabled = false;

            tradingTimer          = new System.Timers.Timer();
            tradingTimer.Elapsed += new ElapsedEventHandler(TradeCycleOnCoinBase);
            tradingTimer.Interval = 100;

            analyzingTimer          = new System.Timers.Timer();;
            analyzingTimer.Elapsed += new ElapsedEventHandler(AnalyzeCycleOnCoinBaseAsync);
            analyzingTimer.Interval = 100;

            //create an authenticator with your apiKey, apiSecret and passphrase
            authenticator = new Authenticator("secret1", "secret2", "secret3");

            //create the CoinbasePro client
            coinbaseProClient = new CoinbasePro.CoinbaseProClient(authenticator);

            Task <Tuple <string, string> > task = Task.Run <Tuple <string, string> >(async() => await GetBTCAndUSDAccountIDs());

            BTCUSDAccIds = task.Result;
        }
        /// <summary>
        /// checks current status of orders
        /// removes orders if necessary
        /// </summary>
        /// <param name="currentBTCPrice">current market BTC price</param>
        /// <returns>string of details of current existing orders</returns>
        public static string DealWithExistingOrders(decimal currentBTCPrice, CoinbasePro.CoinbaseProClient coinbaseProClient)
        {
            var    saleAndBuyBTCsVolumeAtOptimal = GetSellAndBuyBTCsVolumeAtOptimalAsync();
            string filledOrderDetails            = "";

            Task.Run(async() =>
            {
                var fillResponse = await MainWindow.coinbaseProClient.FillsService.GetFillsByProductIdAsync(CoinbasePro.Shared.Types.ProductType.BtcUsd, 10000, 0);
                var pageIterator = fillResponse.GetEnumerator();
                while (pageIterator.MoveNext())
                {
                    var transIterator = pageIterator.Current.GetEnumerator();
                    while (transIterator.MoveNext())
                    {
                        filledOrderDetails += "ID: " + transIterator.Current.OrderId + "\t" +
                                              "BTCprice: " + transIterator.Current.Price + "\t" +
                                              "Volume: " + transIterator.Current.Size + "\t" +
                                              "Fee: " + transIterator.Current.Fee + "\t" +
                                              "TimeCreated:" + transIterator.Current.CreatedAt + "\n";
                    }
                }
            });
            if (!currentOpenOderId.Equals("") &&
                (Math.Abs(saleAndBuyBTCsVolumeAtOptimal.Result.Item1 - saleAndBuyBTCsVolumeAtOptimal.Result.Item2) < HyperParameters.DiffBTCsBetweenCurrSellAndBuyToCancelAll) &&
                ((turnOfBuying && (sellPriceOfBTC < currentBTCPrice + HyperParameters.BuySellVolumeIsBalanceAndOrderTooCloseCurrentBTCPrice)) ||
                 (!turnOfBuying && (buyPriceOfBTC > currentBTCPrice - HyperParameters.BuySellVolumeIsBalanceAndOrderTooCloseCurrentBTCPrice))))
            {
                CancelAllOrders();
            }
            else
            {
                ConsiderToCancelOpenOrders(
                    saleAndBuyBTCsVolumeAtOptimal.Result,
                    currentBTCPrice);
            }
            return(filledOrderDetails);
        }
Esempio n. 3
0
        static async System.Threading.Tasks.Task Main(string[] args)
        {
            //create an authenticator with your apiKey, apiSecret and passphrase
            var authenticator = new Authenticator(
                ConfigurationManager.AppSettings["apiKey"],
                ConfigurationManager.AppSettings["unsignedSignature"],
                ConfigurationManager.AppSettings["passPhrase"]
                );

            //create the CoinbasePro client
            var coinbaseProClient = new CoinbasePro.CoinbaseProClient(authenticator);

            List <ProductType> products = new List <ProductType> {
                //ProductType.BtcUsd,
                //ProductType.EthUsd,
                ProductType.XlmUsd,
                ProductType.BchUsd,
                ProductType.MkrUsd,
                ProductType.EosUsd,
                ProductType.RenUsd,
                ProductType.AdaUsd,
                ProductType.OxtUsd,
                ProductType.OmgUsd,
                ProductType.NknUsd,
                ProductType.LrcUsd,
                ProductType.AnkrUsd,
                ProductType.NuUsd,
                // ProductType.XrpUsd
            };

            Dictionary <string, string> DBNamesDict = new Dictionary <string, string>()
            {
                //{ "BtcUsd", "Bitcoin"},
                //{ "EthUsd", "Ethereum"},
                { "AnkrUsd", "ANKR" },
                { "AdaUsd", "Cardano" },
                { "EosUsd", "EOS" },
                { "LrcUsd", "Loopring" },
                { "MkrUsd", "Maker" },
                { "NknUsd", "NKN" },
                { "NuUsd", "NuCypher" },
                { "OmgUsd", "OmgNetwork" },
                { "OxtUsd", "Orchid" },
                { "RenUsd", "REN" },
                { "XlmUsd", "Stellar" },
                { "BchUsd", "BitcoinCash" }
                //{ "XrpUsd", "XRP" },
            };

            DateTime endTime = DateTime.UtcNow;

            foreach (var product in products)
            {
                string DBname = DBNamesDict[product.ToString()];

                // string latestTimestamp = DataAccess.GetMostRecentDataTimestamp(conn, DBname);
                DateTime startTime = new DateTime(2021, 1, 1);
                //if (!DateTime.TryParse(latestTimestamp, out startTime))
                //{
                //    startTime = DateTime.Now;
                //}


                var history = await coinbaseProClient.ProductsService.GetHistoricRatesAsync(
                    product,
                    startTime,
                    endTime,
                    CandleGranularity.Minutes1
                    );

                // Write to database
                SqlConnection conn           = DataAccess.GetDBConnection();
                int           recordsWritten = DataAccess.WriteCandleDataToDB(conn, history, DBname);

                // Print basic stats to console
                var current = history[0];
                Console.WriteLine($"Current Stats: {DBname}");
                Console.WriteLine("------------------");
                Console.WriteLine($"High:   {current.High}");
                Console.WriteLine($"Low:    {current.Low}");
                Console.WriteLine($"Open:   {current.Open}");
                Console.WriteLine($"Close:  {current.Close}");
                Console.WriteLine($"Volume: {current.Volume}");
                Console.WriteLine($"{recordsWritten} records written.");
                Console.WriteLine("------------------");
            }
        }