Exemplo n.º 1
0
 private void OnLogicEvent(LOGIC_EVENT evt, Object param)
 {
     this.BeginInvoke(new LogicEventHander(this.OnLogicEventHandler), evt, param);
 }
Exemplo n.º 2
0
        private void OnLogicEventHandler(LOGIC_EVENT evt, object param)
        {
            switch (evt)
            {
            case LOGIC_EVENT.API_SERVER_DISCONNECTED:
                gridWallet.Rows.Clear();
                break;

            case LOGIC_EVENT.WALLETS_SNAPSHOT:
            {
                gridWallet.Rows.Clear();
                object[][] balances = ((IEnumerable)param).Cast <Wallet>()
                                      .OrderBy(x => x.Currency)
                                      .Select(x => x.ToDisplayDatas())
                                      .ToArray();
                foreach (object[] row in balances)
                {
                    gridWallet.Rows.Add(row);
                }
                break;
            }

            case LOGIC_EVENT.WALLET_UPDATE:
            {
                var  wallet  = (Wallet)param;
                bool matched = false;
                for (int index = 0; index < gridWallet.Rows.Count; index++)
                {
                    DataGridViewRow row = gridWallet.Rows[index];
                    if (Convert.ToString(row.Cells[0].Value) == wallet.Currency)
                    {
                        gridWallet.Rows[index].Cells[1].Value = wallet.Amount;
                        matched = true;
                        break;
                    }
                }
                if (!matched)
                {
                    gridWallet.Rows.Add(wallet.ToDisplayDatas());
                }
                break;
            }

            case LOGIC_EVENT.BALANCES_LOAD_FAILED:
                MessageBox.Show("Balances loading failed", "error");
                break;

            case LOGIC_EVENT.TICKERS_LOADED:
            {
                comboTicker.Items.Clear();
                object[] tickers = ((IEnumerable)param).Cast <Ticker>()
                                   .Select(x => x).ToArray();
                foreach (object row in tickers)
                {
                    comboTicker.Items.Add(row);
                    if (((Ticker)row).Pair == Global._shortOrderParam.TickerChoice.Pair)
                    {
                        Global._shortOrderParam.TickerChoice = (Ticker)row;
                        comboTicker.SelectedItem             = row;
                    }
                }

                break;
            }

            case LOGIC_EVENT.TICKERS_LOAD_FAILED:
                MessageBox.Show("Balances loading failed", "error");
                break;

            case LOGIC_EVENT.POSITIONS_SNAPSHOT:
            {
                lock (positionLock)
                {
                    gridPosition.Rows.Clear();
                    object[][] positions = ((IEnumerable)param).Cast <Position>()
                                           .OrderBy(x => x.Id)
                                           .Select(x => x.ToDisplayDatas()).ToArray();
                    foreach (object[] row in positions)
                    {
                        gridPosition.Rows.Add(row);
                    }
                }
                break;
            }

            case LOGIC_EVENT.POSITION_NEW:
            {
                lock (positionLock)
                {
                    object[] positionData = ((Position)param).ToDisplayDatas();
                    gridPosition.Rows.Add(positionData);
                }
                break;
            }

            case LOGIC_EVENT.POSITION_UPDATE:
            {
                lock (positionLock)
                {
                    var position = (Position)param;
                    foreach (DataGridViewRow row in gridPosition.Rows)
                    {
                        if (Convert.ToString(row.Cells[0].Value) == position.Id)
                        {
                            row.SetValues(position.ToDisplayDatas());
                            break;
                        }
                    }
                }
                break;
            }

            case LOGIC_EVENT.POSITION_CANCEL:
            {
                lock (positionLock)
                {
                    var position = (Position)param;
                    foreach (DataGridViewRow row in gridPosition.Rows)
                    {
                        if (Convert.ToString(row.Cells[0].Value) == position.Id)
                        {
                            gridPosition.Rows.Remove(row);
                            break;
                        }
                    }
                }
                break;
            }

            case LOGIC_EVENT.POSITIONS_LOAD_FAILED:
                MessageBox.Show("Positions loading failed", "error");
                break;

            case LOGIC_EVENT.PREVIEWS_MADE:
                textPreview.Text = "";
                var previews = (List <string>)param;
                if (previews.Count > 0)
                {
                    if (previews.ElementAt(0) != "match")
                    {
                        MessageBox.Show("Count was adjusted to " + previews.ElementAt(0), "Information");
                    }
                    previews.RemoveAt(0);

                    if (previews.Count == 0)            // No order data
                    {
                        return;
                    }

                    textPreview.Text = previews.ElementAt(0);
                }
                else
                {
                    MessageBox.Show("Inputted data is invalid", "Error");
                    return;
                }

                break;

            case LOGIC_EVENT.ORDERS_SNAPSHOT:
                object[][] orders = ((IEnumerable)param).Cast <Order>()
                                    .OrderBy(x => x.Id)
                                    .Select(x => x.ToDisplayDatas())
                                    .ToArray();
                lock (orderLock)
                {
                    gridOrder.Rows.Clear();
                    foreach (object[] row in orders)
                    {
                        gridOrder.Rows.Add(row);
                    }
                }

                break;

            case LOGIC_EVENT.ORDER_CANCEL:
            {
                Order order = ((Order)param);
                lock (orderLock)
                {
                    foreach (DataGridViewRow row in gridOrder.Rows)
                    {
                        if (order.Id == Convert.ToString(row.Cells[0].Value))
                        {
                            gridOrder.Rows.Remove(row);
                            break;
                        }
                    }
                }
                break;
            }

            case LOGIC_EVENT.ORDER_UPDATE:
            {
                Order order = ((Order)param);
                lock (orderLock)
                {
                    foreach (DataGridViewRow row in gridOrder.Rows)
                    {
                        if (order.Id == Convert.ToString(row.Cells[0].Value))
                        {
                            row.SetValues(order.ToDisplayDatas());
                            break;
                        }
                    }
                }
                break;
            }

            case LOGIC_EVENT.ORDER_NEW:
                object[] orderData = ((Order)param).ToDisplayDatas();
                lock (orderLock)
                {
                    gridOrder.Rows.Add(orderData);
                }
                break;

            case LOGIC_EVENT.ORDERS_LOAD_FAILED:
                MessageBox.Show("Loading orders failed...", "Error");
                break;

            case LOGIC_EVENT.PLACE_DONE:
                MessageBox.Show("Bot algorithm is starting with current previewed orders.", "Information");
                textPreview.Text = "";
                break;

            case LOGIC_EVENT.PLACE_DONE_FAILED:
                MessageBox.Show("No orders to place. Please click <Preview Orders> first.", "Error");
                break;
            }
            UpdateBtnStatus(evt);
        }
