public void start() throws ExecutionException, InterruptedException {

    // Use the default MtGox settings
    Exchange mtGoxExchange = ExchangeFactory.INSTANCE.createExchange(MtGoxExchange.class.getName());

    // Configure BTC/USD ticker stream for MtGox
    ExchangeStreamingConfiguration btcusdConfiguration =
        new MtGoxStreamingConfiguration(10, 10000, Currencies.BTC, Currencies.USD, false);

    // Interested in the public streaming market data feed (no authentication)
    StreamingExchangeService btcusdStreamingMarketDataService =
        mtGoxExchange.getStreamingExchangeService(btcusdConfiguration);

    // Requesting initial order book using the polling service
    PollingMarketDataService marketDataService = mtGoxExchange.getPollingMarketDataService();
    MarketDataRunnable.book = marketDataService.getPartialOrderBook(Currencies.BTC, Currencies.USD);

    // Open the connections to the exchange
    btcusdStreamingMarketDataService.connect();

    ExecutorService executorService = Executors.newSingleThreadExecutor();
    Future<?> mtGoxMarketDataFuture =
        executorService.submit(new MarketDataRunnable(btcusdStreamingMarketDataService));

    // the thread waits here until the Runnable is done.
    mtGoxMarketDataFuture.get();

    executorService.shutdown();

    // Disconnect and exit
    System.out.println(Thread.currentThread().getName() + ": Disconnecting...");
    btcusdStreamingMarketDataService.disconnect();
  }
  @Test
  public void tickerFetchTest() throws Exception {

    Exchange exchange = ExchangeFactory.INSTANCE.createExchange(OkCoinExchange.class.getName());
    PollingMarketDataService marketDataService = exchange.getPollingMarketDataService();
    Ticker ticker = marketDataService.getTicker(new CurrencyPair("BTC", "CNY"));
    System.out.println(ticker.toString());
    assertThat(ticker).isNotNull();
  }
  @Test
  public void tickerFetchTest() throws Exception {

    Exchange exchange = ExchangeFactory.INSTANCE.createExchange(ItBitExchange.class.getName());
    PollingMarketDataService marketDataService = exchange.getPollingMarketDataService();
    OrderBook orderBook = marketDataService.getOrderBook(new CurrencyPair("XBT", "USD"));
    //    System.out.println(orderBook.toString());
    assertThat(orderBook).isNotNull();
  }
  public static void main(String[] args) throws Exception {

    CertHelper.trustAllCerts();

    Exchange exchange = CryptoTradeExampleUtils.createExchange();
    PollingAccountService accountService = exchange.getPollingAccountService();

    generic(accountService);
    raw((CryptoTradeAccountServiceRaw) accountService);
  }
  /**
   * Constructor
   *
   * @param exchange
   */
  public BitcoindeMarketDataServiceRaw(Exchange exchange) {

    super(exchange);
    this.bitcoinde =
        RestProxyFactory.createProxy(
            Bitcoinde.class,
            exchange.getExchangeSpecification().getSslUri()
                + exchange.getExchangeSpecification().getApiKey()
                + "/");
  }
  public static void main(String[] args) throws IOException {

    Exchange ANX = ANXExamplesUtils.createExchange();

    // Interested in the private account functionality (authentication)
    PollingAccountService accountService = ANX.getPollingAccountService();

    // Request a Bitcoin deposit address
    String address = accountService.requestDepositAddress(Currencies.BTC.toString());
    System.out.println("Address to deposit Bitcoins to: " + address);
  }
  private void go() throws IOException {

    ExchangeSpecification exchangeSpecification =
        new ExchangeSpecification(BitcoiniumExchange.class.getName());
    exchangeSpecification.setApiKey("6seon0iepta86txluchde");
    // Use the factory to get the Open Exchange Rates exchange API
    Exchange bitcoiniumExchange = ExchangeFactory.INSTANCE.createExchange(exchangeSpecification);

    // Interested in the public polling market data feed (no authentication)
    bitcoiniumMarketDataService =
        (BitcoiniumMarketDataServiceRaw) bitcoiniumExchange.getPollingMarketDataService();

    // Setup the panel
    final XChartPanel chartPanel = buildPanel();
    // Schedule a job for the event-dispatching thread:
    // creating and showing this application's GUI.
    javax.swing.SwingUtilities.invokeLater(
        new Runnable() {

          @Override
          public void run() {

            // Create and set up the window.
            JFrame frame = new JFrame("XChart");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.add(chartPanel);

            // Display the window.
            frame.pack();
            frame.setVisible(true);
          }
        });

    // Simulate a data feed
    TimerTask chartUpdaterTask =
        new TimerTask() {

          @Override
          public void run() {

            try {
              updateData();
              // update chart
              chartPanel.updateSeries(BIDS_SERIES_NAME, xAxisBidData, yAxisBidData);
              chartPanel.updateSeries(ASKS_SERIES_NAME, xAxisAskData, yAxisAskData);
            } catch (IOException e) {
              e.printStackTrace();
            }
          }
        };

    Timer timer = new Timer();
    timer.scheduleAtFixedRate(chartUpdaterTask, 0, 10000); // every ten seconds
  }
  /** @param exchange */
  public BitstampTradeServiceRaw(Exchange exchange) {

    super(exchange);
    this.bitstampAuthenticated =
        RestProxyFactory.createProxy(
            BitstampAuthenticated.class, exchange.getExchangeSpecification().getSslUri());
    this.signatureCreator =
        BitstampDigest.createInstance(
            exchange.getExchangeSpecification().getSecretKey(),
            exchange.getExchangeSpecification().getUserName(),
            exchange.getExchangeSpecification().getApiKey());
  }
