/// <summary> /// function to place trail stop order in a thread /// </summary> /// <param name="param"></param> void TrailStopper(object param) { KeyValuePair <Stock, decimal> input = (KeyValuePair <Stock, decimal>)param; Stock stock = input.Key; decimal newVal = input.Value; int attempt = 10; while (attempt > 0) { try { //cancel stoploss Robinhood.CancelThrdComp = new ManualResetEvent(false); ThreadPool.QueueUserWorkItem(Robinhood.CancelOrder, new KeyValuePair <Form, ThreadedBindingList <OrderSnapshot> >(this, stock.PendingOrders)); if (stock.PendingOrders != null && stock.PendingOrders.Count() > 0) { Robinhood.CancelThrdComp.WaitOne(); } while (AllPendingOrders.Any(o => o.InstrumentId == stock.InstrumentURL)) { Thread.Sleep(200); } stock.StopLoss.Price = newVal; //place adjusted stop loss Robinhood.PlaceOrder(stock, TimeInForce.GoodTillCancel, Robinhood.TradeStep.StopLoss, this); lock (trailStopping) { trailStopping.Remove(stock.Ticker); } logger.Info("Order plaed at " + newVal.ToString()); //when order is there exit while (stock.PendingOrders == null) { Thread.Sleep(200); } break; } catch (Exception e) { logger.Error(e); } Thread.Sleep(1000); attempt--; } lock (trailStopping) { trailStopping.Remove(stock.Ticker); } }
/// <summary> /// function to place price target order in a thread /// </summary> /// <param name="param"></param> void PriceTargeter(object param) { KeyValuePair <Stock, decimal> input = (KeyValuePair <Stock, decimal>)param; Stock stock = input.Key; decimal newVal = input.Value; int attempt = 10; while (attempt > 0) { try { //cancel stoploss Robinhood.CancelThrdComp = new ManualResetEvent(false); ThreadPool.QueueUserWorkItem(Robinhood.CancelOrder, new KeyValuePair <Form, ThreadedBindingList <OrderSnapshot> >(this, stock.PendingOrders)); Robinhood.CancelThrdComp.WaitOne(); while (AllPendingOrders.Any(o => o.InstrumentId == stock.InstrumentURL)) { Thread.Sleep(200); } //place adjusted stop loss Robinhood.PlaceOrder(stock, TimeInForce.GoodTillCancel, Robinhood.TradeStep.ProfitTarget, this); stock.PriceTarget.NoOfShares = 0; logger.Info("Order plaed at " + newVal.ToString()); break; } catch (Exception e) { logger.Error(e); } Thread.Sleep(1000); attempt--; } lock (priceTargeting) { priceTargeting.Remove(stock.Ticker); } }
void PlaceEntry(object param) { Stock stock = (Stock)param; Robinhood.PlaceOrder(stock, TimeInForce.GoodTillCancel, Robinhood.TradeStep.Entry, this); }
void PlaceStop(object param) { Robinhood.PlaceOrder(stock, TimeInForce.GoodTillCancel, Robinhood.TradeStep.StopLoss, this); }
void PlacePT(object param) { Stock stock = (Stock)param; Robinhood.PlaceOrder(stock, TimeInForce.GoodTillCancel, Robinhood.TradeStep.ProfitTarget, this); }