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 is how to hang an ERC20 token for an OceanOne transaction. Once you’ve mastered ERC20 token buying and selling, you can buy and sell tokens on any EOS and any other Mixin Network in the same way

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:

First deposit the Ben coin in your wallet and 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" ) {
    // Console.WriteLine(mixinApi.VerifyPIN(USRCONFIG.PinCode.ToString()).ToString());
    MixinApi mixinApiNewUser = GetWalletSDK();
    var assets = mixinApiNewUser.ReadAssets();
    string wuuid = GetWalletUUID();
    Console.WriteLine("Current wallet uuid is " + wuuid);
    foreach (Asset asset in assets)
    {
      if (asset.symbol == "EOS") {
       Console.WriteLine(asset.symbol + " Public Address is: " +
                         asset.account_name + "" +
                         asset.account_tag +
                         " Balance is: " + asset.balance);
     } else Console.WriteLine(asset.symbol + " Public Address is: " +
                              asset.public_key + " Balance is: "+ asset.balance); Console.WriteLine(); }}Copy the code

The complete output of a call to the getAssets API is as follows:

Make your choose:
aw
Current wallet uuid is 85d5609d-d93b-3c96-96f6-58357c5d99eb Benz Public Address is: 0x5fD0F147830a186545e6020F58fEc0c4B39065D4 Balance is: 1 EOS Public Address is: eoswithmixin 30399f17622cb2bfc57efd3393144bf9 Balance is: 0 USDT Public Address is: 1JvQ98N5Y8TvDbXr8eA8DHsNZqEuGbzzng Balance is: 1 BTC Public Address is: 1JvQ98N5Y8TvDbXr8eA8DHsNZqEuGbzzng Balance is: 0 XIN Public Address is: 0 x5fd0f147830a186545e6020f58fec0c4b39065d4 Balance is: 0.01Copy 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.

public static string  ERC20_BENZ     = "2b9c216c-ef60-398d-a42a-eba1b298581d";
if ( cmdo == "s2") {
  Console.WriteLine("Please input the price of ERC20/USDT: ");
  var pinput = Console.ReadLine();
  Console.WriteLine("Please input the amount of ERC20: ");
  var ainput = Console.ReadLine();

  string memo = GenerateOrderMemo("A",USRCONFIG.ASSET_ID_USDT,pinput);
  Console.WriteLine(memo);
  // Console.WriteLine(Convert.ToBase64String(stream3.ToArray()));
  MixinApi mixinApiNewUser = GetWalletSDK();
  var assets = mixinApiNewUser.ReadAsset(USRCONFIG.ERC20_BENZ);
  float balance = float.Parse(assets.balance);
  float amount  = float.Parse(ainput);
  if ( ( balance >= 0 ) && ( balance >= amount ) ) {
    Transfer reqInfo = mixinApiNewUser.Transfer(USRCONFIG.ERC20_BENZ,
                            USRCONFIG.OCEANONE_BOT,
                            ainput,
                            GetWalletPinCode(),
                            System.Guid.NewGuid().ToString(),
                            memo);
    Console.WriteLine(reqInfo);
    Console.WriteLine("Order id is " + reqInfo.trace_id);
  } else Console.WriteLine("Not enough ERC20_BENZ!");
}
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 ( cmdo == "b2") {
  Console.WriteLine("Please input the price of ERC20_BENZ/USDT: ");
  var pinput = Console.ReadLine();
  Console.WriteLine("Please input the amount of USDT: ");
  var ainput = Console.ReadLine();

  string memo = GenerateOrderMemo("B",USRCONFIG.ERC20_BENZ,pinput);
  Console.WriteLine(memo);
  MixinApi mixinApiNewUser = GetWalletSDK();
  var assets = mixinApiNewUser.ReadAsset(USRCONFIG.ASSET_ID_USDT);
  Console.WriteLine(assets.balance);
  float balance = float.Parse(assets.balance);
  float amount  = float.Parse(ainput);
  if ( ( balance >= 1.0 ) && ( balance >= amount ) ) {
    Transfer reqInfo = mixinApiNewUser.Transfer(USRCONFIG.ASSET_ID_USDT,
                            USRCONFIG.OCEANONE_BOT,
                            ainput,
                            GetWalletPinCode(),
                            System.Guid.NewGuid().ToString(),
                            memo);
    Console.WriteLine(reqInfo);
    Console.WriteLine("Order id is " + reqInfo.trace_id);
  } else Console.WriteLine("Not enough USDT!");
}
Copy the code

Read the price list of coins

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

if (cmdo == "2") {
  string jsonData = FetchOceanMarketPrice(USRCONFIG.ERC20_BENZ,USRCONFIG.ASSET_ID_USDT);
  // string jsonData = FetchMarketPrice("c6d0c728-2624-429b-8e0d-d9d19b6592fa");
  var marketObj = JsonConvert.DeserializeObject<MarketInfoOcean>(jsonData);
  Console.WriteLine("--Price--Amount---Funds---Side----");
  foreach (order value in marketObj.data.data.asks)
  {
      Console.WriteLine(value.price + "" + value.amount + "" + value.funds + "" + value.side);
  }
  foreach (order value in marketObj.data.data.bids)
  {
      Console.WriteLine(value.price + "" + value.amount + "" + value.funds + "" + value.side); }}public static string FetchOceanMarketPrice(string asset_id, string base_asset)
{
    return FetchOceanMarketPriceAsync(asset_id,base_asset).Result;
}
public static async Task<string> FetchOceanMarketPriceAsync(string asset_id, string base_asset)
{
  HttpClient client = new HttpClient();
  string baseUrl = "https://events.ocean.one/markets/" + asset_id + "-" + base_asset + "/book";
  try
  {
     HttpResponseMessage response = await client.GetAsync(baseUrl);
     response.EnsureSuccessStatusCode();
     string responseBody = await response.Content.ReadAsStringAsync();
     // Above three lines can be replaced with new helper method below
     // string responseBody = await client.GetStringAsync(uri);
     Console.WriteLine(responseBody);
     return responseBody;
  }
  catch(HttpRequestException e)
  {
     Console.WriteLine("\nException Caught!");
     Console.WriteLine("Message :{0} ",e.Message);
  }
  return null;
}
Copy the code

ERC20 related operation instructions

Commands list of this source code:

  • teb:Transfer ERC20 from Bot to Wallet
  • tem:Transfer ERC20 from Wallet to Master
  • o: Ocean.One Exchange

Make your choose:

  • 1: Fetch XIN/USDT orders
  • s1: Sell XIN/USDT
  • b1: Buy XIN/USDT
  • 2: Fetch ERC20(Benz)/USDT orders
  • s2: Sell Benz/USDT
  • b2: Buy Benz/USDT
  • c: Cancel Order
  • q: Exit

Complete code