コード例 #1
0
        public async Task RefreshData(XCommasAccounts keys)
        {
            await base.RefreshData <DealViewModel>(async() =>
            {
                var botMgr   = new XCommasLayer(keys, _logger);
                var allDeals = (await botMgr.GetAllDeals()).OrderBy(x => x.Deal.Id).ToList();

                var cfg = new MapperConfigurationExpression();
                cfg.CreateMap <Deal, DealViewModel>();
                var mapperConfig = new MapperConfiguration(cfg);
                var mapper       = mapperConfig.CreateMapper();

                var result = new List <DealViewModel>();
                foreach (var dealWithExchangeInfo in allDeals)
                {
                    var dealViewModel = mapper.Map <Deal, DealViewModel>(dealWithExchangeInfo.Deal);
                    dealViewModel.XCommasAccountId   = dealWithExchangeInfo.XCommasAccount;
                    dealViewModel.XCommasAccountName = dealWithExchangeInfo.XCommasAccountName;
                    result.Add(dealViewModel);
                }
                return(result);
            },
                                                   new Tuple <string, int>[]
            {
                new Tuple <string, int>(nameof(DealViewModel.Id), 65),
                new Tuple <string, int>(nameof(DealViewModel.DealType), 50),
                new Tuple <string, int>(nameof(DealViewModel.XCommasAccountName), 100),
                new Tuple <string, int>(nameof(DealViewModel.Account), 100),
                new Tuple <string, int>(nameof(DealViewModel.BotId), 55),
                new Tuple <string, int>(nameof(DealViewModel.BotName), 130),
                new Tuple <string, int>(nameof(DealViewModel.Pair), 100),
                new Tuple <string, int>(nameof(DealViewModel.DealHasErrors), 50),
                new Tuple <string, int>(nameof(DealViewModel.ErrorMessage), 100),
                new Tuple <string, int>(nameof(DealViewModel.TakeProfit), 50),
                new Tuple <string, int>(nameof(DealViewModel.TakeProfitType), 70),
                new Tuple <string, int>(nameof(DealViewModel.IsTrailingEnabled), 70),
                new Tuple <string, int>(nameof(DealViewModel.TrailingDeviation), 90),
                new Tuple <string, int>(nameof(DealViewModel.TrailingMaxPrice), 80),
                new Tuple <string, int>(nameof(DealViewModel.BoughtAmount), 80),
                new Tuple <string, int>(nameof(DealViewModel.BoughtVolume), 80),
                new Tuple <string, int>(nameof(DealViewModel.BoughtAveragePrice), 80),
                new Tuple <string, int>(nameof(DealViewModel.SoldAmount), 80),
                new Tuple <string, int>(nameof(DealViewModel.SoldVolume), 80),
                new Tuple <string, int>(nameof(DealViewModel.SoldAveragePrice), 80),
                new Tuple <string, int>(nameof(DealViewModel.BaseOrderVolume), 80),
                new Tuple <string, int>(nameof(DealViewModel.BaseOrderVolumeType), 80),
                new Tuple <string, int>(nameof(DealViewModel.SafetyOrderVolume), 80),
                new Tuple <string, int>(nameof(DealViewModel.SafetyOrderVolumeType), 80),
                new Tuple <string, int>(nameof(DealViewModel.MartingaleCoefficient), 80),
                new Tuple <string, int>(nameof(DealViewModel.MaxSafetyOrders), 80),
                new Tuple <string, int>(nameof(DealViewModel.ActiveSafetyOrdersCount), 80),
                new Tuple <string, int>(nameof(DealViewModel.CompletedSafetyOrdersCount), 80),
                new Tuple <string, int>(nameof(DealViewModel.CurrentActiveSafetyOrdersCount), 80),
                new Tuple <string, int>(nameof(DealViewModel.SafetyOrderStepPercentage), 80),
                new Tuple <string, int>(nameof(DealViewModel.IsCancellable), 80),
                new Tuple <string, int>(nameof(DealViewModel.IsPanicSellable), 80),
                new Tuple <string, int>(nameof(DealViewModel.CreatedAt), 100),
                new Tuple <string, int>(nameof(DealViewModel.UpdatedAt), 100)
            });
        }
