Skip to content

Instantly share code, notes, and snippets.

@jshelton31
jshelton31 / Send Order Java
Created April 28, 2017 23:48
Interactive Brokers Send Order with Trailing Stop
public void sendOrder(String orderSide, int parentOrderId) {
new Thread(() -> {
System.out.print("before getting ids, nextOrderID = " + nextOrderID + ", nextValidId_prev = " + nextValidId_prev);
while (nextOrderID == nextValidId_prev) {
System.out.print("waiting for next valid id...");
client.reqIds(1);
System.out.print("waiting for next valid id done");
try {
Thread.sleep(1000);
@jshelton31
jshelton31 / Check Account Portfolio
Created April 28, 2017 23:43
Interactive Brokers Common Function
@Override
public void updatePortfolio(Contract contract, double position, double marketPrice, double marketValue, double averageCost, double unrealizedPNL, double realizedPNL, String accountName) {
DecimalFormat df = new DecimalFormat("0.0000"); // TODO get digit according
df.setDecimalSeparatorAlwaysShown(true);
String formatedPosition = df.format(position);
formatedPosition = formatedPosition.replace(",", ".");
System.out.println("contract = " + contract.localSymbol() + ", contract.description() = " + contract.description() + ", unrealizedPNL = " + unrealizedPNL + ", formatedPosition = " + formatedPosition);
}