Java binance api maven

Java Binance Unofficial API Client

This library is designed to help you make your own projects that interact with the Binance API. This project seeks to have complete API coverage including User Data Streams and WebSockets for Binance Cryptocurrency Exchange

If you are seeking for a version with Android 4+ support, please take a look at https://github.com/shufps/java-binance-api

Getting Started

with Maven

Add the following Maven dependency to your project’s pom.xml :

with Gradle

with Grapes

with latest source code

After git clone , please run gradle jar , which will result in having jar under build/distribution folder. compilation you will have jar in your folder, which could be included as your dependency like this:

Example of Application

Setting up API KEYS

For API keys you can set an environment variables or java Virtual Machine properties BINANCE_API_KEY , BINANCE_SECRET_KEY , as well as setting up these variables in application.properties resource file of your project

Logging

Logging configuration can be corrected in logback.xml files. To suppress requests/response logging, you might want to increase logging level for BinanceRequest component:

Debugging Library from Source

If you cloned this GITHUB repository, the following tips might be useful:

Running tests

If you cloned this repository, tests with API coverage could be launched with gradle test . Before running, make sure API keys are set as described above. For successful trading tests passing, it is desired to have some BTC, ETH and BNB on your account.

Running in Eclipse

This project uses Lombok. You will need to install lombok for Eclipse to make the project compile in Eclipse. It will compile via gradle just fine without this additional installation step.

Running in Intellij IDEA

This project uses Lombok. You will need to install corresponding plugin and enable Annotation processing in your Compiler settings. It will compile via gradle just fine without this additional installation step. To start, import current directory as Gradle project.

Источник

Java binance api maven

Java Binance API

binance-java-api is a lightweight Java library for interacting with the Binance API, providing complete API coverage, and supporting synchronous and asynchronous requests, as well as event streaming using WebSockets.

  • Support for synchronous and asynchronous REST requests to all General, Market Data, Account endpoints, and User stream endpoints.
  • Support for User Data, Trade, Kline, and Depth event streaming using Binance WebSocket API.
  1. Install library into your Maven’s local repository by running mvn install
  2. Add the following Maven dependency to your project’s pom.xml :

Alternatively, you can clone this repository and run the examples.

There are three main client classes that can be used to interact with the API:

These can be instantiated through the corresponding factory method of BinanceApiClientFactory , by passing the security parameters API-KEY and SECRET , which can be created at https://www.binance.com/userCenter/createApi.html.

If the client only needs to access endpoints which do not require additional security, then these parameters are optional.

Once the client is instantiated, it is possible to start making requests to the API.

Check server time

Читайте также:  Максимальный рост криптовалюты за день

Market Data endpoints

Order book of a symbol

Compressed/Aggregate trades list of a symbol

Weekly candlestick bars for a symbol

Latest price of a symbol

Getting all latests prices

Account Data endpoints

Get account balances

Get list of trades for an account and a symbol

Get account open orders for a symbol

Get order status

Placing a MARKET order

Placing a LIMIT order

Canceling an order

In order to be able to withdraw programatically, please enable the Enable Withdrawals option in the API settings.

Fetch withdraw history

Fetch deposit history

Get deposit address

User stream endpoints

Start user data stream, keepalive, and close data stream

Initialize the WebSocket client

User needs to be aware that REST symbols which are upper case differ from WebSocket symbols which must be lower case . In scenario of subscription with upper case styled symbol, server will return no error and subscribe to given channel — however, no events will be pushed.

Handling web socket errors

Each of the methods on BinanceApiWebSocketClient , which opens a new web socket, takes a BinanceApiCallback , which is called for each event received from the Binance servers.

The BinanceApiCallback interface also has a onFailure(Throwable) method, which, optionally, can be implemented to receive notifications if the web-socket fails, e.g. disconnection.

Closing web sockets

Each of the methods on BinanceApiWebSocketClient , which opens a new web socket, also returns a Closeable . This Closeable can be used to close the underlying web socket and free any associated resources, e.g.

