-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathCryptorgApi.php
296 lines (252 loc) · 7.48 KB
/
CryptorgApi.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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
<?php
class CryptorgApi {
const API_URL = 'https://api.cryptorg.net';
private $apiKey;
private $apiSecret;
public function __construct($key, $secret)
{
$this->apiKey = $key;
$this->apiSecret = $secret;
}
/**
* _________________________________________________________________________________________________________________
*
* Public methods
* _________________________________________________________________________________________________________________
*/
/**
* Get Api status
* @return array
*/
public function status()
{
return $this->sendRequest('GET', 'api/status');
}
/**
* _________________________________________________________________________________________________________________
*
* Methods with bots
* _________________________________________________________________________________________________________________
*/
/**
* Get all user's bots
* @return array
*/
public function botList() {
return $this->sendRequest('GET', 'bot/all');
}
/**
* Get bot details
* @param array $params
* @return array
*/
public function botInfo($params)
{
return $this->sendRequest('GET', 'bot/info', $params);
}
/**
* Delete bot by id
* @param array $params
* @return array
*/
public function deleteBot($params)
{
return $this->sendRequest('GET', 'bot/delete', $params);
}
/**
* Create new bot
* @param array $params Query params
* @param array $attributes Post params
* @return array
*/
public function createBot($params, $attributes) {
return $this->sendRequest('POST', 'bot/create', $params, $attributes);
}
/**
* Create custom bot via preset
* @param $params
* @param $attributes
* @return array
*/
public function createBotPreset($params, $attributes)
{
return $this->sendRequest('POST', 'bot/create-preset', $params, $attributes);
}
/**
* Create new bot
* @param array $params Query params
* @param array $attributes Post params
* @return array
*/
public function updateBot($params, $attributes)
{
return $this->sendRequest('POST', 'bot/configure', $params, $attributes);
}
/**
* Activate Bot
* @param array $params
* @return array
*/
public function activateBot($params)
{
return $this->sendRequest('GET', 'bot/activate', $params);
}
/**
* Start bot force
* @param $params
* @return array
*/
public function startBotForce($params)
{
return $this->sendRequest('GET', 'bot/start-force', $params);
}
/**
* Deactivate Bot
* @param array $params
* @return array
*/
public function deactivateBot($params)
{
return $this->sendRequest('GET', 'bot/deactivate', $params);
}
/**
* Get bot logs
* @param array $params
* @return array
*/
public function getBotLogs($params = null)
{
return $this->sendRequest('GET', 'bot/logs', $params);
}
/**
* _________________________________________________________________________________________________________________
*
* Methods with deals
* _________________________________________________________________________________________________________________
*/
/**
* Freeze deal by id
* @param array $params
* @return array
*/
public function freezeDeal($params)
{
return $this->sendRequest('GET', 'deal/freeze', $params);
}
/**
* Unfreeze deal by id
* @param array $params
* @return array
*/
public function unFreezeDeal($params)
{
return $this->sendRequest('GET', 'deal/unfreeze', $params);
}
/**
* Update take profit of deal
* @param array $params
* @return array
*/
public function updateTakeProfit($params)
{
return $this->sendRequest('GET', 'deal/update-take-profit', $params);
}
/**
* Cancel a deal by id
* @param array $params
* @return array
*/
public function cancelDeal($params)
{
return $this->sendRequest('GET', 'deal/cancel', $params);
}
/**
* Cancel a deal by id
* @param array $params
* @return array
*/
public function dealInfo($params)
{
return $this->sendRequest('GET', 'deal/info', $params);
}
/**
* Get all user's analytic records
* @param array $params
* @return array
*/
public function getAnalytics($params = null)
{
return $this->sendRequest('GET', 'analytics/get', $params);
}
/**
* _________________________________________________________________________________________________________________
*
* Account methods
* _________________________________________________________________________________________________________________
*/
/**
* Get coin balance
* @param $params
* @return array
*/
public function getCoinBalance($params)
{
return $this->sendRequest('GET', 'account/get-coin-balance', $params);
}
/**
* Get list of all users access points
* @return array
*/
public function getAccessList()
{
return $this->sendRequest('GET', 'account/get-access-list');
}
/**
* Get list of all withdrawal
* @param $params
* @return array
*/
public function getWithdrawalHistory($params)
{
return $this->sendRequest('GET', 'account/get-withdrawal-history', $params);
}
/**
* _________________________________________________________________________________________________________________
*
* System methods
* _________________________________________________________________________________________________________________
*/
/**
* Create request to API
* @param string $method
* @param string $url
* @param string | null $params
* @param string | null $attributes
* @return array
*/
private function sendRequest($method, $url, $params = null, $attributes = null) {
$query = json_encode($params == null ? '' : http_build_query($params));
$query = str_replace('"', '', $query);
$currentDate = new DateTime();
$nonce = $currentDate->getTimestamp();
$strForSign = $url . '/' . $nonce . '/' . $query;
$hash = hash_hmac('sha256', base64_encode($strForSign) , $this->apiSecret);
$header = [
"CTG-API-SIGNATURE: $hash",
"CTG-API-KEY: " . $this->apiKey,
"CTG-API-NONCE: $nonce"
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, static::API_URL . '/' . $url . '?' . $query);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
if ($method == "POST") {
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $attributes);
}
$response = curl_exec($ch);
curl_close($ch);
return json_decode($response, true);
}
}