Convert php code to java for [login to view URL] access - repost

Completed Posted Dec 22, 2013 Paid on delivery
Completed 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();

}

?>

Java PHP

Project ID: #5252609

About the project

7 proposals Remote project Active Dec 23, 2013

Awarded to:

javabee4u

Hi, I can convert the php code to java and get the balance for the currency. DO you want it as standalone Java application? To brief about me, I have 6+ years of experience in Java/j2EE technologies with SCJP/SCBCD More

$30 AUD in 1 day
(16 Reviews)
4.6

7 freelancers are bidding on average $64 for this job

ambalaonline1

We are an experienced team of php developers. we will provide you complete Solution as per your need

$149 AUD in 3 days
(37 Reviews)
5.6
Meagan26

Hello, I have read through your project and I am incredibly interested in taking on your project. I am an experienced developer with a diploma in the field of web development. I have been working in the field of web More

$34 AUD in 1 day
(21 Reviews)
4.0
lightning236

A proposal has not yet been provided

$15 AUD in 1 day
(0 Reviews)
0.0