示例#9
0
  public static void main(String[] args) throws IOException {

    // Use the factory to get BitcoinToYou exchange API using default settings
    Exchange bitcoinToYou =
        ExchangeFactory.INSTANCE.createExchange(BitcoinToYouExchange.class.getName());

    // Interested in the public polling market data feed (no authentication)
    PollingMarketDataService marketDataService = bitcoinToYou.getPollingMarketDataService();

    Long now = new Date().getTime();

    generic(now, marketDataService);
    raw(now, (BitcoinToYouMarketDataServiceRaw) marketDataService);
  }
示例#10
0
  @Override
  protected void handleSpecificOrder(SpecificOrder specificOrder) {
    Exchange exchange = XchangeUtil.getExchangeForMarket(specificOrder.getMarket().getExchange());
    PollingTradeService tradeService = exchange.getPollingTradeService();
    if (specificOrder.getLimitPrice() != null && specificOrder.getStopPrice() != null)
      reject(specificOrder, "Stop-limit orders are not supported");
    Order.OrderType orderType = specificOrder.isBid() ? Order.OrderType.BID : Order.OrderType.ASK;
    BigDecimal tradeableVolume = specificOrder.getVolume().abs().asBigDecimal();
    CurrencyPair currencyPair =
        XchangeUtil.getCurrencyPairForListing(specificOrder.getMarket().getListing());
    String id = specificOrder.getId().toString();
    Date timestamp = specificOrder.getTime().toDate();
    if (specificOrder.getLimitPrice() != null) {
      LimitOrder limitOrder =
          new LimitOrder(
              orderType,
              tradeableVolume,
              currencyPair,
              "",
              null,
              specificOrder.getLimitPrice().asBigDecimal());
      // todo put on a queue
      try {
        specificOrder.setRemoteKey(tradeService.placeLimitOrder(limitOrder));
        updateOrderState(specificOrder, OrderState.PLACED, false);
      } catch (IOException e) {
        log.error("Threw a Execption, full stack trace follows:", e);

        e.printStackTrace();
        // todo retry until expiration or reject as invalid
      }
    } else {
      MarketOrder marketOrder =
          new MarketOrder(orderType, tradeableVolume, currencyPair, id, timestamp);
      // todo put on a queue
      try {
        specificOrder.setRemoteKey(tradeService.placeMarketOrder(marketOrder));
        updateOrderState(specificOrder, OrderState.PLACED, false);
      } catch (IOException e) {
        // todo retry until expiration or reject as invalid
        log.warn("Could not place this order: " + specificOrder, e);
      } catch (NotYetImplementedForExchangeException e) {
        log.warn(
            "XChange adapter " + exchange + " does not support this order: " + specificOrder, e);
        reject(specificOrder, "XChange adapter " + exchange + " does not support this order");
      }
    }
  }
  /**
   * Constructor
   *
   * @param exchange
   */
  public BitcoinChartsMarketDataService(Exchange exchange) {

    super(exchange);
    this.bitcoinCharts =
        RestProxyFactory.createProxy(
            BitcoinCharts.class, exchange.getExchangeSpecification().getPlainTextUri());
  }
