Skip to content

Commit c8672fc

Browse files
committed
added API functionality
1 parent 7fe73b4 commit c8672fc

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

public_html/api.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
require_once __DIR__ . '/../vendor/autoload.php';
3+
4+
$handler = new App\Handler();
5+
$handler->setAPIHeaders();
6+
7+
if(! $handler->parseRequest()) {
8+
$handler->apiError($handler->last_error);
9+
}
10+
11+
$requestRoot = $handler->solver->getRoot();
12+
if(empty($requestRoot)) {
13+
$handler->apiError($handler->solver->last_error);
14+
}
15+
16+
if($requestRoot == 'help') {
17+
echo App\HelpProvider::printHelp(); exit;
18+
}
19+
20+
$available_methods = ['market_depth', 'recent_trades', 'chart_data', 'price_change', 'price_current', 'order_book'];
21+
if(!in_array($requestRoot, $available_methods)) {
22+
$handler->apiError('method not found', 404);
23+
}
24+
25+
$data_path = __DIR__ . '/../cache/' . $requestRoot . '.json';
26+
$data_json = file_get_contents($data_path);
27+
if(! App\Utilities::isJson($data_json)) {
28+
$handler->apiError('Data request server error', 500);
29+
}
30+
31+
$handler->apiSuccess(json_decode($data_json));

0 commit comments

Comments
 (0)