-
Notifications
You must be signed in to change notification settings - Fork 5
/
Poloniex.php
114 lines (99 loc) · 2.56 KB
/
Poloniex.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<?php
class Poloniex
{
protected $key = '';
protected $secret = '';
/**
* Poloniex constructor.
*
* @param null $key
* @param null $secret
*/
public function __construct($key = null, $secret = null)
{
$this->key = $key;
$this->secret = $secret;
}
/**
* @return array
*/
public function returnTicker()
{
return $this->queryPublic('returnTicker');
}
/**
* @return array
*/
public function return24hVolume()
{
return $this->queryPublic('return24hVolume');
}
/**
* @param null $currenyPair
*
* @return array
*/
public function returnOrderBook($currencyPair = null)
{
if ($currencyPair === null) {
$currencyPair = 'all';
}
return $this->queryPublic('returnOrderBook¤cyPair='.$currencyPair);
}
/**
* @param null $currenyPair
* @param $start (UNIX TIME)
* @param $end (UNIX TIME)
*
* @return array
*/
public function returnTradeHistory($currencyPair, $start, $end)
{
if ($currencyPair === null) {
$currencyPair = 'all';
}
return $this->queryPublic('returnOrderBook¤cyPair='.$currencyPair.'&start='.$start.'&end='.$end);
}
/**
* @param null $currencyPair
* @param $start (UNIX TIME)
* @param $end (UNIX TIME)
* @param $period (candlestick period in seconds; valid values are 300, 900, 1800, 7200, 14400, and 86400)
*
* @return array
*/
public function returnChartData($currencyPair, $start, $end, $period)
{
if ($currencyPair === null) {
$currencyPair = 'all';
}
return $this->queryPublic('returnChartData¤cyPair='.$currencyPair.'&start='.$start.'&end='.$end.'&period='.$period);
}
/**
* @return array
*/
public function returnCurrencies()
{
return $this->queryPublic('returnCurrencies');
}
/**
* @param $currency (Example: BTC)
*
* @return array
*/
public function returnLoanOrders($currency)
{
return $this->queryPublic('returnCurrencies¤cy='.$currency);
}
// https://poloniex.com/public?command=returnChartData¤cyPair=BTC_XMR&start=1405699200&end=9999999999&period=14400
/**
* @param $command
*
* @return array
*/
private function queryPublic($command)
{
$uri = file_get_contents('https://poloniex.com/public?command='.$command);
return json_decode($uri, true);
}
}