示例#12
0
  public static void main(String[] args) throws IOException {

    Exchange mtgox = MtGoxV1ExamplesUtils.createExchange();

    // Interested in the private trading functionality (authentication)
    PollingTradeService tradeService = mtgox.getPollingTradeService();

    boolean success = tradeService.cancelOrder("fa432315-a929-4202-a681-9a8fbd0e2549");
    System.out.println("success= " + success);

    // get open orders
    OpenOrders openOrders = tradeService.getOpenOrders();
    for (LimitOrder openOrder : openOrders.getOpenOrders()) {
      System.out.println(openOrder.toString());
    }
  }
示例#13
0
  /**
   * Constructor
   *
   * @param exchange
   */
  public ItBitBasePollingService(Exchange exchange) {

    super(exchange);

    this.itBitAuthenticated =
        RestProxyFactory.createProxy(
            ItBitAuthenticated.class,
            (String)
                exchange.getExchangeSpecification().getExchangeSpecificParametersItem("authHost"));
    this.apiKey = exchange.getExchangeSpecification().getApiKey();
    this.signatureCreator =
        ItBitHmacPostBodyDigest.createInstance(
            apiKey, exchange.getExchangeSpecification().getSecretKey());

    this.itBitPublic =
        RestProxyFactory.createProxy(ItBit.class, exchange.getExchangeSpecification().getSslUri());
  }
示例#14
0
  @Override
  @Transient
  public Collection<SpecificOrder> getPendingOrders(Market market, Portfolio portfolio) {
    com.xeiam.xchange.Exchange exchange = XchangeUtil.getExchangeForMarket(market.getExchange());
    PollingTradeService tradeService = exchange.getPollingTradeService();
    Collection<SpecificOrder> pendingOrders = new ConcurrentLinkedQueue<SpecificOrder>();
    SpecificOrder specificOrder;
    try {
      OpenOrders openOrders = tradeService.getOpenOrders();
      for (LimitOrder xchangeOrder : openOrders.getOpenOrders()) {
        for (org.cryptocoinpartners.schema.Order cointraderOrder : orderStateMap.keySet()) {
          if (cointraderOrder instanceof SpecificOrder) {
            specificOrder = (SpecificOrder) cointraderOrder;
            if (xchangeOrder.getId().equals(specificOrder.getRemoteKey())
                && specificOrder.getMarket().equals(market)) {
              specificOrder.update(xchangeOrder);
              updateOrderState(specificOrder, OrderState.PLACED, false);
              pendingOrders.add(specificOrder);
              break;
            } else {
              Date time =
                  (xchangeOrder.getTimestamp() != null) ? xchangeOrder.getTimestamp() : new Date();
              specificOrder = new SpecificOrder(xchangeOrder, exchange, portfolio, time);
              updateOrderState(specificOrder, OrderState.PLACED, false);
              pendingOrders.add(specificOrder);
              break;
            }
          }
        }
        Date time =
            (xchangeOrder.getTimestamp() != null) ? xchangeOrder.getTimestamp() : new Date();

        specificOrder = new SpecificOrder(xchangeOrder, exchange, portfolio, time);
        updateOrderState(specificOrder, OrderState.PLACED, false);
        pendingOrders.add(specificOrder);

        log.debug("completed itteration of orders");
      }

    } catch (IOException e) {
      log.error("Threw a Execption, full stack trace follows:", e);

      e.printStackTrace();
    }
    return pendingOrders;
  }
