Giter VIP home page Giter VIP logo

io.contek.invoker's Introduction

io.contek.invoker

A Java library to connect cryptocurrency exchanges.

Maven

<dependency>
    <groupId>io.contek.invoker</groupId>
    <artifactId>binanceinverse-api</artifactId>
    <version>2.15.0</version>
</dependency>

<dependency>
    <groupId>io.contek.invoker</groupId>
    <artifactId>binancelinear-api</artifactId>
    <version>2.15.0</version>
</dependency>

<dependency>
    <groupId>io.contek.invoker</groupId>
    <artifactId>bitmex-api</artifactId>
    <version>2.15.0</version>
</dependency>

<dependency>
    <groupId>io.contek.invoker</groupId>
    <artifactId>bitstamp-api</artifactId>
    <version>2.15.0</version>
</dependency>

<dependency>
    <groupId>io.contek.invoker</groupId>
    <artifactId>bybit-api</artifactId>
    <version>2.15.0</version>
</dependency>

<dependency>
    <groupId>io.contek.invoker</groupId>
    <artifactId>coinbasepro-api</artifactId>
    <version>2.15.0</version>
</dependency>

<dependency>
    <groupId>io.contek.invoker</groupId>
    <artifactId>deribit-api</artifactId>
    <version>2.15.0</version>
</dependency>

<dependency>
    <groupId>io.contek.invoker</groupId>
    <artifactId>ftx-api</artifactId>
    <version>2.15.0</version>
</dependency>

<dependency>
    <groupId>io.contek.invoker</groupId>
    <artifactId>hbdmlinear-api</artifactId>
    <version>2.15.0</version>
</dependency>

<dependency>
    <groupId>io.contek.invoker</groupId>
    <artifactId>hbdminverse-api</artifactId>
    <version>2.15.0</version>
</dependency>

<dependency>
    <groupId>io.contek.invoker</groupId>
    <artifactId>kraken-api</artifactId>
    <version>2.15.0</version>
</dependency>

Examples

Binance Futures Main Net Get Order Book

MarketRestApi api = ApiFactory.getMainNet().rest().market();
GetDepth.Response response = api.getDepth().setSymbol("BTCUSDT").setLimit(100).submit();
double bestBid = response.bids.get(0).get(0);
double bestAsk = response.asks.get(0).get(0);
System.out.println("Best bid: " + bestBid + ", best ask: " + bestAsk);

Binance Futures Test Net Place Order

ApiKey key = ApiKey.newBuilder().setId("foo").setSecret("bar").build();
UserRestApi api = ApiFactory.getTestNet().rest().user(key);
PostOrder.Response response =
    api.postOrder()
        .setSymbol("BTCUSDT")
        .setSide(OrderSides.BUY)
        .setType(OrderTypes.LIMIT)
        .setPrice(9981.05d)
        .setQuantity(0.03d)
        .submit();
System.out.println("My order ID is: " + response.orderId);

Binance Futures Main Net Subscribe Trades

ISubscribingConsumer<Message> consumer =
    new ISubscribingConsumer<Message>() {
      @Override
      public void onNext(AggTradeChannel.Message message) {
        double price = message.data.p;
        double quantity = message.data.q;
        System.out.println("New trade price: " + price + ", quantity: " + quantity);
      }

      @Override
      public void onStateChange(SubscriptionState state) {
        if (state == SubscriptionState.SUBSCRIBED) {
          System.out.println("Start receiving trade data");
        }
      }

      @Override
      public ConsumerState getState() {
        return ConsumerState.ACTIVE;
      }
    };
MarketWebSocketApi api = ApiFactory.getMainNet().ws().market();
api.getAggTradeChannel("BTCUSDT").addConsumer(consumer);

Goals

This project aims to provide a neat solution to connect cryptocurrency exchanges via their REST and WebSocket APIs.

It handles tedious things that are common in many exchanges, for example: rate limit, authentication, reconnection etc.

Non-goals

This project does not make money for you. It does not contain any logic that predicts the market.

This project does not explain the usages of API endpoints. It is absolutely necessary to read the official API document before using an endpoint.

Audiences

Data scientists who want to (freely and legally) download historical market data from exchanges.

Traders who want to interact with the market programmatically.

Contribution Guidelines

Read before you write

Please make sure you are familiar with the existing code base before coding. This helps keeping the code style and project structure consistent.

