|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace poloniex\api; |
| 4 | + |
| 5 | +use poloniex\api\PoloniexAPIConf; |
| 6 | +use poloniex\api\tools\Request; |
| 7 | + |
| 8 | +/** |
| 9 | + * Poloniex Public API Methods. |
| 10 | + * |
| 11 | + * Please note that making more than 6 calls per second to the public API, or |
| 12 | + * repeatedly and needlessly fetching excessive amounts of data, can result in |
| 13 | + * your IP being banned. |
| 14 | + * |
| 15 | + * There are six public methods, all of which take HTTP GET requests and return |
| 16 | + * output in JSON format. |
| 17 | + * |
| 18 | + * @link URL https://poloniex.com/support/api/ |
| 19 | + * |
| 20 | + * @category Poloniex API |
| 21 | + * @author Dmytro Zarezenko <dmytro.zarezenko@gmail.com> |
| 22 | + * @copyright (c) 2017, Dmytro Zarezenko |
| 23 | + * |
| 24 | + * @git https://github.com/dzarezenko/poloniex-api |
| 25 | + * @license http://opensource.org/licenses/MIT |
| 26 | + */ |
| 27 | +class PoloniexAPIPublic { |
| 28 | + |
| 29 | + /** |
| 30 | + * Returns the ticker for all markets. |
| 31 | + * |
| 32 | + * @return json |
| 33 | + */ |
| 34 | + public static function returnTicker() { |
| 35 | + return Request::json( |
| 36 | + PoloniexAPIConf::URL_PUBLIC . '?command=returnTicker' |
| 37 | + ); |
| 38 | + } |
| 39 | + |
| 40 | + /** |
| 41 | + * Returns the 24-hour volume for all markets, plus totals for primary |
| 42 | + * currencies. |
| 43 | + * |
| 44 | + * @return json |
| 45 | + */ |
| 46 | + public static function return24hVolume() { |
| 47 | + return Request::json( |
| 48 | + PoloniexAPIConf::URL_PUBLIC . '?command=return24hVolume' |
| 49 | + ); |
| 50 | + } |
| 51 | + |
| 52 | + /** |
| 53 | + * Returns the order book for a given market, as well as a sequence number |
| 54 | + * for use with the Push API and an indicator specifying whether the market |
| 55 | + * is frozen. You may set currencyPair to "all" to get the order books of |
| 56 | + * all markets. |
| 57 | + * |
| 58 | + * @param string $currencyPair In the 'BTC_NXT' format or 'all'. |
| 59 | + * @param integer $depth Depth. |
| 60 | + * |
| 61 | + * @return json |
| 62 | + */ |
| 63 | + public static function returnOrderBook($currencyPair = "all", $depth = null) { |
| 64 | + $request = PoloniexAPIConf::URL_PUBLIC . "?command=returnOrderBook" |
| 65 | + . "¤cyPair={$currencyPair}"; |
| 66 | + |
| 67 | + if ($depth) { |
| 68 | + $request.= "&depth={$depth}"; |
| 69 | + } |
| 70 | + |
| 71 | + return Request::json($request); |
| 72 | + } |
| 73 | + |
| 74 | + /** |
| 75 | + * Returns the past 200 trades for a given market, or up to 50,000 trades |
| 76 | + * between a range specified in UNIX timestamps by the "start" and "end" GET |
| 77 | + * parameters. |
| 78 | + * |
| 79 | + * @param type $currencyPair In the 'BTC_NXT' format. |
| 80 | + * @param type $start Start timestamp. |
| 81 | + * @param type $end End timestamp. |
| 82 | + * |
| 83 | + * @return json |
| 84 | + */ |
| 85 | + public static function returnTradeHistory($currencyPair, $start, $end) { |
| 86 | + return Request::json( |
| 87 | + PoloniexAPIConf::URL_PUBLIC . "?command=returnTradeHistory" |
| 88 | + . "¤cyPair={$currencyPair}" |
| 89 | + . "&start={$start}&end={$end}" |
| 90 | + ); |
| 91 | + } |
| 92 | + |
| 93 | + /** |
| 94 | + * Returns candlestick chart data. |
| 95 | + * "Start" and "end" are given in UNIX timestamp format and used to specify the |
| 96 | + * date range for the data returned. |
| 97 | + * |
| 98 | + * @param type $currencyPair In the 'BTC_NXT' format. |
| 99 | + * @param type $period Candlestick period in seconds: |
| 100 | + * valid values are 300, 900, 1800, 7200, 14400, and 86400. |
| 101 | + * @param type $start Start time in the UNIX timestamp format. |
| 102 | + * @param type $end End time in UNIX timestamp format. |
| 103 | + * |
| 104 | + * @return json |
| 105 | + */ |
| 106 | + public static function returnChartData($currencyPair, $period, $start, $end) { |
| 107 | + return Request::json( |
| 108 | + PoloniexAPIConf::URL_PUBLIC . "?command=returnChartData" |
| 109 | + . "¤cyPair={$currencyPair}" |
| 110 | + . "&start={$start}&end={$end}" |
| 111 | + . "&period={$period}" |
| 112 | + ); |
| 113 | + } |
| 114 | + |
| 115 | + /** |
| 116 | + * Returns information about currencies. |
| 117 | + * |
| 118 | + * @return json |
| 119 | + */ |
| 120 | + public static function returnCurrencies() { |
| 121 | + return Request::json(PoloniexAPIConf::URL_PUBLIC . '?command=returnCurrencies'); |
| 122 | + } |
| 123 | + |
| 124 | + /** |
| 125 | + * Returns the list of loan offers and demands for a given currency, |
| 126 | + * specified by the "currency" GET parameter. |
| 127 | + * |
| 128 | + * @param string $currency Currency name. |
| 129 | + * |
| 130 | + * @return json |
| 131 | + */ |
| 132 | + public static function returnLoanOrders($currency = null) { |
| 133 | + $request = PoloniexAPIConf::URL_PUBLIC . '?command=returnLoanOrders'; |
| 134 | + if ($currency) { |
| 135 | + $request.= "¤cy={$currency}"; |
| 136 | + } |
| 137 | + |
| 138 | + return Request::json($request); |
| 139 | + } |
| 140 | + |
| 141 | +} |
0 commit comments