1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
| 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')
|