forked from atlasats/atlasats-php
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.php
69 lines (53 loc) · 1.88 KB
/
client.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
<?php
require_once "unirest-php/lib/Unirest.php";
class AtlasClient {
private $baseurl;
private $apikey;
function __construct($baseurl, $apikey) {
$this->baseurl = $baseurl;
$this->apikey = $apikey;
}
function _headers() {
return array("Accept" => "application/json", "Authorization" => "Token token=\"" . $this->apikey . "\"");
}
function _get($path, $params) {
$resp = Unirest::get($this->baseurl . $path, $this->_headers(), $params);
return $resp->body;
}
function _post($path, $params) {
$resp = Unirest::post($this->baseurl . $path, $this->_headers(), $params);
return $resp->body;
}
function _delete($path, $params) {
$resp = Unirest::delete($this->baseurl . $path, $this->_headers(), $params);
return $resp->body;
}
function account_info() {
return $this->_get("/api/v1/account");
}
function place_limit_order($item, $currency, $side, $quantity, $price) {
return $this->_post("/api/v1/orders", array("item" => $item, "currency" => $currency, "side" => $side, "quantity" => $quantity, "type" => "limit", "price" => $price));
}
function place_market_order($item, $currency, $side, $quantity) {
return $this->_post("/api/v1/orders", array("item" => $item, "currency" => $currency, "side" => $side, "quantity" => $quantity, "type" => "market"));
}
function order_info($orderid) {
return $this->_get("/api/v1/orders/" . $orderid);
}
function cancel_order($orderid) {
return $this->_delete("/api/v1/orders/" . $orderid);
}
function recent_orders() {
return $this->_get("/api/v1/orders");
}
function symbols() {
return $this->_get('/api/v1/market/symbols')
}
function book($item, $currency) {
return $this->_get("/api/v1/market/book", array("item" => $item, "currency" => $currency));
}
function recent_trades($item, $currency) {
return $this->_get("/api/v1/market/trades/recent", array("item" => $item, "currency" => $currency));
}
}
?>