コード例 #2
0
        public void Save(XCommasAccounts accounts)
        {
            string json = JsonConvert.SerializeObject(accounts);
            string base64EncodedAccounts = Convert.ToBase64String(Encoding.UTF8.GetBytes(json));

            Properties.Settings.Default.Keys = base64EncodedAccounts;
            Properties.Settings.Default.Save();
        }
コード例 #3
0
        public CopyBotDialog(XCommasAccounts keys, ILogger logger)
        {
            _keys   = keys;
            _logger = logger;
            InitializeComponent();

            cmbIsEnabled.Items.Add("Same as original bot");
            cmbIsEnabled.Items.Add("Enabled");
            cmbIsEnabled.Items.Add("Disabled");
            cmbIsEnabled.SelectedIndex = 0;
        }
コード例 #4
0
        public Settings(bool persistSettings, string title, XCommasAccounts accounts)
        {
            InitializeComponent();
            chkPersist.Checked = persistSettings;
            Text = title;

            Accounts = new BindingList <XCommasAccount>(accounts.Accounts);

            listBox.DataSource    = Accounts;
            listBox.DisplayMember = nameof(XCommasAccount.Name);
            listBox.ValueMember   = nameof(XCommasAccount.Id);

            _viewLoaded = true;
        }
コード例 #5
0
        public void Init(XCommasAccounts keys, ILogger logger, IMessageBoxService mbs)
        {
            _mbs         = mbs;
            _keys        = keys;
            _logger      = logger;
            _eventBroker = ObjectContainer.EventBroker;
            _eventBroker.Subscribe <KeysChangedEventArgs>(args => this.RunInUiThread(() => RefreshData(args.Keys)));
            tableControl.Init(keys, logger, mbs);

            if (!keys.IsEmpty)
            {
                RefreshData(keys).ConfigureAwait(false);
            }
        }
コード例 #6
0
        private void GetOrMigrateSettings()
        {
            var apiKey = Properties.Settings.Default.ApiKey3Commas;
            var secret = Properties.Settings.Default.Secret3Commas;

            _keys = ObjectContainer.KeyManager.Read();
            if (!string.IsNullOrWhiteSpace(apiKey) && !string.IsNullOrWhiteSpace(secret) && _keys.IsEmpty)
            {
                _keys = new XCommasAccounts {
                    Accounts = new List <XCommasAccount> {
                        new XCommasAccount {
                            ApiKey = apiKey, Secret = secret, Name = "default"
                        }
                    }
                };
                ObjectContainer.KeyManager.Save(_keys);
            }
        }
コード例 #7
0
        public async void OnManageApiKeys()
        {
            var settingsPersisted = !string.IsNullOrWhiteSpace(Properties.Settings.Default.ApiKey3Commas);
            var settings          = new Settings.Settings(settingsPersisted, "3Commas Accounts", _keys);
            var dr = settings.ShowDialog();

            if (dr == DialogResult.OK)
            {
                _keys = new XCommasAccounts {
                    Accounts = settings.Accounts.ToList()
                };

                await LoadAccounts();

                _eventBroker.Publish(new KeysChangedEventArgs()
                {
                    Keys = _keys
                });
            }
        }
コード例 #8
0
        public XCommasAccounts Read()
        {
            var result = new XCommasAccounts();

            try
            {
                var accounts = Properties.Settings.Default.Keys;
                if (!string.IsNullOrWhiteSpace(accounts))
                {
                    byte[] byteArray = Convert.FromBase64String(accounts);
                    string jsonBack  = Encoding.UTF8.GetString(byteArray);
                    result = JsonConvert.DeserializeObject <XCommasAccounts>(jsonBack);
                }
            }
            catch (Exception e)
            {
                ObjectContainer.Logger?.LogError($"Error while reading accounts: {e}");
            }
            return(result);
        }
コード例 #9
0
        protected void Init(string entityName, XCommasAccounts keys)
        {
            _entityName = entityName;
            _keys       = keys;

            btnRefresh.Text       = $"Reload {entityName}";
            lblTotalCount.Text    = $"0 {_entityName} found:";
            lblVisibleCount.Text  = $"0 {_entityName} visible";
            lblSelectedCount.Text = $"0 {_entityName} selected";

            // Initialize DataSet
            _dataSet   = new DataSet();
            _dataTable = _dataSet.Tables.Add(entityName);

            // initialize BindingSource
            bindingSource.DataSource = _dataSet;

            // initialize Datagridview
            grid.SetDoubleBuffered();
        }
