Ejemplo n.º 1
0
 public void SettingEmptyValuesForDefaultAPICredentials_Should_ThrowException(string key, string secret)
 {
     // arrange
     // act
     // assert
     Assert.Throws(typeof(ArgumentException), () => BinanceDefaults.SetDefaultApiCredentials(key, secret));
 }
Ejemplo n.º 2
0
        //private IBinanceApiUser iuser;
        public VolumeInfo()
        {
            InitializeComponent();
            enableTrading = chkLiveTrading.Checked;
            BinanceDefaults.SetDefaultApiCredentials("jfjGYilh6zE3EN0k4ENvFHPfun1MmIhvZsYvOBPgmqExCKyYVb1gjyE2DyAo4Ks8", "eUYGrWr30TDy8iIrI3SVUXg1D7Jo4ysj1wvFuUCaLZlE3ZqcqqjLl08zcIcNr2xc");
            BinanceDefaults.SetDefaultLogVerbosity(LogVerbosity.Debug);
            //BinanceDefaults.SetDefaultLogOutput(Console.Out);
            using (var client = new BinanceClient())
            {
                BinanceAccountInfo           accountInfo = client.GetAccountInfo().Data;
                IEnumerable <BinanceBalance> candlearray = accountInfo.Balances.Select(e => e).Where(e => (e.Total + e.Locked) > 0); //
            }
            if (!System.IO.File.Exists(AppDomain.CurrentDomain.BaseDirectory + "\\Database.sqlite"))
            {
                SQLiteConnection.CreateFile("Database.sqlite");
            }
            _conn = new SQLiteConnection("Data Source=Database.sqlite;Version=3;");
            _conn.Open();
            try
            {
                string        sql     = "CREATE TABLE IF NOT EXISTS TICKERS (Symbol VARCHAR(20), active INT)";
                SQLiteCommand command = new SQLiteCommand(sql, _conn);
                command.ExecuteNonQueryAsync();
                sql     = "CREATE TABLE IF NOT EXISTS ORDERS (Symbol VARCHAR(20),Scanned DATE, Price decimal, Volume decimal, TakerBuyBaseAssetVolume decimal, TakerBuyQuoteAssetVolume decimal, NumberOfTrades INT, Hr8Av INT, NowPercent decimal, Min15Percent decimal, GreenCandles decimal)";
                command = new SQLiteCommand(sql, _conn);
                command.ExecuteNonQueryAsync();
                sql = "CREATE VIEW IF NOT EXISTS [V_Symbols] AS SELECT COUNT(Symbol), Symbol FROM ORDERS GROUP BY Symbol ORDER By COUNT(Symbol) DESC;";
                command.ExecuteNonQueryAsync();
            }
            catch (Exception ex)
            {
                //_conn.Close();
            }
            TableInit();
            //RefreshButton.Visible = false;
            FontSet();

            //this.loopThread = new Thread(new ThreadStart(this.GetVolumes));
            //this.loopThread.Start();

            this.backgroundWorkerView = new System.ComponentModel.BackgroundWorker();
            this.backgroundWorkerView.RunWorkerCompleted += new RunWorkerCompletedEventHandler(this.backgroundWorkerView_RunWorkerCompleted);
            this.backgroundWorkerView.DoWork             += new DoWorkEventHandler(backgroundWorkerView_DoWork);
            //Task.Run(() =>
            //{
            //GetVolumes();
            //});
            //this.Show();
        }
Ejemplo n.º 3
0
        public BinanceAccount(string coin,
                              decimal tradingFee,
                              decimal bitcoinTransferFee)
        {
            BinanceDefaults.SetDefaultApiCredentials("APIKEY", "APISECRET");

            // Setup coin
            this.TradeCoin = new Coin {
                Token = coin
            };
            this.Bitcoin = new Coin {
                Token = "BTC", TransferFee = bitcoinTransferFee
            };
            this.TradingFee = tradingFee;
        }
Ejemplo n.º 4
0
        public void SettingDefaults_Should_ImpactNewClients()
        {
            // arrange
            var stringBuilder = new StringBuilder();

            BinanceDefaults.SetDefaultApiCredentials("test", "test");
            BinanceDefaults.SetDefaultLogOutput(new StringWriter(stringBuilder));
            BinanceDefaults.SetDefaultLogVerbosity(LogVerbosity.Debug);

            var client = PrepareClient(JsonConvert.SerializeObject(new BinancePing()));

            // act
            Assert.DoesNotThrow(() => client.GetAccountInfo());

            // assert
            Assert.IsFalse(string.IsNullOrEmpty(stringBuilder.ToString()));
        }
