// Submit a market order if quantity is not zero. public async Task <Guid> SubmitMarketOrder(int quantity, OrderSide side, string clientId = "", decimal stopDollars = 0) { //if (quantity == 0) if (quantity == 0) { return(Guid.Empty); } //Console.WriteLine($"Submitting {side} order for {quantity} shares."); try { IOrder order; if (clientId.Length > 0) { order = await client.PostOrderAsync(side.Market(symbol, quantity).WithClientOrderId(clientId)); } else { order = await client.PostOrderAsync(side.Market(symbol, quantity)); } lastTradeId = order.OrderId; if (stopDollars > 0) { // Submit a trailing stop order to sell / buy quantitu of symbol at market - stoploss // trailing stop of if (side == OrderSide.Buy) { order = await client.PostOrderAsync( TrailingStopOrder.Sell(symbol, quantity, TrailOffset.InDollars(stopDollars))); // stop price will be hwm - stopDollars$ (326.44 - 0.05 = 326.39) } else { order = await client.PostOrderAsync( TrailingStopOrder.Buy(symbol, quantity, TrailOffset.InDollars(stopDollars))); // stop price will be hwm + stopDollars$ } } } catch (Exception ex) { // jsruntime.alert(ex.Message); } if (clientId.Length > 0) { await GetOrders(clientId); } return(lastTradeId); }
public static BracketOrder Bracket( this OrderSide orderSide, String symbol, OrderQuantity quantity, Decimal takeProfitLimitPrice, Decimal stopLossStopPrice) => orderSide.Market(symbol, quantity) .Bracket(takeProfitLimitPrice, stopLossStopPrice);