Binance java api github
No definitions found in this file.
- Go to file T
- Go to line L
- Go to definition R
- Copy path
- Copy permalink
package com.binance.api.examples ; |
import com.binance.api.client.BinanceApiClientFactory ; |
import com.binance.api.client.BinanceApiRestClient ; |
import com.binance.api.client.domain.TimeInForce ; |
import com.binance.api.client.domain.account.NewOrderResponse ; |
import com.binance.api.client.domain.account.NewOrderResponseType ; |
import com.binance.api.client.domain.account.Order ; |
import com.binance.api.client.domain.account.request.AllOrdersRequest ; |
import com.binance.api.client.domain.account.request.CancelOrderRequest ; |
import com.binance.api.client.domain.account.request.CancelOrderResponse ; |
import com.binance.api.client.domain.account.request.OrderRequest ; |
import com.binance.api.client.domain.account.request.OrderStatusRequest ; |
import com.binance.api.client.exception.BinanceApiException ; |
import java.util.List ; |
import static com.binance.api.client.domain.account.NewOrder.limitBuy ; |
import static com.binance.api.client.domain.account.NewOrder.marketBuy ; |
/** |
* Examples on how to place orders, cancel them, and query account information. |
*/ |
public class OrdersExample < |
public static void main ( String [] args ) < |
BinanceApiClientFactory factory = BinanceApiClientFactory . newInstance( » YOUR_API_KEY » , » YOUR_SECRET » ); |
BinanceApiRestClient client = factory . newRestClient(); |
// Getting list of open orders |
List Order > openOrders = client . getOpenOrders( new OrderRequest ( » LINKETH » )); |
System . out . println(openOrders); |
// Getting list of all orders with a limit of 10 |
List Order > allOrders = client . getAllOrders( new AllOrdersRequest ( » LINKETH » ) . limit( 10 )); |
System . out . println(allOrders); |
// Get status of a particular order |
Order order = client . getOrderStatus( new OrderStatusRequest ( » LINKETH » , 751698L )); |
System . out . println(order); |
// Canceling an order |
try < |
CancelOrderResponse cancelOrderResponse = client . cancelOrder( new CancelOrderRequest ( » LINKETH » , 756762l )); |
System . out . println(cancelOrderResponse); |
> catch ( BinanceApiException e) < |
System . out . println(e . getError() . getMsg()); |
> |
// Placing a test LIMIT order |
client . newOrderTest(limitBuy( » LINKETH » , TimeInForce . GTC , » 1000 » , » 0.0001 » )); |
// Placing a test MARKET order |
client . newOrderTest(marketBuy( » LINKETH » , » 1000 » )); |
// Placing a real LIMIT order |
NewOrderResponse newOrderResponse = client . newOrder(limitBuy( » LINKETH » , TimeInForce . GTC , » 1000 » , » 0.0001 » ) . newOrderRespType( NewOrderResponseType . FULL )); |
System . out . println(newOrderResponse); |
> |
> |
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Источник
Binance java api github
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.
- Install library into your Maven’s local repository by running mvn install
- 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
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
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.
Источник
Binance java api github
Automate your workflow from idea to production
GitHub Actions makes it easy to automate all your software workflows, now with world-class CI/CD. Build, test, and deploy your code right from GitHub.
Linux, macOS, Windows, ARM, and containers
Hosted runners for every major OS make it easy to build and test all your projects. Run directly on a VM or inside a container. Use your own VMs, in the cloud or on-prem, with self-hosted runners.
Matrix builds
Save time with matrix workflows that simultaneously test across multiple operating systems and versions of your runtime.
Any language
GitHub Actions supports Node.js, Python, Java, Ruby, PHP, Go, Rust, .NET, and more. Build, test, and deploy applications in your language of choice.
Live logs
See your workflow run in realtime with color and emoji. It’s one click to copy a link that highlights a specific line number to share a CI/CD failure.
Built-in secret store
Automate your software development practices with workflow files embracing the Git flow by codifying it in your repository.
Multi-container testing
Test your web service and its DB in your workflow by simply adding some docker-compose to your workflow file.
Источник
Binance java api github
0 contributors
Users who have contributed to this file
package com.binance.api.examples ; |
import com.binance.api.client.BinanceApiClientFactory ; |
import com.binance.api.client.BinanceApiRestClient ; |
import com.binance.api.client.domain.TimeInForce ; |
import com.binance.api.client.domain.account.NewOrderResponse ; |
import com.binance.api.client.domain.account.Order ; |
import com.binance.api.client.domain.account.request.AllOrdersRequest ; |
import com.binance.api.client.domain.account.request.CancelOrderRequest ; |
import com.binance.api.client.domain.account.request.OrderRequest ; |
import com.binance.api.client.domain.account.request.OrderStatusRequest ; |
import com.binance.api.client.exception.BinanceApiException ; |
import java.util.List ; |
import static com.binance.api.client.domain.account.NewOrder.limitBuy ; |
import static com.binance.api.client.domain.account.NewOrder.marketBuy ; |
/** |
* Examples on how to place orders, cancel them, and query account information. |
*/ |
public class OrdersExample < |
public static void main ( String [] args ) < |
BinanceApiClientFactory factory = BinanceApiClientFactory . newInstance( » YOUR_API_KEY » , » YOUR_SECRET » ); |
BinanceApiRestClient client = factory . newRestClient(); |
// Getting list of open orders |
List Order > openOrders = client . getOpenOrders( new OrderRequest ( » LINKETH » )); |
System . out . println(openOrders); |
// Getting list of all orders with a limit of 10 |
List Order > allOrders = client . getAllOrders( new AllOrdersRequest ( » LINKETH » ) . limit( 10 )); |
System . out . println(allOrders); |
// Get status of a particular order |
Order order = client . getOrderStatus( new OrderStatusRequest ( » LINKETH » , 751698L )); |
System . out . println(order); |
// Canceling an order |
try < |
client . cancelOrder( new CancelOrderRequest ( » LINKETH » , 756762l )); |
> catch ( BinanceApiException e) < |
System . out . println(e . getError() . getMsg()); |
> |
// Placing a test LIMIT order |
client . newOrderTest(limitBuy( » LINKETH » , TimeInForce . GTC , » 1000 » , » 0.0001 » )); |
// Placing a test MARKET order |
client . newOrderTest(marketBuy( » LINKETH » , » 1000 » )); |
// Placing a real LIMIT order |
NewOrderResponse newOrderResponse = client . newOrder(limitBuy( » LINKETH » , TimeInForce . GTC , » 1000 » , » 0.0001 » )); |
System . out . println(newOrderResponse); |
> |
> |
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Источник
Binance java api github
No definitions found in this file.
- Go to file T
- Go to line L
- Go to definition R
- Copy path
- Copy permalink
package com.binance.api.client.security ; |
import com.binance.api.client.constant.BinanceApiConstants ; |
import okhttp3.HttpUrl ; |
import okhttp3.Interceptor ; |
import okhttp3.Request ; |
import okhttp3.RequestBody ; |
import okhttp3.Response ; |
import okio.Buffer ; |
import org.apache.commons.lang3.StringUtils ; |
import java.io.IOException ; |
import java.util.Objects ; |
/** |
* A request interceptor that injects the API Key Header into requests, and signs messages, whenever required. |
*/ |
public class AuthenticationInterceptor implements Interceptor < |
private final String apiKey; |
private final String secret; |
public AuthenticationInterceptor ( String apiKey , String secret ) < |
this . apiKey = apiKey; |
this . secret = secret; |
> |
@Override |
public Response intercept ( Chain chain ) throws IOException < |
Request original = chain . request(); |
Request . Builder newRequestBuilder = original . newBuilder(); |
boolean isApiKeyRequired = original . header( BinanceApiConstants . ENDPOINT_SECURITY_TYPE_APIKEY ) != null ; |
boolean isSignatureRequired = original . header( BinanceApiConstants . ENDPOINT_SECURITY_TYPE_SIGNED ) != null ; |
newRequestBuilder . removeHeader( BinanceApiConstants . ENDPOINT_SECURITY_TYPE_APIKEY ) |
.removeHeader( BinanceApiConstants . ENDPOINT_SECURITY_TYPE_SIGNED ); |
// Endpoint requires sending a valid API-KEY |
if (isApiKeyRequired || isSignatureRequired) < |
newRequestBuilder . addHeader( BinanceApiConstants . API_KEY_HEADER , apiKey); |
> |
// Endpoint requires signing the payload |
if (isSignatureRequired) < |
String payload = original . url() . query(); |
if ( ! StringUtils . isEmpty(payload)) < |
String signature = HmacSHA256Signer . sign(payload, secret); |
HttpUrl signedUrl = original . url() . newBuilder() . addQueryParameter( » signature » , signature) . build(); |
newRequestBuilder . url(signedUrl); |
> |
> |
// Build new request after adding the necessary authentication information |
Request newRequest = newRequestBuilder . build(); |
return chain . proceed(newRequest); |
> |
/** |
* Extracts the request body into a String. |
* |
* @return request body as a string |
*/ |
@SuppressWarnings ( » unused » ) |
private static String bodyToString ( RequestBody request ) < |
try ( final Buffer buffer = new Buffer ()) < |
final RequestBody copy = request; |
if (copy != null ) < |
copy . writeTo(buffer); |
> else < |
return » » ; |
> |
return buffer . readUtf8(); |
> catch ( IOException e) < |
throw new RuntimeException (e); |
> |
> |
@Override |
public boolean equals ( final Object o ) < |
if ( this == o) return true ; |
if (o == null || getClass() != o . getClass()) return false ; |
final AuthenticationInterceptor that = ( AuthenticationInterceptor ) o; |
return Objects . equals(apiKey, that . apiKey) && |
Objects . equals(secret, that . secret); |
> |
@Override |
public int hashCode () < |
return Objects . hash(apiKey, secret); |
> |
> |
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Источник