This repository has been archived by the owner on Aug 13, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
CcexAPI.php
97 lines (72 loc) · 2.71 KB
/
CcexAPI.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
<?php
/**
* API-call related functions
*
* @author Remdev
* @license MIT License - https://github.com/Remdev/PHP-ccex-api
*/
class CcexAPI {
protected $api_url = 'https://c-cex.com/t/';
protected $api_key;
public function __construct($api_key = '') {
$this->api_key = $api_key;
}
protected function jsonQuery($url) {
$opts = array('http' =>
array(
'method' => 'GET',
'timeout' => 10
)
);
$context = stream_context_create($opts);
$feed = file_get_contents($url, false, $context);
if($feed == 'Empty error'){
return array('error' => 'Invalid parametres');
}else{
return json_decode($feed,true);
}
}
public function getTickerInfo($pair){
$json = $this->jsonQuery($this->api_url.$pair.'.json');
return $json['ticker'];
}
public function getPairs(){
$json = $this->jsonQuery($this->api_url.'pairs.json');
return $json['pairs'];
}
public function getVolumes($hours=24,$pair=false){
$url = ($pair) ? 'volume' : 'lastvolumes&pair='.$pair.'&';
return $this->jsonQuery($this->api_url."s.html?a=".$url."&h=".$hours);
}
public function getOrders($pair,$self = 0){
$self = intval( (bool)$self );//return only 0 or 1
return $this->jsonQuery($this->api_url."r.html?key={$this->api_key}&a=orderlist&self={$self}&pair={$pair}");
}
public function getHistory($pair,$fromTime = false,$toTime = false,$self = false){
if($fromTime === false){
$fromTime = 0;
}
if($toTime === false){
$toTime = time();
}
$fromDate = date('Y-d-m',(int)$fromTime);
$toDate = date('Y-d-m',(int)$toTime);
$url = ($self) ? "r.html?key={$this->api_key}&" : "s.html?";
return $this->jsonQuery($this->api_url.$url."a=tradehistory&d1={$fromDate}&d2={$toDate}&pair={$pair}");
}
public function makeOrder($type,$pair,$quantity,$price){
if(strtolower($type) == 'sell'){
$type = 's';
}
if(strtolower($type) == 'buy'){
$type = 'b';
}
return $this->jsonQuery($this->api_url."r.html?key={$this->api_key}&a=makeorder&pair={$pair}&q={$quantity}&t={$type}&r={$price}");
}
public function cancelOrder($order){
return $this->jsonQuery($this->api_url."r.html?key={$this->api_key}&a=cancelorder&id={$order}");
}
public function getBalance(){
return $this->jsonQuery($this->api_url."r.html?key={$this->api_key}&a=getbalance");
}
}