Convert php code to java for [login to view URL] access - repost
$10-30 AUD
Paid on delivery
I am working on a trading bot for [url removed, login to view] but I cannot get the code to work correctly. Their web page lists an example in php see [url removed, login to view]
What I like is the function bter_query php to be rewritten in java. The result should be that the function can be called and obtain the balance for the currency on the web site. I will supply the key and secret the function requires.
Thus the delivery for this project is a single java file that when run will obtain the balances from [url removed, login to view]
You are free to use additional free libraries like those supplied from Apache as required.
Below is the example from their web site. I have removed a few lines as they run examples not required. Hopefully it will still run in php and all you need to do is convert it to java.
<?php
function bter_query($path, array $req = array()) {
// API settings, add your Key and Secret at here
$key = '';
$secret = '';
// generate a nonce to avoid problems with 32bits systems
$mt = explode(' ', microtime());
$req['nonce'] = $mt[1].substr($mt[0], 2, 6);
// generate the POST data string
$post_data = http_build_query($req, '', '&');
$sign = hash_hmac('sha512', $post_data, $secret);
// generate the extra headers
$headers = array(
'KEY: '.$key,
'SIGN: '.$sign,
);
// curl handle (initialize if required)
static $ch = null;
if (is_null($ch)) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERAGENT,
'Mozilla/4.0 (compatible; Bter PHP bot; '.php_uname('a').'; PHP/'.phpversion().')'
);
}
curl_setopt($ch, CURLOPT_URL, '[url removed, login to view]'.$path);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
// run the query
$res = curl_exec($ch);
if ($res === false) throw new Exception('Curl error: '.curl_error($ch));
//echo $res;
$dec = json_decode($res, true);
if (!$dec) throw new Exception('Invalid data: '.$res);
return $dec;
}
function get_top_rate($pair, $type='BUY') {
$rate = 0;
// our curl handle (initialize if required)
static $ch = null;
if (is_null($ch)) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERAGENT,
'Mozilla/4.0 (compatible; Bter PHP bot; '.php_uname('a').'; PHP/'.phpversion().')'
);
}
curl_setopt($ch, CURLOPT_URL, '[url removed, login to view]'.$pair);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
// run the query
$res = curl_exec($ch);
if ($res === false) throw new Exception('Could not get reply: '.curl_error($ch));
//echo $res;
$dec = json_decode($res, true);
if (!$dec) throw new Exception('Invalid data: '.$res);
if (strtoupper($type) == 'BUY') {
$r = $dec['bids'][0];
$rate = $r[0];
} else {
$r = end($dec['asks']);
$rate = $r[0];
}
return $rate;
}
try {
// example 1: get funds
var_dump(bter_query('1/private/getfunds'));
} catch (Exception $e) {
echo "Error:".$e->getMessage();
}
?>
Project ID: #5252609
About the project
7 freelancers are bidding on average $64 for this job
We are an experienced team of php developers. we will provide you complete Solution as per your need