Giter VIP home page Giter VIP logo

o.c.kraken.java's Introduction

Java API client for the Kraken cryptocurrency exchange: kraken.com.

This library unmarshalls JSON responses into the Java objects (e.g. Trade, Quote,...). A wide collection of Java support objects is provided in this library, designed to be API-agnostic and preferably support additional exchanges in the future.

This project is an early work in progress. Once completed it's planned to be integrated with the Chartsy|One platform. Currently only public API methods are supported.

Roadmap

  • Publish unit and integration tests.
  • Implement Private API methods.
  • AI assisted trading.

Project dependencies

  • GSON
  • Apache Http Components Client

Example usage

1. Basics

Kraken API methods are available through the KrakenService object, which can be instantiated using a static factory method:

    KrakenService service = KrakenService.getInstance();

2. Loading hourly OHLC data:

    Quotes quotes = service.getQuotes(new Symbol("XBTUSD"), TimeFrame.Period.H1);
    System.out.println("Number of Bars = " + quotes.length());
    System.out.println("First Bar = " + quotes.getFirst());
    System.out.println("Last Bar = " + quotes.get(0));

The library supports a basic set of technical and statistical indicators. For example the following code loads hourly OHLC data and calculates the 14-period Average True Range of the result:

    Quotes quotes = service.getQuotes(new Symbol("XBTUSD"), TimeFrame.Period.H1);
    Series atr = quotes.atr(14);
    System.out.println("Current ATR Value = " + atr.get(0));

3. Downloading all historical ticks to a CSV file:

    KrakenService service = KrakenService.getDefault();

    DecimalFormat df = new DecimalFormat("0.########");
    BufferedWriter out = new BufferedWriter(new FileWriter(FILENAME));
    LocalDateTime startDate = Chronological.toDateTime(0);
    try {
        int k = 0;
        while (true) {
            try {
                List<Trade> ticks = service.getTradeTicks(new Symbol("XBTUSD"), startDate);
                if (ticks.size() == 0)
                    break;
                System.out.println("TICK PACK OF " + ticks.size() + " TICKS LOADED:");
                System.out.println(ticks.get(0));
                System.out.println(ticks.get(1));
                System.out.println(ticks.get(2));
                System.out.println(ticks.get(ticks.size()-1));
                System.out.println(ticks.size());
                System.out.println("LOOP COUNT " + ++k);

                for (Trade tick : ticks)
                    out.write(tick.getSymbol() + ";" + tick.getDateTime().toString().replace('T', ';') + ";" + tick.getPrice() + ";" + df.format(tick.getVolume()).replace(',', '.') + ";" + ((tick.getDirection() == Direction.BUY_ASK)? "L" : (tick.getDirection() == Direction.SELL_BID)? "S" : "") + "\r\n");
                out.flush();
                startDate = ticks.get(ticks.size()-1).getDateTime();
            } catch (KrakenServiceUnavailableException e) {
                System.out.println(e);
                Thread.sleep(2L);
            }
        }
    } finally {
        out.close();
    }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.