Format your code

We highly recommend IntelliJ as your Java IDE for this project. In addition, we also recommend using plugin " google-java-format" and plugin "Save Actions" to format your code on the fly.

Do not ignore warnings

Warnings significantly reduce the help you get from your IDE. Also, the more warnings you have in your existing code base, the more likely you will introduce new warnings in the future. Do your best to avoid warnings.

No comment

Your code should be clear enough to understand without any comment. You can (usually) achieve this by writing more descriptive variable names and method names. We also recommend you keep methods short and avoid nested loops whenever possible.

Only send required data

Do not include data/argument that is unnecessary for your purpose. It usually happens when you copy and paste code and forget to remove some fields. It may lead to rejection or unexpected outcomes.

Minimum assumptions

Endpoint implementations shall always follow their official API documents. We shall make the best effort to avoid introducing random constant values that are not described in the API documents.

Example 1:
Q: I can't find a rate limit restriction for XXX endpoint, but I think there must be a limit. Shall I cap it to 10 times per minute?
A: No, because you are likely wrong.

Example 2:
Q: I found XXX endpoint accepts XXX argument, which is not specified in the API document. Shall I add it?
A: No, because it may cause unexpected outcomes.

Example 3:
Q: The example in the official document suggests the field name is XXX but in fact it is YYY. What shall I do?
A: We probably don't want to implement this endpoint yet. Wait for them to fix it first.

FAQs

Is this the official API client for XXX exchange?

No.

Why is there no test for XXX?

We do not have the resources to write those tests (yet).

Is XXX stable?

We do not know and we suggest you find it out in their official API document.

Why is XXX not up to date?

The current version is (probably) good enough for us already. However, feel free to update it and submit pull requests.

Why is XXX not implemented?

We are probably not using this endpoint. However, feel free to implement it and submit pull requests.

io.contek.invoker's People

Contributors

cypher01 avatar darrylsite avatar freelunchcap avatar jottaprivate avatar leofisg avatar mayankpunetha007 avatar nhut avatar norbert-gaulia avatar oleksiilogvin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

io.contek.invoker's Issues

binancelinear WebSocketCommand should be public

These classes should be pulbic:
io.contek.invoker.binancelinear.api.websocket.market.combined.WebSocketCommand
io.contek.invoker.binancelinear.api.websocket.market.combined.WebSocketCommandConfirmation

Binance spot Order Book Ticker API returns an object instead of array

As described in the binance api doc, when symbol parameter provided the order book API will returns an object instead of an array:
https://binance-docs.github.io/apidocs/spot/en/#symbol-order-book-ticker

Therefore https://github.com/contek-io/io.contek.invoker/blob/master/binancespot-api/src/main/java/io/contek/invoker/binancespot/api/rest/market/GetTickerBookTicker.java will fail to execute, when user provide the Symbol parameter since Gson fail to convert the json string back to array.

Suggest fix would be separate the command into two where one for all symbols and one for single symbol...

BigDecimal vs Double

This library looks promising, but why do you use Double instead of BigDecimal? Any plans on using BigDecimal?

Incorrect import

Hello

  1. The readme contains incorrect dependencies:
io.contek.invoker deribit-api 2.15.0

Correct is:

io.contek.invoker
invoker-deribit-api
2.15.0

  1. When I add Deribit dependency - I find error:
    java: cannot access io.contek.invoker.security.ApiKey
    class file for io.contek.invoker.security.ApiKey not found

Primitives in response models

Some response models, e.g. for the Deribit API (package io.contek.invoker.deribit.api.common), use primitive datatypes like double, long, boolean, etc. instead of the classes Double, Long, Boolean, etc.

The problem with this is, that primitive datatypes in Java cannot be null. If a JSON response from an exchange doesn't contain a value, Gson sets default values. For numbers the default value is 0 (long, int) resp. 0.0 (double), for boolean it is false.

The actual problem with this behaviour is that after deserialization one cannot distinguish anymore if the exchange actually returned the value 0 or false, or if the response didn't contain the value.

The solution is simple, use classes instead of primitives. Classes can be checked for null.

This change also preserves backwards compatibility.

I'm willing to do the update and create a pull request, but I need some kind of a confirmation that this change is accepted, because it's plenty of work and I don't want to waste time if this change is not wanted.

