Esempio n. 1
0
        public BrokerErrorCode PlaceEquityOrder(string stockCode,
                                                OrderPositionTypeEnum holdingType,
                                                int availableQty,
                                                int quantity,
                                                string price,
                                                OrderPriceType orderPriceType,
                                                OrderDirection orderDirection,
                                                EquityOrderType orderType,
                                                Exchange exchange,
                                                string settlementNumber,
                                                out string orderRef)
        {
            BrokerErrorCode errCode = BrokerErrorCode.Unknown;

            orderRef = "";

            // Only OrderPositionTypeEnum.Margin is Buy/Sell, rest all others are only sell orders
            if (holdingType == OrderPositionTypeEnum.Btst)  //  only a sell order
            {
                errCode = broker.PlaceEquityDeliveryBTSTOrder(stockCode, quantity, price, orderPriceType, orderDirection, orderType, exchange, settlementNumber, out orderRef);
            }
            else if (holdingType == OrderPositionTypeEnum.Demat || holdingType == OrderPositionTypeEnum.Margin)
            {
                errCode = broker.PlaceEquityMarginDeliveryFBSOrder(stockCode, quantity, price, orderPriceType, orderDirection, orderType, exchange, out orderRef);
            }
            else if (holdingType == OrderPositionTypeEnum.OpenPendingDelivery) // only square off sell order
            {
                errCode = broker.PlaceEquityMarginSquareOffOrder(stockCode, availableQty, quantity, price, orderPriceType, orderDirection, orderType, settlementNumber, exchange, out orderRef);
            }

            var orderTypeStr = orderType == EquityOrderType.DELIVERY ? ("CASH " + holdingType) : "MARGIN";

            Trace(string.Format(orderTraceFormat, stockCode, orderDirection, quantity, price, orderTypeStr, errCode, orderPriceType, settlementNumber));

            if (errCode == BrokerErrorCode.Success && orderDirection == OrderDirection.BUY)
            {
                todayBuyOrderCount++;
                if (todayBuyOrderCount >= maxBuyOrdersAllowedInADay)
                {
                    Trace(string.Format("Buy order count reached is: {0}. Max buy orders allowed: {1}", todayBuyOrderCount, maxBuyOrdersAllowedInADay));
                }
            }

            return(errCode);
        }