PHP Nornet API: Getting error for subscribe command

Added by Zulfiqar almost 2 years ago

Hello,

I am implemented Nordnet API in PHP. I am able to access feeds using http. But when I try to access subscribe command, it gives error. Here code goes,

public function public_feed() {

$session_key = $this->session_key; // Session key I get from HTTP login
$hostname = "ssl://pub.api.test.nordnet.se";
$port = 443;
$fp = stream_socket_client("ssl://pub.api.test.nordnet.se:443", $errno, $errstr, 30,STREAM_CLIENT_ASYNC_CONNECT);
if (!$fp) {
echo "$errstr ($errno)<br />\n";
} else {
stream_set_timeout($fp, 100);
//stream_set_blocking($fp, 0);
fwrite($fp, '{"cmd":"login", "args":{"session_key":"$session_key", "service":"NEXTAPI"}}');
while (!feof($fp)) {
echo fgets($fp, 128); // ingenting skrivs ut, borde det det?
}
$info = stream_get_meta_data($fp);
echo "
";
            print_r($info);
            echo "
";
//sleep(5); 
// Subscribe to Nordnet B (identifier 1869) on Burgundy (marketplace 30).
$cmd = '{"cmd":"subscribe", "args":{"t":"price", "i":"1869", "m":30}}' . PHP_EOL;
fwrite($fp, $cmd);
$result = "";
while (!feof($fp)) {
$result .= fgets($fp, 128);
}
$info = stream_get_meta_data($fp);
echo "
";
            print_r($info);
            echo "
";
fclose($fp);
return json_decode($result);
}
}

Lines,
$cmd = '{"cmd":"subscribe", "args":{"t":"price", "i":"1869", "m":30}}' . PHP_EOL;
fwrite($fp, $cmd);
gives below error,

"Message: fwrite() [function.fwrite]: SSL operation failed with code 1. OpenSSL Error messages: error:140D00CF:SSL routines:SSL_write:protocol is shutdown"

I found that there is no code example available for PHP. Please guide me.


Replies (2)

RE: PHP Nornet API: Getting error for subscribe command - Added by Nordnet_Support almost 2 years ago

I suggest that you check out the new user guides that are out for Python3 and Java.

RE: PHP Nornet API: Getting error for subscribe command - Added by moses 6 days ago

Getting an error for subscribe command is not easy that it can be solved too well. You should have vast knowledge about it that may be helping you very well. In such a way everyone will be happy about that. And that will help you so well. cbd benefits

(1-2/2)