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); }
public void ExecuteSellStop(string symbol, double inPrice) { Global.StopEntryTime = 90000; Global.StopCheckInterval = 3000; api.RegisterL1(symbol); long elapsedMs = 0; var watch = Stopwatch.StartNew(); FormHelper.FormSetText(String.Format("Execute SellStop {0} @ {1}", symbol, inPrice)); while (elapsedMs < Global.StopEntryTime) { var l1 = ExecuteGetL1(symbol); if (l1.AskPrice < inPrice) { var sellPrice = l1.BidPrice - 0.1; // only try once api.ExecuteOrder("Sell", symbol, sellPrice, Global.ShareSize); log.AddFormLogMessage(String.Format("Price reached. Market In")); break; } elapsedMs = watch.ElapsedMilliseconds; Thread.Sleep(Global.StopCheckInterval); } watch.Stop(); var position = api.GetOpenPositionForSymbol(symbol); const int stopLoss = 0; if (position.Volume != 0) { Global.UpdateSymbol(symbol, inPrice, stopLoss, position.Side, position.Volume); log.AddFormLogMessage(String.Format("Filled {0} for {1}", position.Symbol, position.Volume)); } else { FormHelper.FormSetText(String.Format("Did not get fill")); log.Updatelog(String.Format("Did not get fill")); } api.CancelBuyOrdersForSymbol(symbol); }