请把Python翻译成Java,谢谢

李海华 2017-10-11 12:38:34
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()
...全文
269 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
GoodCoder666 2020-04-11
  • 打赏
  • 举报
回复
李海华 2017-10-11
  • 打赏
  • 举报
回复
没分了,要不加我好友
一个治疗术 2017-10-11
  • 打赏
  • 举报
回复
你确定一分有人会帮你改???
魏飞翔 2017-10-11
  • 打赏
  • 举报
回复
1分
李海华 2017-10-11
  • 打赏
  • 举报
回复
帮改就发红包
李德胜1995 2017-10-11
  • 打赏
  • 举报
回复

23,404

社区成员

发帖
与我相关
我的任务
社区描述
Java 非技术区
社区管理员
  • 非技术区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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