Stellar开发中关于offer相关的总结

in #stellar6 years ago

最近完工的 StellarBot v0.0.8 对核心进行了重写,由于之前赶比赛进度,一直没有在offer这块搞明白。这次花了大量的时间来研究orderbook和创建offer这两部分的重要参数。这篇文章就是对于之前研究的一个总结。(是不是现在就已经开始晕了?一会order一会offer的。)

本文将会根据 base/counter 为交易单位来总结,如果对于 base/counter 还不明白的,请先看我之前写的 这篇文章,里面解释了这种单位的意思是怎样的。

Orderbook

GET /order_book?selling_asset_type={selling_asset_type}&selling_asset_code={selling_asset_code}&selling_asset_issuer={selling_asset_issuer}&buying_asset_type={buying_asset_type}&buying_asset_code={buying_asset_code}&buying_asset_issuer={buying_asset_issuer}&limit={limit}

上面的就是 OrderbookREST API。我们可以看到这个接口有以下参数:

namenotesdescriptionexample
selling_asset_typerequired, stringType of the Asset being soldnative
selling_asset_codeoptional, stringCode of the Asset being soldUSD
selling_asset_issueroptional, stringAccount ID of the issuer of the Asset being soldGA2HGBJIJKI6O4XEM7CZWY5PS6GKSXL6D34ERAJYQSPYA6X6AI7HYW36
buying_asset_typerequired, stringType of the Asset being boughtcredit_alphanum4
buying_asset_codeoptional, stringCode of the Asset being boughtBTC
buying_asset_issueroptional, stringAccount ID of the issuer of the Asset being boughtGD6VWBXI6NY3AOOR55RLVQ4MNIDSXE5JSAVXUTF35FRRI72LYPI3WL6Z
limitoptional, stringLimit the number of items returned20

(该表格来自 https://www.stellar.org/developers/horizon/reference/endpoints/orderbook-details.html

官方给的这张表格,感觉太不好理解了,以下是我总结出来的参数和 base/counter 的对应关系:

1.png

再结合着实际的数据来看一下(接口 返回数据与钱包数据的对应图):

注意 Orderbook 接口返回的数据里,买卖单的 amount 是不同货币的》

提交 Offer 的各种参数

Stellar 系统里把单个订单称作 offer,这就跟之前的 orderbook 感觉跟别扭。这样的命名别扭会一直贯穿整个开发过程,所以我直接在我的代码里用了 order 代替 offer

管理订单的接口文档 在这里 可以看到,我摘录过来相关的参数表格如下:

FieldTypeDescription
offer_idnumberOffer ID.
amountstringAmount of asset to be sold.
buying_asset_codestringThe code of asset to buy.
buying_asset_issuerstringThe issuer of asset to buy.
buying_asset_typestringType of asset to buy (native / alphanum4 / alphanum12)
pricestringPrice to buy a buying_asset
price_rObjectn: price numerator, d: price denominator
selling_asset_codestringThe code of asset to sell.
selling_asset_issuerstringThe issuer of asset to sell.
selling_asset_typestringType of asset to sell (native / alphanum4 / alphanum12)

这里面最需要注意的就是 price 的计算是不同于 orderbook 中的 price 的。,以下是我总结的参数(params)和 base/counter 的对应关系:

创意 - 9.png

总结

开发中,主要注意的就是各个位置的 priceamount 计算和其代表的意义。多对照钱包和接口返回数据看几遍,应该就可以慢慢的参透其中的奥义,也就能看明白我总结的两张图里面的意思。再开发的时候,我的这两张图就会起到类似公式一样的作用。



感谢你的阅读,我是中文区见证人之一,欢迎通过 SteemConnect 来给我投票,或者打开 https://steemit.com/~witnesses 页面,输入 ety001 进行投票。

2.gif

中文区的见证人目前有:
支持一下他们(按字母顺序),一人可以有30票


Thank you for reading. I'm a witness. I would really appreciate your witness vote! You can vote by SteemConnect. Or open https://steemit.com/~witnesses page, input ety001 to vote.

2.gif

Sort:  

我刚在feed里看到更新 发现你好厉害 👍 特来抱一下大腿 别拦我

Coin Marketplace

STEEM 0.15
TRX 0.12
JST 0.025
BTC 55910.18
ETH 2507.08
USDT 1.00
SBD 2.27