public decimal GetBaseCurrencyBalance(BinanceClient client, string symbol = "")
        {
            decimal            baseBalance = 0;
            BinanceAccountInfo accountInfo = new BinanceAccountInfo();

            try {
                if (string.IsNullOrEmpty(symbol))
                {
                    symbol = GetBaseCurrencySymbol();
                }

                accountInfo = GetAccountData(client);
                if (accountInfo.Balances != null && accountInfo.Balances.Count > 0)
                {
                    var baseCurrencyData = accountInfo.Balances.Where(a => a.Asset == symbol).FirstOrDefault();
                    if (baseCurrencyData != null)
                    {
                        baseBalance = baseCurrencyData.Free;
                    }
                }
            } catch (Exception ex) {
                _logger.LogException(ex);
            }
            return(baseBalance);
        }
示例#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();
        }
        private BinanceStreamAccountInfo Convert(BinanceAccountInfo ai)
        {
            var bai = new BinanceStreamAccountInfo();

            bai.Balances         = Convert(ai.Balances);
            bai.BuyerCommission  = ai.BuyerCommission;
            bai.CanDeposit       = ai.CanDeposit;
            bai.CanTrade         = ai.CanTrade;
            bai.CanWithdraw      = ai.CanWithdraw;
            bai.MakerCommission  = ai.MakerCommission;
            bai.SellerCommission = ai.SellerCommission;
            bai.TakerCommission  = ai.TakerCommission;
            bai.EventTime        = ai.UpdateTime;
            //bai.Event =
            return(bai);
        }
示例#4
0
        public void GetAccountInfo_Should_RespondWithAccountInfo()
        {
            // arrange
            var accountInfo = new BinanceAccountInfo()
            {
                BuyerCommission  = 0.1m,
                CanDeposit       = true,
                CanTrade         = false,
                CanWithdraw      = true,
                MakerCommission  = 0.2m,
                SellerCommission = 0.3m,
                TakerCommission  = 0.4m,
                Balances         = new List <BinanceBalance>()
                {
                    new BinanceBalance()
                    {
                        Asset  = "bnb",
                        Free   = 0.1m,
                        Locked = 0.2m
                    },
                    new BinanceBalance()
                    {
                        Asset  = "btc",
                        Free   = 0.3m,
                        Locked = 0.4m
                    }
                }
            };

            var client = TestHelpers.CreateResponseClient(accountInfo, new BinanceClientOptions()
            {
                ApiCredentials = new ApiCredentials("Test", "Test"),
                AutoTimestamp  = false
            });

            // act
            var result = client.GetAccountInfo();

            // assert
            Assert.IsTrue(result.Success);
            Assert.IsTrue(TestHelpers.AreEqual(accountInfo, result.Data, "Balances"));
            Assert.IsTrue(TestHelpers.AreEqual(accountInfo.Balances.ToList()[0], result.Data.Balances.ToList()[0]));
            Assert.IsTrue(TestHelpers.AreEqual(accountInfo.Balances.ToList()[1], result.Data.Balances.ToList()[1]));
        }
示例#5
0
        public void GetAccountInfo_Should_RespondWithAccountInfo()
        {
            // arrange
            var accountInfo = new BinanceAccountInfo()
            {
                BuyerCommission  = 0.1m,
                CanDeposit       = true,
                CanTrade         = false,
                CanWithdraw      = true,
                MakerCommission  = 0.2m,
                SellerCommission = 0.3m,
                TakerCommission  = 0.4m,
                Balances         = new List <BinanceBalance>()
                {
                    new BinanceBalance()
                    {
                        Asset  = "bnb",
                        Free   = 0.1m,
                        Locked = 0.2m
                    },
                    new BinanceBalance()
                    {
                        Asset  = "btc",
                        Free   = 0.3m,
                        Locked = 0.4m
                    }
                }
            };

            var objects = TestHelpers.PrepareClient(() => Construct(new BinanceClientOptions()
            {
                ApiCredentials = new ApiCredentials("Test", "Test"),
                AutoTimestamp  = false
            }), JsonConvert.SerializeObject(accountInfo));

            // act
            var result = objects.Client.GetAccountInfo();

            // assert
            Assert.IsTrue(result.Success);
            Assert.IsTrue(TestHelpers.PublicInstancePropertiesEqual(accountInfo, result.Data, "Balances"));
            Assert.IsTrue(TestHelpers.PublicInstancePropertiesEqual(accountInfo.Balances[0], result.Data.Balances[0]));
            Assert.IsTrue(TestHelpers.PublicInstancePropertiesEqual(accountInfo.Balances[1], result.Data.Balances[1]));
        }
        public BinanceAccountInfo GetAccountData(BinanceClient client)
        {
            BinanceAccountInfo accountInfo = new BinanceAccountInfo();

            try {
                var accountInfoData = client.GetAccountInfo();
                if (accountInfoData.Error != null)
                {
                    _logger.LogError(accountInfoData.Error.Message);
                }
                else
                {
                    accountInfo = accountInfoData.Data;
                }
            } catch (Exception ex) {
                _logger.LogException(ex);
            }
            return(accountInfo);
        }
        public void GetAccountInfo_Should_RespondWithAccountInfo()
        {
            // arrange
            var accountInfo = new BinanceAccountInfo()
            {
                BuyerCommission  = 0.1,
                CanDeposit       = true,
                CanTrade         = false,
                CanWithdraw      = true,
                MakerCommission  = 0.2,
                SellerCommission = 0.3,
                TakerCommission  = 0.4,
                Balances         = new List <BinanceBalance>()
                {
                    new BinanceBalance()
                    {
                        Asset  = "bnb",
                        Free   = 0.1,
                        Locked = 0.2
                    },
                    new BinanceBalance()
                    {
                        Asset  = "btc",
                        Free   = 0.3,
                        Locked = 0.4
                    }
                }
            };

            var client = PrepareClient(JsonConvert.SerializeObject(accountInfo));

            // act
            var result = client.GetAccountInfo();

            // assert
            Assert.IsTrue(result.Success);
            Assert.IsTrue(Compare.PublicInstancePropertiesEqual(accountInfo, result.Data, "Balances"));
            Assert.IsTrue(Compare.PublicInstancePropertiesEqual(accountInfo.Balances[0], result.Data.Balances[0]));
            Assert.IsTrue(Compare.PublicInstancePropertiesEqual(accountInfo.Balances[1], result.Data.Balances[1]));
        }
