package se.koc.trader.exchange.binance;

import zutil.net.ws.WSInterface;
import zutil.parser.DataNode;

/**
 * @see <a href="https://github.com/binance/binance-spot-api-docs/blob/master/rest-api.md">Binance REST API sdocumentation</a>
 */
public interface BinanceRestAPI extends WSInterface {
    enum CandlestickInterval {
        Minute("1m"), Minute_x3("3m"), Minute_x5("5m"), Minute_x15("15m"), Minute_x30("30m"),
        Hour("1h"), Hour_x2("2h"), Hour_x4("4h"), Hour_x6("6h"), Hour_x8("8h"), Hour_x12("12h"),
        Day("1d"), Day_x3("3d"),
        Week("1w"),
        Month("1M");

        String interval;

        CandlestickInterval(String interval) {
            this.interval = interval;
        }

        public String toString() {
            return interval;
        }
    }


    /**
     * Test connectivity to the Rest API and get the current server time.
     * <p></p><pre>GET /api/v3/time</pre>
     *
     * @return the current server time in EPOC, e.g. <pre>{"serverTime": 1499827319559}</pre>
     */
    @WSPath("/api/v3/time")
    DataNode getServerTime();

    /**
     * Current exchange trading rules and symbol information.
     * <p></p><pre>GET /api/v3/exchangeInfo</pre>
     */
    @WSPath("/api/v3/exchangeInfo")
    DataNode getExchangeInfo();

    /**
     * Kline/candlestick bars for a symbol, method will return the latest data.
     * Klines are uniquely identified by their open time.
     * <p></p><pre>GET /api/v3/klines</pre>
     *
     * @param symbol    is the symbol identity
     * @param interval  is the intervall of candlestick data
     * @param limit     is the maximum amount of candlesticks to return, max is 1000
     */
    @WSPath("/api/v3/klines")
    DataNode getCandlestickData(String symbol, CandlestickInterval interval, int limit);

    /**
     * Kline/candlestick bars for a symbol.
     * Klines are uniquely identified by their open time.
     * <p></p><pre>GET /api/v3/klines</pre>
     *
     * @param symbol    is the symbol identity
     * @param interval  is the intervall of candlestick data
     * @param startTime is the start of the time range of the data
     * @param endTime   is the end of the time range for data
     * @param limit     is the maximum amount of candlesticks to return, max is 1000
     */
    @WSPath("/api/v3/klines")
    DataNode getCandlestickData(String symbol, CandlestickInterval interval, long startTime, long endTime, int limit);

    /**
     * Latest price for a symbol.
     * <p></p><pre>GET /api/v3/ticker/price</pre>
     *
     * @param symbol    is the symbol identity
     * @return JSON example => <pre>{"symbol": "LTCBTC", "price": "4.00000200"}</pre>
     */
    @WSPath("/api/v3/ticker/price")
    DataNode getPrice(String symbol);
}