Listen for aggregated trade events for ETH/BTC

Listen for changes in the order book for ETH/BTC

Get 1m candlesticks in real-time for ETH/BTC

Keep a local depth cache for a symbol

Please see DepthCacheExample.java for an implementation which uses the binance-java-api for maintaining a local depth cache for a symbol. In the same folder, you can also find how to do caching of account balances, aggregated trades, and klines/candlesticks.

Listen for changes in the account

Client provides a way for user to subscribe to multiple channels using same websocket — to achieve that user needs to coma-separate symbols as it is in following examples.

To make an asynchronous request it is necessary to use the BinanceApiAsyncRestClient , and call the method with the same name as in the synchronous version, but passing a callback BinanceApiCallback that handles the response whenever it arrives.

Get latest price of a symbol asynchronously

Placing a LIMIT order asynchronously

Every API method can potentially throw an unchecked BinanceApiException which wraps the error message returned from the Binance API, or an exception, in case the request never properly reached the server.

Источник

Java binance api maven

Java Binance Unofficial API Client

This library is designed to help you make your own projects that interact with the Binance API. This project seeks to have complete API coverage including User Data Streams and WebSockets for Binance Cryptocurrency Exchange

If you are seeking for a version with Android 4+ support, please take a look at https://github.com/shufps/java-binance-api

Add the following Maven dependency to your project’s pom.xml :

with latest source code

After git clone , please run gradle jar , which will result in having jar under build/distribution folder. compilation you will have jar in your folder, which could be included as your dependency like this:

Example of Application

Setting up API KEYS

For API keys you can set an environment variables or java Virtual Machine properties BINANCE_API_KEY , BINANCE_SECRET_KEY , as well as setting up these variables in application.properties resource file of your project

Читайте также:  Майнинг миф или реальность

Logging configuration can be corrected in logback.xml files. To suppress requests/response logging, you might want to increase logging level for BinanceRequest component:

Debugging Library from Source

If you cloned this GITHUB repository, the following tips might be useful:

If you cloned this repository, tests with API coverage could be launched with gradle test . Before running, make sure API keys are set as described above. For successful trading tests passing, it is desired to have some BTC, ETH and BNB on your account.

Running in Eclipse

This project uses Lombok. You will need to install lombok for Eclipse to make the project compile in Eclipse. It will compile via gradle just fine without this additional installation step.

Running in Intellij IDEA

This project uses Lombok. You will need to install corresponding plugin and enable Annotation processing in your Compiler settings. It will compile via gradle just fine without this additional installation step. To start, import current directory as Gradle project.

Using API — General Endpoints

Checking Server Responsiveness

Getting Server Time

Using API — Getting Account Information

Getting Account Information

Getting All Balances

Getting Asset Balance

Getting Open Orders

Checking Order Status

Getting All Orders

Getting My Trades

Getting All Deposits History

Server side team still works on this endpoint. At the moment of writing that you will just receive a message in Chinese about parameters exception.

Getting Withdrawal History

Server side team still works on this endpoint. At the moment of writing that you will just receive a message in Chinese about parameters exception.

Using API — Getting Market Data

Getting Bids and Asks on Symbol

Getting latest prices — as list of JsonObjects

Getting latest prices — as map of decimals

Getting latest price of a symbol

Getting Aggregated Trades

Getting All Book Tickers

Getting All Available Symbols

Getting 24hr Tickers for Symbol

Getting Klines / Candlesticks

Getting Exchange Market Information (Lot Sizes)

Using API — Placing Orders

Placing a LIMIT order

Placing a MARKET order

Placing a STOP LOSS order

Placing an ICEBERG order

Cancel/Delete an order

Using API — Using User Data Streams

Start User Data Stream

Keep User Data Stream Alive

Close User Data Stream

Using API — Connecting to Web Sockets

Depth Web Socket Listener