示例#8
0
        public static void InitGlobals()
        {
            var t = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);

            if (File.Exists(t + "/config.ini"))
            {
                // todo wat wat
                var ini = new CryptoCore.Classes.IniFile(t + "/config.ini");
                if (ini.KeyExists("binancy_key") && ini.KeyExists("binancy_secret"))
                {
                    Globals.DEFAULT_BINANCE_KEY    = ini.Read("binance_key");
                    Globals.DEFAULT_BINANCE_SECRET = ini.Read("binance_secret");
                }
            }

            adminBinanceClient = new BinanceClient();
            adminBinanceClient.SetApiCredentials(CryptoCore.Classes.Globals.DEFAULT_BINANCE_KEY,
                                                 CryptoCore.Classes.Globals.DEFAULT_BINANCE_SECRET); // just for candles

            var req = adminBinanceClient.GetAccountInfo();

            adminAccountInfo = req.Data;

            if (req.Error != null)
            {
                // error
                adminAccountInfo = null;
            }

            var usdtBalance = GetBalance("usdt");
            var btc         = GetBalance("btc");

            GoodMarkets = new List <string>();
            GoodMarkets.Add("BTCUSDT");
            GoodMarkets.Add("ETHUSDT");
            GoodMarkets.Add("BNBUSDT");
            GoodMarkets.Add("EOSUSDT");
            GoodMarkets.Add("BCHABCUSDT");
            GoodMarkets.Add("XRPUSDT");
            GoodMarkets.Add("LTCUSDT");
            GoodMarkets.Add("LINKUSDT");
            GoodMarkets.Add("USDCUSDT");
            GoodMarkets.Add("PAXUSDT");
            GoodMarkets.Add("TUSDUSDT");
            GoodMarkets.Add("TRXUSDT");
            GoodMarkets.Add("NEOUSDT");
            GoodMarkets.Add("ERDUSDT");
            GoodMarkets.Add("ADAUSDT");
            GoodMarkets.Add("BTTUSDT");
            GoodMarkets.Add("ETCUSDT");
            GoodMarkets.Add("ALGOUSDT");
            GoodMarkets.Add("WAVESUSDT");
            GoodMarkets.Add("ONTUSDT");
            GoodMarkets.Add("MATICUSDT");
            GoodMarkets.Add("ATOMUSDT");
            GoodMarkets.Add("XLMUSDT");
            GoodMarkets.Add("ONEUSDT");
            GoodMarkets.Add("ZECUSDT");
            GoodMarkets.Add("QTUMUSDT");
            GoodMarkets.Add("VETUSDT");
            GoodMarkets.Add("IOTAUSDT");
            GoodMarkets.Add("ICXUSDT");
            GoodMarkets.Add("XMRUSDT");
            GoodMarkets.Add("CELRUSDT");
            GoodMarkets.Add("ZILUSDT");
            GoodMarkets.Add("FETUSDT");
            GoodMarkets.Add("HOTUSDT");
            GoodMarkets.Add("DASHUSDT");
            GoodMarkets.Add("BATUSDT");
            GoodMarkets.Add("ENJUSDT");
            GoodMarkets.Add("DOGEUSDT");
            GoodMarkets.Add("FTMUSDT");
            GoodMarkets.Add("ZRXUSDT");
            GoodMarkets.Add("OMGUSDT");
            GoodMarkets.Add("THETAUSDT");
            GoodMarkets.Add("IOSTUSDT");
            GoodMarkets.Add("TFUELUSDT");
            GoodMarkets.Add("NANOUSDT");
            GoodMarkets.Add("NULSUSDT");
            GoodMarkets.Add("USDSUSDT");
            GoodMarkets.Add("MITHUSDT");
            GoodMarkets.Add("GTOUSDT");
            GoodMarkets.Add("ONGUSDT");
        }