コード例 #10
0
        public async Task RefreshData(XCommasAccounts keys)
        {
            await base.RefreshData <GridBotViewModel>(async() =>
            {
                var botMgr  = new XCommasLayer(keys, _logger);
                var allBots = (await botMgr.GetAllGridBots()).OrderBy(x => x.Bot.Id).ToList();

                var cfg = new MapperConfigurationExpression();
                cfg.CreateMap <GridBot, GridBotViewModel>();
                var mapperConfig = new MapperConfiguration(cfg);
                var mapper       = mapperConfig.CreateMapper();

                var result = new List <GridBotViewModel>();
                foreach (var botWithExchangeInfo in allBots)
                {
                    var botViewModel = mapper.Map <GridBot, GridBotViewModel>(botWithExchangeInfo.Bot);
                    botViewModel.XCommasAccountId   = botWithExchangeInfo.XCommasAccount;
                    botViewModel.XCommasAccountName = botWithExchangeInfo.XCommasAccountName;
                    result.Add(botViewModel);
                }

                return(result);
            },
                                                      new[]
            {
                new Tuple <string, int>(nameof(GridBotViewModel.Id), 55),
                new Tuple <string, int>(nameof(GridBotViewModel.IsEnabled), 80),
                new Tuple <string, int>(nameof(GridBotViewModel.XCommasAccountName), 120),
                new Tuple <string, int>(nameof(GridBotViewModel.AccountName), 120),
                new Tuple <string, int>(nameof(GridBotViewModel.Name), 120),
                new Tuple <string, int>(nameof(GridBotViewModel.Pair), 100),
                // new Tuple<string, int>(nameof(GridBotViewModel.LeverageType), 80),
                // new Tuple<string, int>(nameof(GridBotViewModel.LeverageCustomValue), 80),
                new Tuple <string, int>(nameof(GridBotViewModel.UpperLimitPrice), 100),
                new Tuple <string, int>(nameof(GridBotViewModel.LowerLimitPrice), 100),
                new Tuple <string, int>(nameof(GridBotViewModel.GridsQuantity), 100),
                new Tuple <string, int>(nameof(GridBotViewModel.QuantityPerGrid), 100),
                new Tuple <string, int>(nameof(GridBotViewModel.CreatedAt), 100),
                new Tuple <string, int>(nameof(GridBotViewModel.UpdatedAt), 100),
            });
        }
コード例 #11
0
 public void InitGrids(XCommasAccounts keys, ILogger logger, IMessageBoxService mbs)
 {
     manageBotControl.Init(keys, logger, mbs);
     manageGridBotControl.Init(keys, logger, mbs);
     manageDealControl.Init(keys, logger, mbs);
 }