示例#15
0
  public static void main(String[] args) throws IOException {

    // Use the factory to get ANX exchange API using default settings
    Exchange anx = ExchangeFactory.INSTANCE.createExchange(BitbayExchange.class.getName());

    // Interested in the public polling market data feed (no authentication)
    PollingMarketDataService marketDataService = anx.getPollingMarketDataService();

    // Get the latest ticker data showing BTC to USD
    Ticker ticker = marketDataService.getTicker(CurrencyPair.BTC_USD);
    System.out.println(ticker.toString());

    // Get the latest ticker data showing BTC to EUR
    ticker = marketDataService.getTicker(CurrencyPair.BTC_EUR);
    System.out.println(ticker.toString());

    // Get the latest ticker data showing BTC to GBP
    ticker = marketDataService.getTicker(CurrencyPair.BTC_PLN);
    System.out.println(ticker.toString());
  }
  public static void main(String[] args) {

    Exchange bitfloor = BitfloorDemoUtils.getExchange();
    PollingTradeService tradeService = bitfloor.getPollingTradeService();

    printOpenOrders(tradeService);

    // place a limit buy order
    LimitOrder limitOrder =
        new LimitOrder(
            (OrderType.ASK), new BigDecimal("0.01"), "BTC", "USD", MoneyUtils.parse("USD 1250"));
    String limitOrderReturnValue = tradeService.placeLimitOrder(limitOrder);
    System.out.println("Limit Order return value: " + limitOrderReturnValue);

    printOpenOrders(tradeService);

    // Cancel the added order
    boolean cancelResult = tradeService.cancelOrder(limitOrderReturnValue);
    System.out.println("Canceling returned " + cancelResult);

    printOpenOrders(tradeService);
  }
示例#17
0
  /** Demonstrates how to connect to the AccountService for MtGox */
  private static void demoTradeService() {

    // Use the factory to get the version 1 MtGox exchange API using default settings
    Map<String, Object> params = new HashMap<String, Object>();
    params.put(ExchangeSpecification.API_KEY, "XXX");
    params.put(ExchangeSpecification.API_SECRET, "YYY");
    params.put(ExchangeSpecification.API_URI, "https://mtgox.com");
    params.put(ExchangeSpecification.API_VERSION, "1");
    ExchangeSpecification exchangeSpecification =
        new ExchangeSpecification("com.xeiam.xchange.mtgox.v1.MtGoxExchange", params);
    Exchange mtgox = ExchangeFactory.INSTANCE.createExchange(exchangeSpecification);

    // Interested in the public market data feed (no authentication)
    TradeService tradeService = mtgox.getTradeService();

    // Get the account information
    // AccountInfo accountInfo = tradeService.getAccountInfo();
    // System.out.printf("Account info: %s", accountInfo);

    // Get the open orders
    OpenOrders openOrders = tradeService.getOpenOrders();
    System.out.printf("Open Orders: %s", openOrders);
  }
  public static void main(String[] args) throws IOException {

    String username = args[0];
    String password = args[1];
    String ipAddress = args[2];

    Exchange coinsetter = CoinsetterExamplesUtils.getExchange();
    CoinsetterClientSessionServiceRaw clientSessionService =
        new CoinsetterClientSessionServiceRaw(coinsetter);
    CoinsetterAccountServiceRaw accountService =
        (CoinsetterAccountServiceRaw) coinsetter.getPollingAccountService();
    CoinsetterFinancialTransactionServiceRaw financialTransactionService =
        new CoinsetterFinancialTransactionServiceRaw(coinsetter);

    CoinsetterClientSession clientSession =
        clientSessionService.login(username, password, ipAddress);
    log.info("Client session: {}", clientSession);

    CoinsetterAccountList coinsetterAccounts = accountService.list(clientSession.getUuid());
    for (CoinsetterAccount account : coinsetterAccounts.getAccountList()) {
      log.info("account: {}", account.getAccountUuid());

      CoinsetterAccount a = accountService.get(clientSession.getUuid(), account.getAccountUuid());
      log.info("account: {}", a);

      CoinsetterFinancialTransactionList financialTransactions =
          financialTransactionService.list(clientSession.getUuid(), account.getAccountUuid());
      for (CoinsetterFinancialTransaction transaction :
          financialTransactions.getFinancialTransactionList()) {
        CoinsetterFinancialTransaction t =
            financialTransactionService.get(clientSession.getUuid(), transaction.getUuid());
        log.info("Transaction: {}", t);
      }
    }

    clientSessionService.logout(clientSession.getUuid());
  }
示例#19
0
  /** @return A default configuration for this exchange */
  public static Exchange newInstance() {

    Exchange exchange = new VirtExExchange();
    exchange.applySpecification(exchange.getDefaultExchangeSpecification());
    return exchange;
  }