Bitshares Python库的文档并没有写如果在一个tx中下多个单的方法,经过看源码,找到了方法。
现总结下代码
from bitshares import BitShares
from bitshares.market import Market
from bitshares.asset import Asset
from bitshares.account import Account
from bitshares.utils import formatTimeFromNow
from bitsharesbase import transactions, memo, account, operations, objects
API_URL = 'ws://127.0.0.1:8090/ws'
PRIV_KEY = '这是账号私钥'
ACCOUNT_NAME = 'ety001'
# 创建连接
bitshares = BitShares(API_URL, keys=PRIV_KEY)
# 创建账号实体
importAccount = Account(ACCOUNT_NAME, blockchain_instance=bitshares)
# 拿到 orderbook
market = Market('BTS:CNY', blockchain_instance=bitshares)
orderbook = market.orderbook(1)
sellAssetId = orderbook['bids'][0]['quote']['asset']['id']
receiveAssetId = orderbook['bids'][0]['base']['asset']['id']
amountToSell = 3 * 10 ** orderbook['bids'][0]['quote']['asset']['precision']
receiveAmount = 5 * 10 ** orderbook['bids'][0]['base']['asset']['precision']
# 创建订单
op1 = operations.Limit_order_create(
**{
"fee": {"amount": 0, "asset_id": "1.3.0"},
"seller": importAccount['id'],
"amount_to_sell": {
"amount": int(round(amountToSell)),
"asset_id": sellAssetId,
},
"min_to_receive": {
'amount': int(round(receiveAmount)),
"asset_id": receiveAssetId,
},
"expiration": formatTimeFromNow(60 * 60 * 24 * 7),
"fill_or_kill": True,
"extensions": [],
}
)
op2 = operations.Limit_order_create(
**{
"fee": {"amount": 0, "asset_id": "1.3.0"},
"seller": importAccount['id'],
"amount_to_sell": {
"amount": int(round(amountToSell)),
"asset_id": sellAssetId,
},
"min_to_receive": {
'amount': int(round(receiveAmount)),
"asset_id": receiveAssetId,
},
"expiration": formatTimeFromNow(60 * 60 * 24 * 7),
"fill_or_kill": True,
"extensions": [],
}
)
opList = []
opList.append(op1)
opList.append(op2)
# 下单
bitshares.finalizeOp(opList, ACCOUNT_NAME, 'active')
说明:
- 需要连接获取数据的方法,请使用参数
blockchain_instance
把你自己创建的对象传入,
否则连接的API
并不是你指定的。默认连接库作者的API
。- 买入卖出数量需要转换成整数,即乘以
precision
ET碎碎念,每周一,晚六点一刻更新,欢迎订阅
欢迎使用 SteemEditor 来编写文章,获取 @steemeditor.bot 的点赞!
感谢你的阅读,我是中文区见证人之一,欢迎通过 SteemConnect 来给我投票,或者打开 https://steemitwallet.com/~witnesses 页面,输入 ety001 进行投票。
中文区的见证人目前有:
支持一下他们(按字母顺序),一人可以有30票:
Thank you for reading. I'm a witness. I would really appreciate your witness vote! You can vote by SteemConnect. Or open https://steemitwallet.com/~witnesses page, input ety001 to vote.
@tipu curate
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Upvoted 👌 (Mana: 5/10 - need recharge?)
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit