-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexamples.php
174 lines (155 loc) · 3.99 KB
/
examples.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
<?php
// Include CEX API class
include_once("cex.class.php");
$api_username = false;
$api_key = false;
$api_secret = false;
$api_url = 'https://cex.io/api';
$api_cert = 'cacert.pem';
// Create CEX Object
$CEX = new CEX($api_username, $api_key, $api_secret, $api_url, $api_cert);
/*
* Public functions, can be used without providing API credentials
*/
/**
* symbols
* Returns an array of available symbol pairs
* @return array $symbols_pair
*/
$symbols = $CEX->symbols();
var_dump($symbols);
/**
* Ticker
* Get the symbols ticker
* @param string $symbol_pair
* @return array $response_array
*
* Returns JSON dictionary:
* last - last BTC price
* high - last 24 hours price high
* low - last 24 hours price low
* volume - last 24 hours volume
* bid - highest buy order
* ask - lowest sell order
*/
$ticker = $CEX->ticker('BTC/USD');
var_dump($ticker);
/**
* Last Price
* Last Price for each trading pair will be defined as price of the last executed order for this pair.
* @param string $symbol_pair
* @return array $response_array
*/
$last_price = $CEX->last_price('BTC/USD');
var_dump($last_price);
/**
* Converter
* Converts any amount of the currency to any other currency by multiplying the amount by the last price of the chosen pair according to the current exchange rate.
* @param string $symbol_pair
* @return array $response_array
*/
$convert = $CEX->convert('BTC/USD',1.0);
var_dump($convert);
/**
* Chart
* Allows building price change charts (daily, weekly, monthly) and showing historical point in any point of the chart
* @param int $lastHours
* @param int $maxRespArrSize
* @return array $response_array
*/
$price_stats = $CEX->price_stats('BTC/USD', 24, 10);
var_dump($price_stats);
/**
* Order Book
* Returns JSON dictionary with "bids" and "asks". Each is a list of open orders and each order is represented as a list of price and amount.
* @param int $depth - limit the number of bid/ask records returned (optional)
* @return array $response_array
*/
$order_book = $CEX->order_book('BTC/USD', false);
var_dump($order_book);
/**
* Trade history
* @param int $since - return trades with tid >= since
* @return array $response_array
*
* Returns a list of recent trades, where each trade is a JSON dictionary:
* tid - trade id
* amount - trade amount
* date - UNIX timestamp
*/
$trade_history = $CEX->trade_history('BTC/USD', 135039);
var_dump($trade_history);
/*
* Private functions, make sure to set your API crendentials to test these
*/
/**
* Balance
* @return array $response_array
*
* Returns JSON dictionary:
* available - available balance
* orders - balance in pending orders
* bonus - referral program bonus
*/
$balance = $CEX->balance();
var_dump($balance);
/**
* Place order
* @param string type - 'buy' or 'sell'
* @param float amount
* @param float price
* @return array $response_array
*
* Returns JSON dictionary representing order:
* id - order id
* time - timestamp
* type - buy or sell
* price - price
* amount - amount
* pending - pending amount (if partially executed)
*/
$place_order = $CEX->place_order('GHS/BTC','buy',1,0.0001);
var_dump($place_order);
/**
* Open orders
* @return array $response_array
*
* Returns JSON list of open orders. Each order is represented as dictionary:
* id - order id
* time - timestamp
* price - price
* amount - amount
* pending - pending amount (if partially executed)
*/
$open_orders = $CEX->open_orders('GHS/BTC');
var_dump($open_orders);
/**
* Cancel order
* @param int $id - order id
* @return bool
*
*/
$id = $place_order['id'];
$cancel_order = $CEX->cancel_order($id);
var_dump($cancel_order);
if ($cancel_order){
echo 'Order was cancelled'."\n";
} else {
echo 'Error cancelling order'."\n";
}
$open_orders = $CEX->open_orders('GHS/BTC');
var_dump($open_orders);
/**
* Hash Rate
* Returns overall hash rate in MH/s.
* @return array $response_array
*/
$hashrate = $CEX->hashrate();
var_dump($hashrate);
/**
* Workers Hash Rate
* Returns workers' hash rate and rejected shares.
* @return array $response_array
*/
$workers = $CEX->workers();
var_dump($workers);