Пример #1
0
        private void DrawDay(Graphics graphics, DateTime dayDate, DayPosition dayPosition)
        {
            bool      isCurrentDay      = dayDate.Date.Equals(value.Date);
            bool      isCurrentMonthDay = this.IsCurrentMonthsDate(dayDate);
            bool      isToday           = dayDate.Date.Equals(DateTime.Now.Date);
            string    dayText           = this.Calendar.GetDayOfMonth(dayDate).ToString();
            bool      isFocused         = focusedDayPosition.Equals(dayPosition);
            Rectangle bounds            = this.GetDayBounds(dayPosition);
            Rectangle textBounds        = new Rectangle(bounds.Left + dayTextPadding.Left,
                                                        bounds.Top + dayTextPadding.Top,
                                                        bounds.Width - dayTextPadding.Horizontal,
                                                        bounds.Height - dayTextPadding.Vertical);

            TextFormatFlags format = TextFormatFlags.Right | TextFormatFlags.VerticalCenter;

            if (this.RightToLeft == RightToLeft.Yes)
            {
                format |= TextFormatFlags.RightToLeft;
            }
            Color foreColor;
            Color backColor;

            if (isCurrentDay)
            {
                foreColor = this.titleForeColor;
                backColor = this.titleBackColor;
            }
            else if (!isCurrentMonthDay)
            {
                foreColor = this.trailingForeColor;
                backColor = this.BackColor;
            }
            else
            {
                foreColor = this.ForeColor;
                backColor = this.BackColor;
            }
            using (var brush = new SolidBrush(backColor)) {
                Rectangle rect = bounds;
                rect.Inflate(-1, -1);
                graphics.FillRectangle(brush, rect);
            }
            TextRenderer.DrawText(graphics, dayText, this.Font, textBounds, foreColor, backColor, format);
            if (isToday)
            {
                Rectangle rect = bounds;
                rect.Width--;
                rect.Height--;
                using (var pen = new Pen(this.titleBackColor)) {
                    graphics.DrawRectangle(pen, rect);
                }
            }
            if (isFocused || (this.Focused && isCurrentDay))
            {
                Rectangle rect = bounds;
                rect.Inflate(-1, -1);
                ControlPaint.DrawFocusRectangle(graphics, rect, isToday ? this.BackColor : this.ForeColor,
                                                Color.Transparent);
            }
        }
Пример #2
0
        private async void Timer_Elapsed(object sender, ElapsedEventArgs e)
        {
            try
            {
                dayPosition = await apiProcessor.GetDayPosition();

                if (dayPosition.data.positions.Any())
                {
                    double mtmVal = GetMTMValue(dayPosition);
                    SetHighLowMTM(mtmVal);
                    OnMTMChanged?.Invoke(new MTMDetail {
                        MTM = mtmVal.ToString(), High = High.ToString(), Low = Low.ToString()
                    });
                    if ((mtmVal >= TargerMTM || mtmVal <= MaxLossMTM) && !timerStop)
                    {
                        TimerStop();
                        apiProcessor.ExitOrderRetryCount = 3;
                        await apiProcessor.ExitAllOrders();

                        OnMTMTargetHit("Target hit");
                    }
                }
            }
            catch (Exception ex)
            {
                OnError?.Invoke(ex.Message);
            }
        }
Пример #3
0
            public override bool Equals(object obj)
            {
                if (!(obj is DayPosition))
                {
                    return(false);
                }
                DayPosition dayPosition = (DayPosition)obj;

                return(dayPosition.column.Equals(this.column) && dayPosition.row.Equals(this.row));
            }
Пример #4
0
        public double GetMTMValue(DayPosition dayPosition)
        {
            double mtmval = 0;

            foreach (Position position in dayPosition.data.positions)
            {
                mtmval += double.Parse(position.m2m);
            }
            return(mtmval);
        }
Пример #5
0
        public async Task ExitAllOrders()
        {
            try
            {
                await GetOrderHistory();

                foreach (var order in pendingOrders)
                {
                    await CancelOrder(order.oms_order_id);
                }
                DayPosition dayPosition = await aliceBlue.GetDayPosition(tradeSetting.Token);

                string transactionType = string.Empty;
                foreach (Position position in dayPosition.data.positions)
                {
                    if (position.net_quantity != 0)
                    {
                        if (position.net_quantity > 0)
                        {
                            transactionType = TransactionType.Sell;
                        }
                        else
                        {
                            transactionType = TransactionType.Buy;
                        }

                        Order squareoffOrder = new Order
                        {
                            order_type       = OrderType.Market,
                            instrument_token = position.instrument_token,
                            transaction_type = transactionType,
                            quantity         = Math.Abs(position.net_quantity).ToString(),
                            product          = position.product,
                        };

                        await aliceBlue.PlaceOrder(tradeSetting.Token, squareoffOrder);
                    }
                }
                LogAdded("Exited all pending order.");
            }
            catch (Exception ex)
            {
                LogAdded("ExitAllOrders failed");
                if (ExitOrderRetryCount != 0)
                {
                    ExitOrderRetryCount--;
                    Thread.Sleep(500);
                    LogAdded("ExitAllOrders Retry");
                    await ExitAllOrders();
                }
                LogAdded(ex.Message);
            }
        }
Пример #6
0
        public async Task <DayPosition> GetDayPosition(string token)
        {
            httpClient.DefaultRequestHeaders.Clear();
            httpClient.DefaultRequestHeaders.Add("Authorization", "Bearer " + token);
            string url      = baseUrl + urls["day_position"];
            var    response = await Get(url);

            string result = await response.Content.ReadAsStringAsync();

            DayPosition dayPosition = JsonConvert.DeserializeObject <DayPosition>(result);

            return(dayPosition);
        }
Пример #7
0
        private void InvalidateDayBounds(DayPosition dayPosition)
        {
            Rectangle bounds = this.GetDayBounds(dayPosition);

            this.Invalidate(bounds);
        }
Пример #8
0
 private Rectangle GetDayBounds(DayPosition dayPosition)
 {
     Debug.Assert(dayPosition.Column >= 0 && dayPosition.Column < DaysInWeek);
     Debug.Assert(dayPosition.Row >= 0 && dayPosition.Row < RowCount);
     return(this.dayBounds[dayPosition.Row * DaysInWeek + dayPosition.Column]);
 }
Пример #9
0
        public async Task <double> GetFinalMTM()
        {
            dayPosition = await apiProcessor.GetDayPosition();

            return(GetMTMValue(dayPosition));
        }