ConsumerState

RateLimitRule need to have option to set rate limited per hour or per minute, Bitmex websocket api allows 30 conncetions per hour, Rate limiter limits 20 per minute

 RateLimiter createRateLimiter(String key, double cushion) {
    return RateLimiter.of(
        Joiner.on('_').join(type, name, key),
        RateLimiterConfig.custom()
            .limitForPeriod((int) (maxPermits * (1d - cushion)))
            .limitRefreshPeriod(Duration.of(1, MINUTES))
            .build());
  }

If IOException is common Okio keeps reconnecting more than 20 times per hour, which leads to
429 Too Many Requests' following '403 Forbidden' following permaban of IP

I guess simply changing

.limitRefreshPeriod(Duration.of(1, MINUTES))

with

 .limitRefreshPeriod(resetPeriod)

Will do the trick?

Add Bybit V5 API

Bybit has added a new API version V5, that unifies all old APIs (Spot, Derivatives, Options).

https://bybit-exchange.github.io/docs/v5/upgrade-guide

It's already helpful that the old derivatives API module "bybit-api" was renamed to "bybitinverse-api".

A new API module "bybit-api" could be added, implementing the Bybit V5 API. This preserves backwards compatibility for everyone using the existing modules.

Bitmex _Instrument missing fields

io.contek.invoker.bitmex.api.common._Instrument
missing few very important fields, without which is impossible to work with USDT instrument:

"underlyingToPositionMultiplier"
"underlyingToSettleMultiplier"
"quoteToSettleMultiplier"

api...

Thanks.

你好

你好,能帮忙写个基于xchange的币安期货接口吗,那边只有现货的,有偿,微信676821842

Correct JDK version

The file .github/workflows/main.yml says, the project uses JDK 15.
The build.gradle file configures the sourceCompatibility and targetCompatibility to JDK 1.8.
Which version should be used to build the project?

I could build the project with JDK 17, but it caused a bunch of warnings.
I could also build the project with JDK 1.8, except for the module bybitlinear-api.

The JDK version should be aligned over all project files.

Different between bybitliner and bybit

Hello,

I am starting to use this SDK to integrate ByBit APIs in my project. There is one small confusion, which one is the correct one to use :

  1. Bybit-api
  2. Bybitlinear-api

Thanks.

Inconsistent dependencies in okhttp

[com.squareup.okhttp3/okhttp "4.10.0"] -> [org.jetbrains.kotlin/kotlin-stdlib "1.6.20"] -> [org.jetbrains.kotlin/kotlin-stdlib-common "1.6.20"]

but also

[com.squareup.okhttp3/okhttp "4.10.0"] -> [com.squareup.okio/okio-jvm "3.0.0"] -> [org.jetbrains.kotlin/kotlin-stdlib-common "1.5.31"]

Solution:
Update https://github.com/square/okhttp once they release their new version

EDIT: They seem to intend to release 4.11 still: square/okhttp#7358

Wrong endpoint path

Is this library still working? I was trying to launch example and noticed it uses wrong url for binance api request - I mean "dapi/v1/depth" - doesnt work but I can get right responce using api/v3/depth. Is it ok?

ForceOrderEvent.Order wrong filed

Binance ws api ForceOrderEvent.Order both for linears and inverse has wrong field for liqudation price.
As per manual it should be public Double ap; instead of a.

I dont think its worth pr, so just reporting.

Bybit linear open_interest should be Double

io.contek.invoker.bybitlinear.api.websocket.market.InstrumentInfoChannel.InstrumentInfo
fields
open_interest

and other volumetric values should be Double, otherwise you will see notional value change in one unit of base currency (1 Bitcoin for example), Contracts in linears are expressed in coin fractions (Satoshis for BTC)

For both Linear and Inverse prices prev_price_24h_e4 etc, should be in Double too, most of the contracts tick size is not equal to 1.

Thanks

Gate.io support

Hello!
Could anyone please add support for gate.io exchange?
I tried forking and copy/paste from binance and started to fill in for the gate.io api but it just got really complicated since I don't fully understand all the layers of the library.

I would be most interested in the WebSocket API that can be found here: https://www.gate.io/docs/developers/apiv4/ws/en/#api-overview

Or if someone can help me setup a new module for gateio spot api, then I could start filling in the blanks.
Thank you!

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.