Ejemplo n.º 5
0
        public BinanceAccount(string coin,
                              decimal tradingFee,
                              decimal bitcoinTransferFee,
                              string apiKey,
                              string apiSecret,
                              ILogger <BinanceAccount> logger)
        {
            BinanceDefaults.SetDefaultApiCredentials(apiKey, apiSecret);

            // Setup coin
            this.TradeCoin = new Coin {
                Token = coin
            };
            this.Bitcoin = new Coin {
                Token = "BTC", TransferFee = bitcoinTransferFee
            };
            this.TradingFee = tradingFee;
            this._logger    = logger;
        }
Ejemplo n.º 6
0
        static void Main(string[] args)
        {
            BinanceDefaults.SetDefaultApiCredentials("APIKEY", "APISECRET");
            BinanceDefaults.SetDefaultLogVerbosity(LogVerbosity.Debug);
            BinanceDefaults.SetDefaultLogOutput(Console.Out);

            using (var client = new BinanceClient())
                using (var socketClient = new BinanceSocketClient())
                {
                    // Public
                    var ping          = client.Ping();
                    var serverTime    = client.GetServerTime();
                    var orderBook     = client.GetOrderBook("BNBBTC", 10);
                    var aggTrades     = client.GetAggregatedTrades("BNBBTC", startTime: DateTime.UtcNow.AddMinutes(-2), endTime: DateTime.UtcNow, limit: 10);
                    var klines        = client.GetKlines("BNBBTC", KlineInterval.OneHour, startTime: DateTime.UtcNow.AddHours(-10), endTime: DateTime.UtcNow, limit: 10);
                    var prices24h     = client.Get24HPrices("BNBBTC");
                    var allPrices     = client.GetAllPrices();
                    var allBookPrices = client.GetAllBookPrices();

                    // Private
                    var openOrders      = client.GetOpenOrders("BNBBTC");
                    var allOrders       = client.GetAllOrders("BNBBTC");
                    var testOrderResult = client.PlaceTestOrder("BNBBTC", OrderSide.Buy, OrderType.Limit, TimeInForce.GoodTillCancel, 1, 1);
                    var queryOrder      = client.QueryOrder("BNBBTC", allOrders.Data[0].OrderId);
                    var orderResult     = client.PlaceOrder("BNBBTC", OrderSide.Sell, OrderType.Limit, TimeInForce.GoodTillCancel, 10, 0.0002);
                    var cancelResult    = client.CancelOrder("BNBBTC", orderResult.Data.OrderId);
                    var accountInfo     = client.GetAccountInfo();
                    var myTrades        = client.GetMyTrades("BNBBTC");


                    // Withdrawal/deposit
                    var withdrawalHistory = client.GetWithdrawHistory();
                    var depositHistory    = client.GetDepositHistory();
                    var withdraw          = client.Withdraw("ASSET", "ADDRESS", 0);


                    // Streams
                    var successDepth = socketClient.SubscribeToDepthStream("bnbbtc", (data) =>
                    {
                        // handle data
                    });
                    var successTrades = socketClient.SubscribeToTradesStream("bnbbtc", (data) =>
                    {
                        // handle data
                    });
                    var successKline = socketClient.SubscribeToKlineStream("bnbbtc", KlineInterval.OneMinute, (data) =>
                    {
                        // handle data
                    });

                    var successStart   = client.StartUserStream();
                    var successAccount = socketClient.SubscribeToAccountUpdateStream(successStart.Data.ListenKey, (data) =>
                    {
                        // handle data
                    });
                    var successOrder = socketClient.SubscribeToOrderUpdateStream(successStart.Data.ListenKey, (data) =>
                    {
                        // handle data
                    });

                    socketClient.UnsubscribeFromStream(successDepth.Data);
                    socketClient.UnsubscribeFromAccountUpdateStream();
                    socketClient.UnsubscribeAllStreams();
                }

            Console.ReadLine();
        }
Ejemplo n.º 7
0
 static BinanceExchange()
 {
     BinanceDefaults.SetDefaultApiCredentials(AppSettings.Default.BinanceKey, AppSettings.Default.BinanceSecret);
 }