Klines Web Socket Listener

Trades Web Socket Listener

User Data Web Socket Listener

This is an API that is not officially supported. So contributions in any form, especially pull requests are always welcome. If you like what we do, and want to support our development of distributed future, you can also send tips:

MIT. Anyone can copy, change, derive further work from this repository without any restrictions.

Источник

Java binance api maven

Binance-Api-Client ( Java Binance API )

binance-java-api is a lightweight Java library for interacting with the Binance API, providing complete API coverage, and supporting synchronous and asynchronous requests, as well as event streaming using WebSockets.

NOTE: This project has won the Binance API Competition for the Java language, and as such, this repository has been forked, and the official version can be found at https://github.com/binance-exchange/binance-java-api, where all further upgrades will be done.

  • Support for synchronous and asynchronous REST requests to all General, Market Data, Account endpoints, and User stream endpoints.
  • Support for User Data, Trade, Kline, and Depth event streaming using Binance WebSocket API.
  1. Install library into your Maven’s local repository by running mvn install
  2. Add the following Maven dependency to your project’s pom.xml :
Читайте также:  Список ноутбуков для майнинга

Alternatively, you can clone this repository and run the examples.

There are three main client classes that can be used to interact with the API:

These can be instantiated through the corresponding factory method of BinanceApiClientFactory , by passing the security parameters API-KEY and SECRET , which can be created at https://www.binance.com/userCenter/createApi.html.

If the client only needs to access endpoints which do not require additional security, then these parameters are optional.

Once the client is instantiated, it is possible to start making requests to the API.

Check server time

Market Data endpoints

Order book of a symbol

Compressed/Aggregate trades list of a symbol

Weekly candlestick bars for a symbol

Latest price of a symbol

Getting all latests prices

Account Data endpoints

Get account balances

Get list of trades for an account and a symbol

Get account open orders for a symbol

Get order status

Placing a MARKET order

Placing a LIMIT order

Canceling an order

In order to be able to withdraw programatically, please enable the Enable Withdrawals option in the API settings.

Fetch withdraw history

Fetch deposit history

Get deposit address

User stream endpoints

Start user data stream, keepalive, and close data stream

Initialize the WebSocket client

User needs to be aware that REST symbols which are upper case differ from WebSocket symbols which must be lower case . In scenario of subscription with upper case styled symbol, server will return no error and subscribe to given channel — however, no events will be pushed.

Handling web socket errors

Each of the methods on BinanceApiWebSocketClient , which opens a new web socket, takes a BinanceApiCallback , which is called for each event received from the Binance servers.

The BinanceApiCallback interface also has a onFailure(Throwable) method, which, optionally, can be implemented to receive notifications if the web-socket fails, e.g. disconnection.

Closing web sockets

Each of the methods on BinanceApiWebSocketClient , which opens a new web socket, also returns a Closeable . This Closeable can be used to close the underlying web socket and free any associated resources, e.g.

Listen for aggregated trade events for ETH/BTC

Listen for changes in the order book for ETH/BTC

Get 1m candlesticks in real-time for ETH/BTC

Keep a local depth cache for a symbol

Please see DepthCacheExample.java for an implementation which uses the binance-java-api for maintaining a local depth cache for a symbol. In the same folder, you can also find how to do caching of account balances, aggregated trades, and klines/candlesticks.

Listen for changes in the account

Client provides a way for user to subscribe to multiple channels using same websocket — to achieve that user needs to coma-separate symbols as it is in following examples.

To make an asynchronous request it is necessary to use the BinanceApiAsyncRestClient , and call the method with the same name as in the synchronous version, but passing a callback BinanceApiCallback that handles the response whenever it arrives.

Get latest price of a symbol asynchronously

Placing a LIMIT order asynchronously

Every API method can potentially throw an unchecked BinanceApiException which wraps the error message returned from the Binance API, or an exception, in case the request never properly reached the server.

Источник

Оцените статью