It was the Bitcointalk forum that inspired us to create Bitcointalksearch.org - Bitcointalk is an excellent site that should be the default page for anybody dealing in cryptocurrency, since it is a virtual gold-mine of data. However, our experience and user feedback led us create our site; Bitcointalk's search is slow, and difficult to get the results you need, because you need to log in first to find anything useful - furthermore, there are rate limiters for their search functionality.
The aim of our project is to create a faster website that yields more results and faster without having to create an account and eliminate the need to log in - your personal data, therefore, will never be in jeopardy since we are not asking for any of your data and you don't need to provide them to use our site with all of its capabilities.
We created this website with the sole purpose of users being able to search quickly and efficiently in the field of cryptocurrency so they will have access to the latest and most accurate information and thereby assisting the crypto-community at large.
public static String POLONIEX_SECRET_KEY = "my secret"; //KEY
public static String POLONIEX_API_KEY = "my key"; // TODO API KEY
public static void main(String[] args) {
try {
accessPoloniex();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static final long generateNonce(){
Date d = new Date();
return d.getTime();
}
public static final void accessPoloniex() throws IOException{
String nonce = new BigDecimal(Polo2.generateNonce()).toString();
String connectionString = "https://poloniex.com/tradingApi";
String queryArgs = "command=returnBalances";
String hmac512 = hmac512Digest(queryArgs, POLONIEX_SECRET_KEY);
// Produce the output
ByteArrayOutputStream out = new ByteArrayOutputStream();
Writer writer = new OutputStreamWriter(out, "UTF-8");
writer.append(queryArgs);
CloseableHttpClient httpClient = HttpClients.createDefault();
HttpPost post = new HttpPost(connectionString);
post.setHeader("Key", POLONIEX_API_KEY);
post.setHeader("Sign", hmac512);
post.setEntity(new ByteArrayEntity(out.toByteArray()));
Listparams = new ArrayList<>();
params.add(new BasicNameValuePair("nonce", nonce));
CloseableHttpResponse response = null;
Scanner in = null;
try
{
post.setEntity(new UrlEncodedFormEntity(params));
response = httpClient.execute(post);
// System.out.println(response.getStatusLine());
HttpEntity entity = response.getEntity();
in = new Scanner(entity.getContent());
while (in.hasNext())
{
System.out.println(in.next());
}
EntityUtils.consume(entity);
} finally
{
in.close();
response.close();
}
}
public static String hmac512Digest(String msg, String keyString) {
Mac shaMac;
try {
shaMac = Mac.getInstance("HmacSHA512");
SecretKeySpec keySpec = new SecretKeySpec(keyString.getBytes(), "HmacSHA512");
shaMac.init(keySpec);
final byte[] macData = shaMac.doFinal(msg.getBytes());
return Hex.encodeHexString(macData); //again with try/catch for InvalidKeyException
} catch (Exception e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
return null;
}
public static String POLONIEX_SECRET_KEY = "my secret"; //KEY
public static String POLONIEX_API_KEY = "my key"; // TODO API KEY
public static void main(String[] args) {
try {
accessPoloniex();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static final long generateNonce(){
Date d = new Date();
return d.getTime();
}
public static final void accessPoloniex() throws IOException{
String nonce = new BigDecimal(Polo2.generateNonce()).toString();
String connectionString = "https://poloniex.com/tradingApi";
String queryArgs = "command=returnBalances";
String hmac512 = hmac512Digest(queryArgs, POLONIEX_SECRET_KEY);
// Produce the output
ByteArrayOutputStream out = new ByteArrayOutputStream();
Writer writer = new OutputStreamWriter(out, "UTF-8");
writer.append(queryArgs);
CloseableHttpClient httpClient = HttpClients.createDefault();
HttpPost post = new HttpPost(connectionString);
post.setHeader("Key", POLONIEX_API_KEY);
post.setHeader("Sign", hmac512);
post.setEntity(new ByteArrayEntity(out.toByteArray()));
Listparams = new ArrayList<>();
params.add(new BasicNameValuePair("nonce", nonce));
CloseableHttpResponse response = null;
Scanner in = null;
try
{
post.setEntity(new UrlEncodedFormEntity(params));
response = httpClient.execute(post);
// System.out.println(response.getStatusLine());
HttpEntity entity = response.getEntity();
in = new Scanner(entity.getContent());
while (in.hasNext())
{
System.out.println(in.next());
}
EntityUtils.consume(entity);
} finally
{
in.close();
response.close();
}
}
public static String hmac512Digest(String msg, String keyString) {
Mac shaMac;
try {
shaMac = Mac.getInstance("HmacSHA512");
SecretKeySpec keySpec = new SecretKeySpec(keyString.getBytes(), "HmacSHA512");
shaMac.init(keySpec);
final byte[] macData = shaMac.doFinal(msg.getBytes());
return Hex.encodeHexString(macData); //again with try/catch for InvalidKeyException
} catch (Exception e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
return null;
}
...
conn.setRequestProperty("Key", "your public key");
//build your args query parameter String (needs to include "command", "nonce" ), e.g.
String queryArgs = "command=cancelOrder&orderNumber=12345"
//encrypt the queryArgs using HmacSHA512. In java that looks something like this
Mac shaMac = Mac.getInstance("HmacSHA512") //with try/catch for NoSuchAlgorithmException
SecretKeySpec keySpec = new SecretKeySpec(.getBytes(), "HmacSHA512");
shaMac.init(keySpec);
final byte[] macData = shaMac.doFinal(queryArgs.getBytes());
String result = Hex.encodeHexString(macData); //again with try/catch for InvalidKeyException
//this result you add as header param
conn.setRequestProperty("Sign", result);
//and the queryArgs themselves you write onto the connection's outputstream
OutputStreamWriter out = new OutputStreamWriter(conn.getOutputStream());
out.write(queryArgs);
...