请把Python翻译成Java

李海华 2017-10-11 04:12:30
import requests  # pip install requests
import json
import base64
import hashlib
import hmac
import os
import time #for nonce

class BitfinexClient(object):
BASE_URL = "https://api.bitfinex.com/"
KEY=os.environ["BFX_KEY"]
SECRET=os.environ["BFX_SECRET"]

def _nonce(self):
"""
Returns a nonce
Used in authentication
"""
return str(int(round(time.time() * 10000)))

def _headers(self, path, nonce, body):
signature = "/api/" + path + nonce + body
h = hmac.new(self.SECRET, signature, hashlib.sha384)
signature = h.hexdigest()
return {
"bfx-nonce": nonce,
"bfx-apikey": self.KEY,
"bfx-signature": signature,
"content-type": "application/json"
}

def req(self, path, params = {}):
nonce = self._nonce()
body = params
rawBody = json.dumps(body)
headers = self._headers(path, nonce, rawBody)
url = self.BASE_URL + path
resp = requests.post(url, headers=headers, data=rawBody, verify=True)
return resp

def active_orders(self):
"""
Fetch active orders
"""
response = self.req("v2/auth/r/orders")
if response.status_code == 200:
return response.json()
else:
print response.status_code
print response
return ''

client = BitfinexClient()
print client.active_orders()
...全文
178 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
李海华 2017-10-11
  • 打赏
  • 举报
回复
谢谢你的建议
混沌鳄鱼 2017-10-11
  • 打赏
  • 举报
回复
建议你发到java版去吧,这分数最好再提高点儿。 有人可能为了练手会帮你的。 我以前用过java但是很久不用了,能看得懂写起来困难了。
李海华 2017-10-11
  • 打赏
  • 举报
回复
帮我改,可加好友,发红包

37,721

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • IT.BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