- 
                Notifications
    
You must be signed in to change notification settings  - Fork 10
 
Trading
        James Robert Somers edited this page Mar 6, 2018 
        ·
        2 revisions
      
    First create a TradeItOrder object to encapsulate the user's intended trade:
TradeItOrderParcelable order = new TradeItOrderParcelable(linkedBrokerAccount, "GE"); // by default it is a market order, quantity: 1, action: buy, expiration: good for day
order.setAction("buy"); // Check order capabilities for valid values
order.setPriceType("limit"); // Check order capabilities for valid values
order.setLimitPrice(20.0);
order.setQuantity(10);
order.setExpiration("gtc"); // Check order capabilities for valid valuesThen preview the order:
order.previewOrder(
    new TradeItCallback<TradeItPreviewStockOrEtfOrderResponse>() {
        @Override
        public void onSuccess(TradeItPreviewStockOrEtfOrderResponse response) {
            // Present the order preview info to the user and prompt them to submit the trade
        }
        @Override
        public void onError(TradeItErrorResult error) {
            //an error occured
        }
    }
);Finally, submit the order:
String orderId = response.orderId; // get the orderId from the previewResponse
order.placeOrder(
    orderId,
    new TradeItCallback<TradeItPlaceStockOrEtfOrderResponse>() {
        @Override
        public void onSuccess(TradeItPlaceStockOrEtfOrderResponse placeOrderResponse) {
            // Successfully placed the order. Display returned order info to the user.
        }
        @Override
        public void onError(TradeItErrorResult error) {
            // an error occured
        }
    }
);