Git Product home page Git Product logo

java-binance-api's Introduction

Java Binance API

This project is designed to help you make your own projects that interact with the Binance API. You can stream candlestick chart data, market depth, or use other advanced features such as setting stop losses and iceberg orders. This project seeks to have complete API coverage including WebSockets.

Installation

The Java and Android project can also use the library.

1.Download the Jar here,and dependence the Jar in your Java or Android project
2.git clone the java source ,and add the source into your project .

So,You can use him as simple as the following:

Init

   BinanceApi.init("APIKEY","APISECRET");
   ApiMethods apiMethods = ApiMethods.getInstance()

Now , you can get all method through "apiMethods" ,and fetch data what you want .
All normal request result in ApiCallback,you can get data String in "onSuccess",and also can deal with err in "onFailure".  
But the websocket callback through "WebSocketListener",you can get data from "onMessage".

Example

Get all account orders; active, canceled, or filled
    //some multi-parameter request we use Map Upload,
    //but you must upload what server want
    Map map = new HashMap();
    map.put("symbol", "BNBETH");
    map.put("timestamp", System.currentTimeMillis());
    apiMethods.getAllOrders(map, new ApiCallback() {
           public void onSuccess(String result) {
               System.out.print(result);
           }
           public void onFailure(String msg) {
               System.out.print(msg);
           }
        });
24 hour price change statistics.
    apiMethods.get24hr("BNBETH", new ApiCallback() {
        public void onSuccess(String result) {
            System.out.print(result);
        }
        public void onFailure(String msg) {
            System.out.print(msg);
        }
    });

Websocket url for depth endpoint

// 1m,3m,5m,15m,30m,1h,2h,4h,6h,8h,12h,1d,3d,1w,1M
apiMethods.wsKline("BNBETH", "1m",new WebSocketListener() {
            @Override
            public void onMessage(WebSocket webSocket, String text) {
                super.onMessage(webSocket, text);
                System.out.println(text);
            }

            @Override
            public void onFailure(WebSocket webSocket, Throwable t, okhttp3.Response response) {
                super.onFailure(webSocket, t, response);
            }

            @Override
            public void onOpen(WebSocket webSocket, okhttp3.Response response) {
                super.onOpen(webSocket, response);
            }
        });
when you want to close the websocket
apiMethods.closeWs();

Other

All requests are similar to the above, so I just list the Apilist below.
if you want test or know more about the API ,you can clone the demo Source code.
Also ,if there are any problems in use, please let me know.I'll fix it as soon as possible

ApiList

  //Test connectivity to the Rest API.
  ping(ApiCallback callback)
  //Test connectivity to the Rest API and get the current server time.
  getTime(ApiCallback callback)
  //Get compressed, aggregate trades.
  getAggTrades(Map map, ApiCallback callback)
  //Kline/candlestick bars for a symbol. Klines are uniquely identified by their open time.
  getKlines(Map map, ApiCallback callback)
  //24 hour price change statistics.
  get24hr(String symbol, ApiCallback callback)
    //Latest price for all symbols.
   getAllPrices(ApiCallback callback)
   //Best price/qty on the order book for all symbols.
   getAllBookTickers(ApiCallback callback)
   //Check an order's status
   getOrder(Map map, ApiCallback callback)
   //Send in a new order
   sendOrder(Map map, ApiCallback callback)
  //Cancel an active order
  cancelOrder(Map map, Callback<String> callback)
  // Get all open orders on a symbo 
  getOpenOrders(String symbol, ApiCallback callback)
  //get symbol depth 
  getDepth(String symbol, ApiCallback callback)
  //Get current account information
  getCount(ApiCallback callback)
  //Get trades for a specific account and symbol
  getMyTrades(Map map, ApiCallback callback)
  //Get all account orders; active, canceled, or filled
  getAllOrders(Map map, ApiCallback callback)
  //Start a new user data stream
  getUserDataStream(ApiCallback callback)
   //Close out a user data stream
   closeUserDataStream(String listenKey, ApiCallback callback)
   //Fetch deposit history.
   getDepositHistory(Map map, ApiCallback callback)
   //Fetch withdraw history
   getWithdrawHistory(Map map, ApiCallback callback)
   //Submit a withdraw request.
   submitWithdraw(Map map, ApiCallback callback)
   //Depth Websocket Endpoint
   wsDepth(String symbol, WebSocketListener socketListener)
   //Kline Websocket Endpoint
   wsKline(String symbol, String interval, WebSocketListener socketListener) 
   //Trades Websocket Endpoint
   wsAggTrade(String symbol, WebSocketListener socketListener)
   //User Data Websocket Endpoint
   wsUserData(String key, WebSocketListener socketListener)

   

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.