public void TxExplorerPreparation()
        {
            if (comboBoxTxExCcy.InvokeRequired)
            {
                DelegateTables d = new DelegateTables(TxExplorerPreparation);
                this.Invoke(d, new object[] { });
            }
            else
            {
                comboBoxTxExCcy.Items.Clear();
                comboBoxTxExCcy.Items.Add("ALL");
                foreach (var item in TSP.Currencies)
                {
                    comboBoxTxExCcy.Items.Add(item.ToString());
                }
                comboBoxTxExCcy.SelectedIndex = 0;

                comboBoxTxExType.Items.Clear();
                comboBoxTxExType.Items.Add("ALL");
                foreach (TransactionType tt in Enum.GetValues(typeof(TransactionType)))
                {
                    if (tt != TransactionType.None)
                    {
                        comboBoxTxExType.Items.Add(tt.ToString());
                    }
                }
                comboBoxTxExType.SelectedIndex = 0;
            }
        }
        public void ShowOpenOrders()
        {
            if (comboBoxCcy1.InvokeRequired)
            {
                DelegateTables d = new DelegateTables(ShowOpenOrders);
                this.Invoke(d, new object[] { });
            }
            else
            {
                dataGridViewOpenBuyOrders.Rows.Clear();
                dataGridViewOpenSellOrders.Rows.Clear();
                CurrencyPair cp = new CurrencyPair((string)comboBoxCcy1.SelectedItem,
                                                   (string)comboBoxCcy2.SelectedItem);
                List <OpenOrder> openOrders = TSP.GetOpenOrders(cp);
                foreach (var item in openOrders)
                {
                    object[] newRow = item.GetDataRow();

                    if (item.Return < 0)
                    {
                        dataGridViewOpenBuyOrders.Rows.Add(newRow);
                    }
                    else
                    {
                        dataGridViewOpenSellOrders.Rows.Add(newRow);
                    }
                }
            }
        }
 public void OpenOrdersPreparation()
 {
     if (comboBoxCcy1.InvokeRequired)
     {
         DelegateTables d = new DelegateTables(OpenOrdersPreparation);
         this.Invoke(d, new object[] { });
     }
     else
     {
         comboBoxCcy1.Items.Clear();
         comboBoxCcy2.Items.Clear();
         foreach (var item in TSP.Currencies)
         {
             if (!item.IsFiat())
             {
                 comboBoxCcy1.Items.Add(item.ToString());
             }
             else
             {
                 comboBoxCcy2.Items.Add(item.ToString());
             }
         }
         comboBoxCcy1.SelectedIndex = 0;
         comboBoxCcy2.SelectedIndex = 0;
     }
 }
 public void AllocationTableUpdate()
 {
     if (dataGridViewAllocation.InvokeRequired)
     {
         DelegateTables d = new DelegateTables(AllocationTableUpdate);
         this.Invoke(d, new object[] { });
     }
     else
     {
         var    data     = TSP.GetLastAllocationToTable(LiveTxHistory: true);
         double position = data["Total"].Position;
         dataGridViewAllocation.Rows.Clear();
         foreach (var key in data.Keys)
         {
             PnLElement item = data[key];
             Currency   ccy  = CurrencyPorperties.FromNameToCurrency(key);
             if (ccy.IsNone())
             {
                 ccy = Fiat;
             }
             dataGridViewAllocation.Rows.
             Add(key,
                 item.Presentation_Position(ccy),
                 item.Presentation_XChangeRate(ccy),
                 item.Presentation_AverageCost(ccy),
                 item.Weight.HasValue ? PercentageToString(item.Weight.Value) : "0",
                 Math.Round(item.OnGoingPnL, 2),
                 Math.Round(item.Fees, 2),
                 Math.Round(item.RealizedPnL, 2));
         }
         TSP.GetOnGoingPnLs();
     }
 }
 public void ShowTxExplorer()
 {
     if (dataGridViewTxExplorer.InvokeRequired)
     {
         DelegateTables d = new DelegateTables(ShowTxExplorer);
         this.Invoke(d, new object[] { });
     }
     else
     {
         dataGridViewTxExplorer.Rows.Clear();
         string selected_ccy  = comboBoxTxExCcy.SelectedItem.ToString();
         string selected_type = comboBoxTxExType.SelectedItem.ToString();
         SortedList <DateTime, Transaction> data_tx = TSP.DataProvider.GetTransactionList();
         List <DateTime> data_dates = data_tx.GetReversedKeys();
         foreach (DateTime dt in data_dates)
         {
             Transaction tx = data_tx[dt];
             if (tx.Paid.Ccy.ToString() == selected_ccy ||
                 tx.Received.Ccy.ToString() == selected_ccy ||
                 selected_ccy == "ALL")
             {
                 if (tx.Type.ToString() == selected_type ||
                     selected_type == "ALL")
                 {
                     dataGridViewTxExplorer
                     .Rows
                     .Add(
                         dt,
                         tx.Type.ToString(),
                         tx.Paid.Amount,
                         tx.Paid.Ccy,
                         tx.Received.Amount,
                         tx.Received.Ccy,
                         tx.Fees.Amount,
                         tx.Fees.Ccy,
                         tx.XRate.ToString()
                         );
                 }
             }
         }
     }
 }
 public void GetCheckedCurrencyPairs()
 {
     if (comboBoxFiat.InvokeRequired)
     {
         DelegateTables d = new DelegateTables(GetCheckedCurrencyPairs);
         this.Invoke(d, new object[] { });
     }
     else
     {
         TimeSeriesKeyList = new List <ITimeSeriesKey>();
         foreach (string item in checkedListBox1.CheckedItems)
         {
             Currency ccy = CurrencyPorperties.FromNameToCurrency(item);
             if (!ccy.IsNone())
             {
                 TimeSeriesKeyList.Add(new CurrencyPairTimeSeries(new CurrencyPair(ccy, Fiat), Frequency));
             }
             else if (item == "MyStrategy")
             {
                 TimeSeriesKeyList.Add(new AllocationSrategy(item, Fiat, Frequency));
             }
         }
     }
 }
        public void PnLTableUpdate()
        {
            if (dataGridViewPnL.InvokeRequired)
            {
                DelegateTables d = new DelegateTables(PnLTableUpdate);
                this.Invoke(d, new object[] { });
            }
            else
            {
                // start date
                DateTime dateStart = PnLExplainStartDateSelector.Date.GetRoundDate(TenorUnit.Day);
                var      dataStart = TSP.GetAllocationToTable(dateStart);
                // end date
                DateTime dateEnd = PnLExaplainEndDateSelector.Date.GetRoundDate(TenorUnit.Day);
                Dictionary <string, PnLElement> dataEnd;
                if (dateEnd == TSP.FXMH.LastRealDate_NoLive.Date)
                {
                    dataEnd = TSP.GetLastAllocationToTable();
                }
                else
                {
                    dataEnd = TSP.GetAllocationToTable(dateEnd);
                }

                // Total Statistics
                double value1 = dataStart["Total"].Position - (dataStart["Total"].Deposit - dataStart["Total"].Withdrawal);
                double value2 = dataEnd["Total"].Position - (dataEnd["Total"].Deposit - dataEnd["Total"].Withdrawal);
                double AbsoluteValueChange = value2 - value1;
                double RelativeChange      = AbsoluteValueChange / dataStart["Total"].Position;

                // fill rows
                dataGridViewPnL.Rows.Clear();
                foreach (var key in dataStart.Keys)
                {
                    PnLElement item  = dataStart[key];
                    PnLElement item2 = dataEnd[key];
                    Currency   ccy   = CurrencyPorperties.FromNameToCurrency(key);
                    if (ccy.IsNone())
                    {
                        ccy = Fiat;
                    }
                    double depositNetTotal   = Math.Round((item2.Deposit - item.Deposit) - (item2.Withdrawal - item.Withdrawal), 2);
                    double realizedPnLChange = item2.RealizedPnL - item.RealizedPnL;
                    double onGoingPnLChange  = item2.OnGoingPnL - item.OnGoingPnL + realizedPnLChange;
                    if (key != "Total")
                    {
                        dataGridViewPnL.Rows.
                        Add(key,                                                                // Ccy
                            item.Presentation_Position(ccy),                                    // Position
                            item.Presentation_XChangeRate(ccy),                                 // Rate
                            PercentageToString(item.Weight),                                    // Weight
                            PercentageToString(item2.Position / item.Position - 1),             // Delta Pos.
                            PercentageToString(item2.xChangeRate / item.xChangeRate - 1),       // Delta Rate
                            Math.Round(onGoingPnLChange, 2),                                    // Delta On Going PnL
                            Math.Round(realizedPnLChange, 2),                                   // Delta Realizes PnL
                            depositNetTotal);                                                   // Deposit Net Total
                    }
                    else
                    {
                        dataGridViewPnL.Rows.
                        Add(key,                                                                // Ccy
                            item.Presentation_Position(ccy),                                    // Total
                            0,                                                                  // 0
                            PercentageToString(item.Weight),                                    // Weight (100%)
                            Math.Round(AbsoluteValueChange, 2),                                 // Delta Pos. (Total Absolute Change)
                            PercentageToString(RelativeChange),                                 // Delta Rate (Total Relative Change)
                            Math.Round(onGoingPnLChange, 2),                                    // Delta On Going PnL
                            Math.Round(realizedPnLChange, 2),                                   // Delta Realized PnL
                            depositNetTotal);                                                   // Deposit Net Total
                    }
                }
            }
        }