在上一課中,咱們介紹瞭如何在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