Ejemplo n.º 1
0
  @Override
  protected synchronized void doConnect() {
    super.doConnect();
    if (isConnected()) {
      logger.info("Requesting account updates for {}", ACCOUNT_CODE.get());
      socket.reqAccountUpdates(true, ACCOUNT_CODE.get());
      socket.reqOpenOrders();
      try {
        while (accountCode == null) {
          wait();
        }
      } catch (InterruptedException e) {
        throw new JTradeException(e);
      }
      commission = new Commission(0.0, 0.0, 0.0, 0.0, 0.0);

      if (!ACCOUNT_CODE.get().equals(accountCode)) {
        logger.info(
            "Account code does not match specified account {} <> {}, exiting.",
            accountCode,
            ACCOUNT_CODE.get());
        disconnect();
      } else if (!accountCode.startsWith("D")) {
        if (!REAL_MONEY_ACCOUNT.get()) {
          logger.info(
              "Connected to real money account {} without #REAL_MONEY_ACCOUNT set to true, exiting.",
              accountCode);
          disconnect();
        }
        logger.info("Connected to real money account {} (Manage risk accordingly!)", accountCode);
      } else {
        logger.info("Connected to paper money account {}", accountCode);
      }
    }
  }
Ejemplo n.º 2
0
  public static void main(String[] args) {
    Trader trader = new IBTrader("localhost:4000", 22);

    Configurable.configure("jtrade.trader.IBTrader#ACCOUNT_CODE", "DU66791");

    try {
      // Symbol s = SymbolFactory.getESFutureSymbol(new DateTime());
      Symbol s = SymbolFactory.getSymbol("AAPL-SMART-USD-STOCK");

      trader.connect();
      Thread.sleep(2000);

      try {
        trader.placeOrder(s, 1, "testref1");
      } catch (Exception e) {
        e.printStackTrace();
      }
      Thread.sleep(2000);

      try {
        trader.placeOrder(s, -1, "testref2");
      } catch (Exception e) {
        e.printStackTrace();
      }
      Thread.sleep(2000);

      trader.cancelOrder(s, null);

    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      trader.disconnect();
    }
  }
Ejemplo n.º 3
0
 @Override
 public void accountDownloadEnd(String accountName) {
   try {
     if (logger.isDebugEnabled()) logger.debug("accountDownloadEnd: {}", accountName);
     logger.info("Updated {}", portfolio);
     socket.reqAccountUpdates(false, ACCOUNT_CODE.get());
   } catch (Throwable t) {
     logger.error(t.getMessage(), t);
   }
 }
Ejemplo n.º 4
0
  @BeforeClass
  public void setUp() {
    symbol = new Symbol("ABB-SFB-SEK-STOCK");
    date = new DateTime(2013, 1, 2, 0, 0, 0, 0);
    double[] opens = {5.0, 6.0, 7.0, 8.0};
    double[] highs = {7.0, 8.0, 9.0, 10.0};
    double[] lows = {4.0, 5.0, 6.0, 7.0};
    double[] closes = {5.0, 6.0, 7.0, 8.0};
    double[] waps = {5.0, 6.0, 7.0, 8.0};
    int[] volumes = {10, 20, 30, 40, 50};
    int[] trades = {1, 1, 1, 1, 1};
    marketFeed =
        new MockBarMarketFeed(symbol, 60, date, opens, highs, lows, closes, waps, volumes, trades);

    Configurable.configure("jtrade.trader.DummyTrader#EXECUTION_DELAY_MILLIS", 0);
  }