栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

Kraken API在Java中的实现

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Kraken API在Java中的实现

这是一个工作示例:

static String key = "---myKey---";static String secret = "---mySecret---";String nonce, signature, data, path;static String domain = "https://api.kraken.com";void account_balance() {    nonce = String.valueOf(System.currentTimeMillis());    data = "nonce=" + nonce;    path = "/0/private/Balance";    calculateSignature();    String answer = post(domain + path, data);    // on empty accounts, returns {"error":[],"result":{}}    // this is a known Kraken bug    ...}String post(String address, String output) {    String answer = "";    HttpsURLConnection c = null;    try {        URL u = new URL(address);         c = (HttpsURLConnection)u.openConnection();        c.setRequestMethod("POST");        c.setRequestProperty("API-Key", key);        c.setRequestProperty("API-Sign", signature);        c.setDoOutput(true);        DataOutputStream os = new DataOutputStream(c.getOutputStream());        os.writeBytes(output);        os.flush();        os.close();        BufferedReader br = null;        if(c.getResponseCode() >= 400) { System.exit(1);        }        br = new BufferedReader(new InputStreamReader((c.getInputStream())));        String line;        while ((line = br.readLine()) != null) answer += line;    } catch (Exception x) {        System.exit(1);    } finally {        c.disconnect();    }    return answer;        }void calculateSignature() {    signature = "";    try {        MessageDigest md = MessageDigest.getInstance("SHA-256");        md.update((nonce + data).getBytes());        Mac mac = Mac.getInstance("HmacSHA512");        mac.init(new SecretKeySpec(base64.deprebase64(secret.getBytes()), "HmacSHA512"));        mac.update(path.getBytes());        signature = new String(base64.enprebase64(mac.doFinal(md.digest())));    } catch(Exception e) {}    return;}


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/483584.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号