コード例 #12
0
        public async Task RefreshData(XCommasAccounts keys)
        {
            await base.RefreshData <BotViewModel>(async() =>
            {
                var botMgr  = new XCommasLayer(keys, _logger);
                var allBots = (await botMgr.GetAllBots()).OrderBy(x => x.Bot.Id).ToList();

                var cfg = new MapperConfigurationExpression();
                cfg.CreateMap <Bot, BotViewModel>();
                var mapperConfig = new MapperConfiguration(cfg);
                var mapper       = mapperConfig.CreateMapper();

                var result = new List <BotViewModel>();
                foreach (var botWithExchangeInfo in allBots)
                {
                    var botViewModel = mapper.Map <Bot, BotViewModel>(botWithExchangeInfo.Bot);
                    botViewModel.XCommasAccountId   = botWithExchangeInfo.XCommasAccount;
                    botViewModel.XCommasAccountName = botWithExchangeInfo.XCommasAccountName;
                    result.Add(botViewModel);
                }
                return(result);
            },
                                                  new[]
            {
                new Tuple <string, int>(nameof(BotViewModel.Id), 55),
                new Tuple <string, int>(nameof(BotViewModel.BotType), 70),
                new Tuple <string, int>(nameof(BotViewModel.IsEnabled), 65),
                new Tuple <string, int>(nameof(BotViewModel.XCommasAccountName), 120),
                new Tuple <string, int>(nameof(BotViewModel.AccountName), 120),
                new Tuple <string, int>(nameof(BotViewModel.Name), 120),
                new Tuple <string, int>(nameof(BotViewModel.Strategy), 70),
                new Tuple <string, int>(nameof(BotViewModel.Pair), 100),
                new Tuple <string, int>(nameof(BotViewModel.MaxActiveDeals), 100),
                new Tuple <string, int>(nameof(BotViewModel.ActiveDealsCount), 100),
                new Tuple <string, int>(nameof(BotViewModel.TakeProfit), 50),
                new Tuple <string, int>(nameof(BotViewModel.TakeProfitType), 70),
                new Tuple <string, int>(nameof(BotViewModel.ProfitCurrency), 90),
                new Tuple <string, int>(nameof(BotViewModel.TrailingEnabled), 70),
                new Tuple <string, int>(nameof(BotViewModel.TrailingDeviation), 90),
                new Tuple <string, int>(nameof(BotViewModel.DealStartCondition), 200),
                new Tuple <string, int>(nameof(BotViewModel.StopLossPercentage), 100),
                new Tuple <string, int>(nameof(BotViewModel.StopLossType), 70),
                new Tuple <string, int>(nameof(BotViewModel.StopLossTimeoutEnabled), 100),
                new Tuple <string, int>(nameof(BotViewModel.StopLossTimeoutInSeconds), 80),
                new Tuple <string, int>(nameof(BotViewModel.BaseOrderVolume), 60),
                new Tuple <string, int>(nameof(BotViewModel.BaseOrderVolumeType), 80),
                new Tuple <string, int>(nameof(BotViewModel.StartOrderType), 60),
                new Tuple <string, int>(nameof(BotViewModel.SafetyOrderVolume), 60),
                new Tuple <string, int>(nameof(BotViewModel.SafetyOrderVolumeType), 80),
                new Tuple <string, int>(nameof(BotViewModel.MaxSafetyOrders), 80),
                new Tuple <string, int>(nameof(BotViewModel.ActiveSafetyOrdersCount), 80),
                new Tuple <string, int>(nameof(BotViewModel.SafetyOrderStepPercentage), 80),
                new Tuple <string, int>(nameof(BotViewModel.LeverageType), 80),
                new Tuple <string, int>(nameof(BotViewModel.LeverageCustomValue), 80),
                new Tuple <string, int>(nameof(BotViewModel.MartingaleVolumeCoefficient), 80),
                new Tuple <string, int>(nameof(BotViewModel.MartingaleStepCoefficient), 80),
                new Tuple <string, int>(nameof(BotViewModel.MinPrice), 80),
                new Tuple <string, int>(nameof(BotViewModel.MaxPrice), 80),
                new Tuple <string, int>(nameof(BotViewModel.MinVolumeBtc24h), 80),
                new Tuple <string, int>(nameof(BotViewModel.Cooldown), 80),
                new Tuple <string, int>(nameof(BotViewModel.DisableAfterDealsCount), 80),
                new Tuple <string, int>(nameof(BotViewModel.FinishedDealsCount), 80),
                new Tuple <string, int>(nameof(BotViewModel.FinishedDealsProfitUsd), 80),
                new Tuple <string, int>(nameof(BotViewModel.ProfitRatio), 80),
                new Tuple <string, int>(nameof(BotViewModel.CreatedAt), 100),
                new Tuple <string, int>(nameof(BotViewModel.UpdatedAt), 100),
                new Tuple <string, int>(nameof(BotViewModel.IsDeleteable), 80)
            });
        }
コード例 #13
0
 public void Init(XCommasAccounts keys, ILogger logger)
 {
     _keys   = keys;
     _logger = logger;
     base.Init("DCA Bots", _keys);
 }
コード例 #14
0
 public void Init(XCommasAccounts keys, ILogger logger, IMessageBoxService mbs)
 {
     _keys   = keys;
     _logger = logger;
     base.Init("Deals", keys);
 }
コード例 #15
0
        public async Task RefreshData(XCommasAccounts keys)
        {
            await tableControl.RefreshData(keys);

            SetDataSource();
        }