Skip to content

Instantly share code, notes, and snippets.

@rterp
Created March 4, 2016 14:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rterp/28d32acb519bfc3fd077 to your computer and use it in GitHub Desktop.
Save rterp/28d32acb519bfc3fd077 to your computer and use it in GitHub Desktop.
public void placeFuturesOrder() {
InteractiveBrokersClientInterface ibClient = InteractiveBrokersClient.getInstance("localhost", 7999, 1);
ibClient.connect();
//Create a crude oil futures ticker
FuturesTicker futuresTicker = new FuturesTicker();
futuresTicker.setSymbol("CL");
futuresTicker.setExpiryMonth(4);
futuresTicker.setExpiryYear(2016);
futuresTicker.setExchange(Exchange.NYMEX);
String orderId = ibClient.getNextOrderId();
int contracts = 5;
//Create the order and send to Interactive Brokers
TradeOrder order = new TradeOrder(orderId, futuresTicker, contracts, TradeDirection.BUY);
order.setType(TradeOrder.Type.LIMIT);
order.setLimitPrice(32.50);
ibClient.placeOrder(order);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment