markets.py 文件源码

python
阅读 16 收藏 0 点赞 0 评论 0

项目:steemtools 作者: Netherdrake 项目源码 文件源码
def steem_btc_ticker():
        prices = {}
        urls = [
            "https://poloniex.com/public?command=returnTicker",
            "https://bittrex.com/api/v1.1/public/getticker?market=BTC-STEEM",
        ]
        rs = (grequests.get(u, timeout=2) for u in urls)
        responses = list(grequests.map(rs, exception_handler=lambda x, y: ""))

        for r in [x for x in responses if hasattr(x, "status_code") and x.status_code == 200 and x.json()]:
            if "poloniex" in r.url:
                data = r.json()["BTC_STEEM"]
                prices['poloniex'] = {'price': float(data['last']), 'volume': float(data['baseVolume'])}
            elif "bittrex" in r.url:
                data = r.json()["result"]
                price = (data['Bid'] + data['Ask']) / 2
                prices['bittrex'] = {'price': price, 'volume': 0}

        if len(prices) == 0:
            raise RuntimeError("Obtaining STEEM/BTC prices has failed from all sources.")

        return mean([x['price'] for x in prices.values()])
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号