使用python-bitshares 生成bitCNY喂价列表

in #python-bitshares6 years ago

在比特股的区块链浏览器上,我们可以查询bitCN这项资产的相关信息。
https://www.cryptofresh.com/a/CNY

喂价信息 / Feeds

区块链浏览器可以查询喂价信息


其中有一点对我而言很不方便,就是喂价是以CNY=>BTS的方式表示的,我的大脑没法处理这种价格。

尽管在区块链浏览器中可以点击来对调资产对,但是对调以后喂价信息没有啦。于是我就想能否用python-bitshares实现个显示喂价的功能。

Python 代码

经过一番了解,发现python-bitshares中的Asset类可以实现这个功能。

比如说使用Asset类的feeds属性获取喂价列表:

简单的示例代码如下:

from bitshares.asset import Asset
from prettytable import PrettyTable
from pprint import pprint
import operator

from bitshares import BitShares
bitshares = BitShares(node="wss://bitshares-api.wancloud.io/ws")

asset=Asset(asset="CNY", bitshares_instance=bitshares)

t = PrettyTable(["Producer", "Settlement Price", "CER", "MCR", "MSSR", "Time"])
feeds = list(asset.feeds)
feeds_sorted = sorted(feeds, key=operator.itemgetter('date'), reverse=True)

t.padding_width = 1
#t.align["Collateral"] = "r"
#t.align["Debt"] = "r"

for item in feeds_sorted:
        t.add_row([str(item['producer']['name']),
                        str(item['settlement_price']),
                        str(item['core_exchange_rate']),
                        str(item['maintenance_collateral_ratio']),
                        str(item['maximum_short_squeeze_ratio']),
                        str(item['date'])])

print(t)

执行效果

运行效果如下:

其它

我们还可以通过Asset类的feed属性来获取当前喂价信息

突然间发现自己就是个文盲,这些参数干啥的,两眼一抹黑

如果简单的想获取喂价信息,还是使用公众号查询方便:

😭哭,我明明记得我写文之前,价格4.5多呢。

封面图源:https://pixabay.com

参考文章

Sort:  

Nice post

@oflyhigh your posts are amezing like your ranking. Thanks for sharing. Please follow me @dreamlandsteem.

good post you fren

beautiful post keep going

I like to see your posts.

dane wonderfully

good informations friend
New Year will enter tonight with midnight
We hope that it will be better than 2017 and that there will be more progress and prosperity
Happy year to all and we wish all the struggle and diligence in this year to realize your dreams
Let us make this year a beautiful and happy year for all

Thanks for share ...

wooow, i like it, haha

Coin Marketplace

STEEM 0.28
TRX 0.12
JST 0.033
BTC 62991.27
ETH 3180.91
USDT 1.00
SBD 3.82