示例#1
0
        public void ExecuteBuyBidInExitHalfOffer(string symbol, int shareSize, double halfTarget)
        {
            api.RegisterL1(symbol);
            var l1 = ExecuteGetL1(symbol);

            if (l1.Symbol == null)
            {
                log.AddFormLogMessage(String.Format("Cannot get Lv1 for {0}", symbol));
                return;
            }

            var openPos = api.GetOpenPositionForSymbol(symbol);

            if (openPos != null && openPos.Side != "B")
            {
                api.FlattenSymbol(symbol);
            }
            var remaining = GetRemainingShareFromOpenPos(openPos, shareSize);

            if (remaining > 0)
            {
                api.CancelBuyOrdersForSymbol(symbol);
                var buyPrice = l1.BidPrice;
                // only try once
                api.ExecuteOrder("Buy", symbol, buyPrice, shareSize);
                FormHelper.FormSetText(String.Format("Bid In @{0}", buyPrice));
                log.Updatelog(String.Format("Bid In @{0}", buyPrice));
            }
            const int oneMinute = 60000;

            Thread.Sleep(1 * oneMinute);
            api.CancelBuyOrdersForSymbol(symbol);

            //check if the thing gets filled
            openPos = api.GetOpenPositionForSymbol(symbol);
            if (openPos != null && openPos.Side == "B")
            {
                var halfShare = openPos.Volume / 2;
                halfShare  = Math.Abs(halfShare);
                halfTarget = Math.Round(halfTarget, 2);
                if (symbol.ToLowerInvariant().Contains("mhi"))
                {
                    halfTarget = Math.Round(halfTarget, 0);
                }

                if (halfShare > 0)
                {
                    api.ExecuteOrder("Sell", symbol, halfTarget, halfShare);
                    log.AddFormLogMessage(String.Format("Offer half @{0}", halfTarget));
                }
            }
        }
示例#2
0
        public IFSymbolExecute BidAtPrice(double price)
        {
            var curOpenPos = api.GetOpenPositionForSymbol(Symbol);

            if (curOpenPos.Volume != 0 && curOpenPos.Side != "B")
            {
                api.FlattenSymbol(Symbol);
            }

            var remaining = GetRemainingShareFromOpenPos(curOpenPos);

            api.CancelBuyOrdersForSymbol(Symbol);
            api.ExecuteOrder("Buy", Symbol, price, remaining);
            FLog.AddFormLogMessage(String.Format("Bid In @{0}", price));

            return(this);
        }