Skip to content

Commit 1177c0b

Browse files
committed
Initial functionality classes commit.
1 parent 8ab11a5 commit 1177c0b

5 files changed

+934
-0
lines changed

src/Poloniex.php

+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
<?php
2+
3+
namespace poloniex\api;
4+
5+
use poloniex\api\PoloniexAPIPublic;
6+
7+
/**
8+
* Poloniex API Wrapper.
9+
*
10+
* @category Poloniex API
11+
* @author Dmytro Zarezenko <dmytro.zarezenko@gmail.com>
12+
* @copyright (c) 2017, Dmytro Zarezenko
13+
*
14+
* @git https://github.com/dzarezenko/poloniex-api
15+
* @license http://opensource.org/licenses/MIT
16+
*/
17+
class Poloniex extends PoloniexAPITrading {
18+
19+
private $balances = null;
20+
private $completeBalances = null;
21+
22+
private $depositAddresses = null;
23+
24+
public function returnTicker() {
25+
return PoloniexAPIPublic::returnTicker();
26+
}
27+
28+
public function return24hVolume() {
29+
return PoloniexAPIPublic::return24hVolume();
30+
}
31+
32+
public function returnOrderBook($currencyPair = "all", $depth = null) {
33+
return PoloniexAPIPublic::returnOrderBook($currencyPair, $depth);
34+
}
35+
36+
public function returnPublicTradeHistory($currencyPair, $start, $end) {
37+
return PoloniexAPIPublic::returnTradeHistory($currencyPair, $start, $end);
38+
}
39+
40+
public function returnPublicLastTradeHistory($currencyPair, $timePeriod) {
41+
$time = time();
42+
43+
return PoloniexAPIPublic::returnTradeHistory($currencyPair, $time - $timePeriod, $time);
44+
}
45+
46+
public function returnChartData($currencyPair, $period, $start, $end) {
47+
return PoloniexAPIPublic::returnChartData($currencyPair, $period, $start, $end);
48+
}
49+
50+
public function returnCurrencies() {
51+
return PoloniexAPIPublic::returnCurrencies();
52+
}
53+
54+
public function returnLoanOrders($currency = null) {
55+
return PoloniexAPIPublic::returnLoanOrders($currency);
56+
}
57+
58+
//Authenticated Methods
59+
public function returnBalances($reload = false) {
60+
if (is_null($this->balances) || $reload) {
61+
$this->balances = parent::returnBalances();
62+
}
63+
64+
return $this->balances;
65+
}
66+
67+
public function returnCompleteBalances($account = null, $reload = false) {
68+
if (is_null($this->completeBalances) || $reload) {
69+
$this->completeBalances = parent::returnCompleteBalances($account);
70+
}
71+
72+
return $this->completeBalances;
73+
}
74+
75+
public function returnDepositAddresses($reload = false) {
76+
if (is_null($this->depositAddresses) || $reload) {
77+
$this->depositAddresses = parent::returnDepositAddresses();
78+
}
79+
80+
return $this->depositAddresses;
81+
}
82+
83+
}

src/PoloniexAPIConf.php

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
namespace poloniex\api;
4+
5+
/**
6+
* Poloniex API Configuration constants.
7+
*
8+
* @category Poloniex API
9+
* @author Dmytro Zarezenko <dmytro.zarezenko@gmail.com>
10+
* @copyright (c) 2017, Dmytro Zarezenko
11+
*
12+
* @git https://github.com/dzarezenko/poloniex-api
13+
* @license http://opensource.org/licenses/MIT
14+
*/
15+
class PoloniexAPIConf {
16+
17+
const URL_PUBLIC = "https://poloniex.com/public";
18+
const URL_TRADING = "https://poloniex.com/tradingApi";
19+
20+
const ACCOUNT_EXCHANGE = 'exchange';
21+
const ACCOUNT_MARGIN = 'margin';
22+
const ACCOUNT_LENDING = 'lending';
23+
24+
public static $accounts = [
25+
self::ACCOUNT_EXCHANGE, self::ACCOUNT_MARGIN, self::ACCOUNT_LENDING
26+
];
27+
28+
}

src/PoloniexAPIPublic.php

+141
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
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+
. "&currencyPair={$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+
. "&currencyPair={$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+
. "&currencyPair={$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.= "&currency={$currency}";
136+
}
137+
138+
return Request::json($request);
139+
}
140+
141+
}

0 commit comments

Comments
 (0)