In the last lesson, we explained how to trade bitcoin in OceanOne. OceanOne supports the exchange of tokens on any Mixin Network, including all ERC20 and EOS tokens, with no formalities and no fees. Here’s how to hang up an ERC20 token for OceanOne transaction! After mastering the ERC20 token, you can buy and sell any token on Ocean.

Here we use an ERC20 token called Benz. This token has been charged to the Mixin Network, and you can see the total number and transactions of this token within the Mixin Network in the blockchain browser

Preliminary knowledge:

Deposit Your Benz coin in your wallet, then use the getAssets API to read its UUID.

Get the UUID of the coin

Calling the getAssets API returns JSON data, such as:

  • UUID asset_id currency.
  • Public_key Current wallet address of the coin.
  • Symbol The name of a currency. Such as: Benz.
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
Copy the code

The complete output from a call to the read_assets API is as follows:

"--------The Wallet Assets List-----------------"Benz 10.03 0 x822664c2efb27e2eb4c4286f421b4bf6fb943fc6 ETH 0 0 x822664c2efb27e2eb4c4286f421b4bf6fb943fc6 EOS 0 1 1 eoswithmixin b0adfae2f8828d15e11cb1fbe23d6096 USDT kb4rbv5w4mnybpjcjjulknvxubfr5mjqa CNB 0.99999995 0x822664c2EFb27E2Eb4c4286f421B4BF6FB943fC6 BTC 0 1KB4RbV5W4MNybpjcJjULKNVXubfR5MJqA"----------End of Wallet Assets --------------"
-------------------------------------------------------------------------
Copy the code

Price are cancelled

  • An order that is below or equal to the market price.
  • Limit order An order higher than or equal to the market price.

OceanOne supports three base price categories: USDT, XIN, BTC, namely: Benz/USDT, Benz/XIN, Benz/BTC, Benz/USDT here.

Limit price hang sell order.

After the new currency is listed, we need to wait for about a minute for OceanOne to initialize the relevant data of the new currency.

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
Copy the code

Limit price hang buy.

After the new currency is listed, we need to wait for about a minute for OceanOne to initialize the relevant data of the new currency.

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
Copy the code

Read the price list of coins

Read the price list of coins to confirm whether the listing is successful!

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
   whileredData ! =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
Copy the code

ERC20 related operation instructions

Commands list of this source code:

  • 1: Fetch BTC/USDT Order Book
  • 2: Fetch XIN/USDT Order Book
  • 3: Fetch ERC20/USDT Order Book
  • s1: Sell BTC/USDT
  • b1: Buy BTC/USDT
  • s2: Sell XIN/USDT
  • b2: Buy XIN/USDT
  • s3: Sell ERC20/USDT
  • s3: Buy ERC20/USDT
  • c: Cancel the order
  • q: Exit Make your choose(eg: q for Exit!) :

Complete code