在上一课中,咱们介绍了如何在OceanOne交易比特币。OceanOne支持交易任何Mixin Network上的token,包括全部的ERC20和EOS token,不须要任何手续和费用,直接挂单便可。下面介绍如何将将一个ERC20 token挂上OceanOne交易!在掌握了ERC20 token以后,就能够把任何token在Ocean上买卖。git
此处咱们用一个叫作Benz的ERC20 token为例。这个token已经被充值进Mixin Network,你能够在区块链浏览器看到这个token在Mixin Network内部的总数和交易github
先将Benz币存入你的钱包,而后使用getAssets API读取它的UUID.json
调用 getAssets API 会返回json数据, 如:浏览器
if cmd == "aw" assetsInfo = walletAccount.read_assets() p "--------The Wallet Assets List-----------------" assetsInfo["data"].each { |x| puts x["symbol"] + " " + x["balance"] + " " + x["public_key"] + x["account_name"] + " " + x["account_tag"]} p "----------End of Wallet Assets --------------" end
调用 read_assets API的完整输出以下:ruby
"--------The Wallet Assets List-----------------" Benz 10.03 0x822664c2EFb27E2Eb4c4286f421B4BF6FB943fC6 ETH 0 0x822664c2EFb27E2Eb4c4286f421B4BF6FB943fC6 EOS 0 eoswithmixin b0adfae2f8828d15e11cb1fbe23d6096 USDT 1 1KB4RbV5W4MNybpjcJjULKNVXubfR5MJqA CNB 0.99999995 0x822664c2EFb27E2Eb4c4286f421B4BF6FB943fC6 BTC 0 1KB4RbV5W4MNybpjcJjULKNVXubfR5MJqA "----------End of Wallet Assets --------------" -------------------------------------------------------------------------
OceanOne支持三种基类价格: USDT, XIN, BTC, 即: Benz/USDT, Benz/XIN, Benz/BTC, 这儿示范Benz/USDT.bash
新币挂单后,须要等一分钟左右,等OceanOne来初始化新币的相关数据.dom
if ocmd == "s3" p "Input the price of ERC/USDT: " bprice = gets.chomp p "Input the amount of ERC20_BENZ: " amount = gets.chomp memo = Utils.GenerateOceanMemo(USDT_ASSET_ID,"A",bprice) p memo assetsInfo = walletAccount.read_asset(ERC20_BENZ) if assetsInfo["data"]["balance"].to_f > 0 && assetsInfo["data"]["balance"].to_f >= amount.to_f transInfo = walletAccount.create_transfer(walletAccount.encrypt_pin(DEFAULT_PIN), { asset_id: ERC20_BENZ, opponent_id: OCEANONE_BOT, amount: amount, trace_id: SecureRandom.uuid, memo: memo }) p transInfo p "The Order id is " + transInfo["data"]["trace_id"] + " It's needed by cancel-order!" else p "Not enough ERC20_BENZ" end end
新币挂单后,须要等一分钟左右,等OceanOne来初始化新币的相关数据.ide
if ocmd == "b3" p "Input the price of ERC20/USDT: " bprice = gets.chomp p "Input the amount of USDT: " amount = gets.chomp memo = Utils.GenerateOceanMemo(ERC20_BENZ,"B",bprice) p memo assetsInfo = walletAccount.read_asset(USDT_ASSET_ID) if assetsInfo["data"]["balance"].to_f >= 1 && assetsInfo["data"]["balance"].to_f >= amount.to_f transInfo = walletAccount.create_transfer(walletAccount.encrypt_pin(DEFAULT_PIN), { asset_id: USDT_ASSET_ID, opponent_id: OCEANONE_BOT, amount: amount, trace_id: SecureRandom.uuid, memo: memo }) p transInfo p "The Order id is " + transInfo["data"]["trace_id"] + " It's needed by cancel-order!" else p "Not enough USDT" end end
读取币的价格列表,来确认挂单是否成功!区块链
if ocmd == "3" Utils.OceanOneMarketPriceRequest(ERC20_BENZ, USDT_ASSET_ID) end def self.OceanOneMarketPriceRequest(asset_id, base_asset_id) full_url = "https://events.ocean.one/markets/" + asset_id + "-" + base_asset_id + "/book" data = HTTP.get(full_url).body body = "" redData = data.readpartial while redData != nil body = body + redData redData = data.readpartial end result = ActiveSupport::JSON.decode(body).with_indifferent_access result["data"]["data"]["asks"].each { |x| puts x["side"] + " " + x["price"] + " " + x["amount"] + " " + x["funds"] } result["data"]["data"]["bids"].each { |x| puts x["side"] + " " + x["price"] + " " + x["amount"] + " " + x["funds"] } end
Commands list of this source code:ui
Make your choose(eg: q for Exit!):
个人博客即将同步至腾讯云+社区,邀请你们一同入驻:https://cloud.tencent.com/developer/support-plan?invite_code=cw4h96k6poj4