Exemplo n.º 3
0
        private void UpdateBtnStatus(LOGIC_EVENT evt)
        {
            switch (evt)
            {
            case LOGIC_EVENT.INIT_STEP:
            case LOGIC_EVENT.API_SERVER_CONNECT_FAILED:
                btnConnect.Text = "Connect";
                EnableBtn(btnConnect, true);
                EnableBtn(btnExit, true);
                txtApiPublicKey.Enabled = true;
                txtApiSecretKey.Enabled = true;
                EnableBtn(btnPreviewOrders, false);
                EnableBtn(btnPlaceOrders, false);
                EnableBtn(btnDeleteOrders, false);
                EnableBtn(btnBreakAllLoops, false);
                break;

            case LOGIC_EVENT.API_SERVER_CONNECTING:
                btnConnect.Text = "Connecting...";
                EnableBtn(btnConnect, false);
                EnableBtn(btnExit, false);
                txtApiPublicKey.Enabled = false;
                txtApiSecretKey.Enabled = false;
                break;

            case LOGIC_EVENT.API_SERVER_CONNECTED:
                btnConnect.Text = "Disconnect";
                EnableBtn(btnConnect, true);
                EnableBtn(btnExit, true);
                EnableBtn(btnPreviewOrders, true);
                EnableBtn(btnPlaceOrders, false);
                EnableBtn(btnDeleteOrders, true);
                EnableBtn(btnBreakAllLoops, true);
                break;

            case LOGIC_EVENT.API_SERVER_DISCONNECTING:
                btnConnect.Text = "Disconnecting...";
                EnableBtn(btnConnect, false);
                txtApiPublicKey.Enabled = false;
                txtApiSecretKey.Enabled = false;
                EnableBtn(btnExit, false);
                EnableBtn(btnPreviewOrders, false);
                EnableBtn(btnPlaceOrders, false);
                EnableBtn(btnDeleteOrders, false);
                EnableBtn(btnBreakAllLoops, false);
                break;

            case LOGIC_EVENT.API_SERVER_DISCONNECTED:
                btnConnect.Text = "Connect";
                EnableBtn(btnConnect, true);
                txtApiPublicKey.Enabled = true;
                txtApiSecretKey.Enabled = true;
                EnableBtn(btnExit, true);
                break;

            case LOGIC_EVENT.PREVIEWS_MADE:
                EnableBtn(btnPlaceOrders, true);
                break;

            case LOGIC_EVENT.PLACE_DONE:
                EnableBtn(btnPlaceOrders, false);
                break;

            case LOGIC_EVENT.EXIT_APP:
                this.Close();
                break;
            }
        }