Giter VIP home page Giter VIP logo

xapi-client's Introduction

xAPI Java Client

Overview

Java client library for interacting with the XTB xAPI service.

xAPI reference: http://developers.xstore.pro/api

Java version

This project is designed to compile and run on Java 1.8 and higher.

xAPI Compliance

Library implements xAPI Protocol version 2.5.0. Full specification is available at http://developers.xstore.pro/documentation/.

How to use it?

โš ๏ธ This project is ongoing work in progress. It shouldn't be used in any real-world cases yet, unless you are willing to take the risk.

With the above in mind, the basic idea is as following:

  1. Add dependencies to pom or gradle:
<dependency>
    <groupId>TODO</groupId>
    <artifactId>TODO</artifactId>
    <version>TODO</version>
</dependency>
<dependency>
    <!-- In case you are not using jackson you can omit this and provide your own jsonCodec -->
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-databind</artifactId>
    <version>YOUR JACKSON VERSION</version>
    </dependency>
<dependency>
    <!-- In case you are not using jackson you can omit this -->
    <!-- Just make sure to provide correct Instant deserialization from UNIX millis. -->
    <groupId>com.fasterxml.jackson.datatype</groupId>
    <artifactId>jackson-datatype-jsr310</artifactId>
    <version>YOUR JACKSON VERSION</version>
</dependency>
  1. Instantiate the client
XApiConfig config =
        XApiConfig.builder()
            .host("xapi.xtb.com")
            .port(5124)
            .streamingHost("xapi.xtb.com")
            .streamingPort(5125)
            .build();
XApiClient client = XApi.newClient(config);
client.setCredentials(
        XApiCredentials
            .builder()
            .userId("USERID")
            .password("PASSWORD")
            .build());

You can also provide custom JSON deserializer by implementing com.olafparfienczyk.xapi.client.JsonCodec interface and using XApi#newClient(Codec, XApiConfig) function. In such case you can omit adding jackson-databind dependency.

  1. Open streaming connection (optional)
XApiStream stream = client.openStream();
new Thread(() -> {
    try {
        stream.listen();
    } catch (XApiException e) {
        //Listen failed, connection was not closed cleanly, reconnect perhaps?
    }
}).start();

stream.addGetBalanceListener(balance -> System.out.println("Got balance: " + balance.getData().getBalance()));
stream.addGetCandlesListener(candle -> System.out.println("Got candle" + candle.getData().getOpen()));
stream.getCandles("EURUSD"); //enable candles streaming for EURUSD
stream.getBalance(); //enable balance streaming
  1. Send commands & enjoy
List<SymbolRecord> symbols = client.getAllSymbols();
//do something with the symbols

The client and streams use TCP connections internally, so it's a good idea to close them once they're not needed anymore.

In case any streams were opened by the client, those will have to be closed first. Closing the parent client will close all the child streams as specified here, however it will be done so from the server-side outside of client's control. For that reason it's best to close all the streams before closing the client.

stream.close();
client.close();

Contributing

Contributions are welcome, whether it's fixing a typo, adding documentation, implementing features or fixing bugs - anything that makes sense. There are no hard rules to it as of now. Unless you want to do some major changes, you are more than welcome to submit a PR. Otherwise, it would be better to consult beforehand.

What's done?

  • Communication (TCP connection, marshalling and unmarshalling)
  • Client backbone for streaming and commands
  • Authentication
  • Few basic commands and streaming commands

What needs to be done?

  • Support for all commands
  • Support for all streaming commands
  • CI/CD
  • Javadoc & Wiki
  • Tests
  • Connection pool (pooling library such as apache-commons-pool may be used)

Bugs

If you find a bug or have an idea for a feature/improvement don't hesitate to create an issue.

xapi-client's People

Contributors

lordofleaks avatar

Watchers

 avatar

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.