Hit the au Kabu Com Securities kabu station API with php!
Create up to the token acquisition place.
Although I’m posting the password, it is miso to send it in JSON. Note that if you send it here as a query parameter normally, a 4001005 parameter conversion error will occur.
$url = "http://localhost:18081/kabusapi/token";
$data = ['APIPassword' =>'mypass'];
$opts = [
'http' => [
'method' => "POST",
'header'=> "Content-type: application/json\r\n" ."Accept: application/json\r\n",
'content' => json_encode($data),
'ignore_errors' => true,
'protocol_version' => '1.1'
]
];
$context = stream_context_create($opts);
$json = file_get_contents($url, false, $context);
if (isset($http_response_header)) {
$pos = strpos($http_response_header[0], '200');
if ($pos === false) {
// error handling
exit;
}
}
if (!$json) {
// error handling
exit;
}
$response = json_decode($json, true);
if ($response['ResultCode'] === 0) {
$apikey = $response['Token'];
} else {
// error handling
exit;
}
Cancel all API stock registration.
It is miso to send Content-Length: 0.
An error certainly occurred when it was executed when no API brand was registered.
If the port is 18080, it is the actual production, but in the verification environment, I can not register the stock in the first place.
$url = "http://localhost:18080/kabusapi/unregister/all";
$opts = [
'http' => [
'method' => "PUT",
'header'=> "Content-type: application/json\r\nContent-Length: 0\r\n"
. "X-API-KEY: ". $apikey,
'ignore_errors' => true,
'protocol_version' => '1.1'
]
];
$context = stream_context_create($opts);
$json = file_get_contents($url, false, $context);
if (isset($http_response_header)) {
$pos = strpos($http_response_header[0], '200');
if ($pos === false) {
// error handling
}
}
if (!$json) {
// error handling
}
$response = json_decode($json, true);