国产xxxx99真实实拍_久久不雅视频_高清韩国a级特黄毛片_嗯老师别我我受不了了小说

資訊專欄INFORMATION COLUMN

用Java在去中心化交易所OceanOne上掛單買賣任意ERC20 token

honmaple / 606人閱讀

摘要:在上一課中,我們介紹了如何在交易比特幣。支持交易任何上的,包括所有的和,不需要任何手續和費用,直接掛單即可。下面介紹如何將將一個掛上交易此處我們用一個叫做的為例。

在上一課中,我們介紹了如何在OceanOne交易比特幣。OceanOne支持交易任何Mixin Network上的token,包括所有的ERC20和EOS token,不需要任何手續和費用,直接掛單即可。下面介紹如何將將一個ERC20 token掛上OceanOne交易!

此處我們用一個叫做Benz的ERC20 token為例。這個token已經被充值進Mixin Network,你可以在區塊鏈瀏覽器看到這個token在Mixin Network內部的總數和交易

預備知識:

先將Ben幣存入你的錢包,然后使用getAssets API讀取它的UUID.

取得該幣的UUID

調用 getAssets API 會返回json數據, 如:

asset_id 幣的UUID.

public_key 該幣的當前錢包的地址.

symbol 幣的名稱. 如: Benz.

if ( input.equals("aw") ) {
  MixinAPI mixinApiUser = generateAPI_FromCSV();
  JsonArray assets = mixinApiUser.getAssets();
  System.out.println("------------------------All Assets Information---------------------------");
  System.out.println(assets);
  assets.forEach((element) ->  {
     JsonObject jsonObj = element.getAsJsonObject();
     System.out.println(jsonObj.get("asset_id").getAsString() + " " +
                        jsonObj.get("symbol").getAsString() + " " +
                        jsonObj.get("public_key").getAsString() + " " +
                        jsonObj.get("balance").getAsString() );
  });
  System.out.println("-----------------------------------------------------------------------");
}

調用 getAssets API的完整輸出如下:

Make your choose(eg: q for Exit!): aw
aw
------------------------All Assets Information---------------------------
[{"type":"asset","asset_id":"2b9c216c-ef60-398d-a42a-eba1b298581d","chain_id":"43d61dcd-e413-450d-80b8-101d5e903357","symbol":"Benz","name":"Benz coin","icon_url":"https://images.mixin.one/yH_I5b0GiV2zDmvrXRyr3bK5xusjfy5q7FX3lw3mM2Ryx4Dfuj6Xcw8SHNRnDKm7ZVE3_LvpKlLdcLrlFQUBhds=s128",
"balance":"1000","public_key":"0x62F20013472a72b8Fe3f9a99f36e5802E6e93c15","account_name":"",
"account_tag":"","price_btc":"0","price_usd":"0","change_btc":"0","change_usd":"0",
"asset_key":"0xc409b5696c5f9612e194a582e14c8cd41ecdbc67","confirmations":100,
"capitalization":0},{"type":"asset","asset_id":"6cfe566e-4aad-470b-8c9a-2fd35b49c68d",
"chain_id":"6cfe566e-4aad-470b-8c9a-2fd35b49c68d","symbol":"EOS","name":"EOS",
"icon_url":"https://images.mixin.one/a5dtG-IAg2IO0Zm4HxqJoQjfz-5nf1HWZ0teCyOnReMd3pmB8oEdSAXWvFHt2AJkJj5YgfyceTACjGmXnI-VyRo=s128","balance":"0","public_key":"","account_name":"eoswithmixin","account_tag":"889ed66a1059bc3dab60e2ee44d0f993",
"price_btc":"0.0008953","price_usd":"4.73591781","change_btc":"-0.004161988128557199","change_usd":"0.00012182287348895748",
"asset_key":"eosio.token:EOS","confirmations":64,"capitalization":0},
{"type":"asset","asset_id":"965e5c6e-434c-3fa9-b780-c50f43cd955c","chain_id":"43d61dcd-e413-450d-80b8-101d5e903357","symbol":"CNB","name":"Chui Niu Bi",
"icon_url":"https://images.mixin.one/0sQY63dDMkWTURkJVjowWY6Le4ICjAFuu3ANVyZA4uI3UdkbuOT5fjJUT82ArNYmZvVcxDXyNjxoOv0TAYbQTNKS=s128",
"balance":"0.99984","public_key":"0x62F20013472a72b8Fe3f9a99f36e5802E6e93c15","account_name":"",
"account_tag":"","price_btc":"0","price_usd":"0","change_btc":"0","change_usd":"0",
"asset_key":"0xec2a0550a2e4da2a027b3fc06f70ba15a94a6dac","confirmations":100,
"capitalization":0},{"type":"asset","asset_id":"c6d0c728-2624-429b-8e0d-d9d19b6592fa",
"chain_id":"c6d0c728-2624-429b-8e0d-d9d19b6592fa","symbol":"BTC","name":"Bitcoin",
"icon_url":"https://images.mixin.one/HvYGJsV5TGeZ-X9Ek3FEQohQZ3fE9LBEBGcOcn4c4BNHovP4fW4YB97Dg5LcXoQ1hUjMEgjbl1DPlKg1TW7kK6XP=s128","balance":"0",
"public_key":"15RNBb5GzoXWRoEMT5MJL3pqzSjdPoXf6J","account_name":"","account_tag":"",
"price_btc":"1","price_usd":"5289.7409549","change_btc":"0","change_usd":"0.004160319338628907",
"asset_key":"c6d0c728-2624-429b-8e0d-d9d19b6592fa","confirmations":6,"capitalization":0}]
2b9c216c-ef60-398d-a42a-eba1b298581d Benz 0x62F20013472a72b8Fe3f9a99f36e5802E6e93c15 1000
6cfe566e-4aad-470b-8c9a-2fd35b49c68d EOS  0
965e5c6e-434c-3fa9-b780-c50f43cd955c CNB 0x62F20013472a72b8Fe3f9a99f36e5802E6e93c15 0.99984
c6d0c728-2624-429b-8e0d-d9d19b6592fa BTC 15RNBb5GzoXWRoEMT5MJL3pqzSjdPoXf6J 0
限價掛單

掛限價買單 低于或者等于市場價的單.

掛限價賣單 高于或者是等于市場價的單.

OceanOne支持三種基類價格: USDT, XIN, BTC, 即: Benz/USDT, Benz/XIN, Benz/BTC, 這兒示范Benz/USDT.

限價掛賣單.

新幣掛單后,需要等一分鐘左右,等OceanOne來初始化新幣的相關數據.

if ( subinput.equals("x2") ) {
  MakeTheSellOrder(ERC20_BENZ,USDT_ASSET_ID);
}
public static void MakeTheSellOrder(String AssetID, String BaseAssetID) {
  System.out.print(String.format("Please input the %s price of %s: ",AssetID,BaseAssetID));
  String pinput = System.console().readLine();
  System.out.println(pinput);

  System.out.print(String.format("Please input the %s amount: ",AssetID));
  String aminput = System.console().readLine();
  System.out.println(aminput);
  float amountf = Float.valueOf(aminput.trim()).floatValue();

  String OrderMemo = GenerateOrderMemo("A",BaseAssetID,pinput);
  MixinAPI mixinApiUser = generateAPI_FromCSV();
  // UUID usdtUUID         =  UUID.fromString(USDT_ASSET_ID);
  // String memoTarget     = encodeUUID(usdtUUID);
  System.out.println("------------------Ocean.one-EXCHANGE----------------------------");
  System.out.println(OrderMemo);
  JsonObject asset = mixinApiUser.getAsset(AssetID);
  System.out.println(asset);
  System.out.println(asset.get("balance").getAsFloat());
  if ( asset.get("balance").getAsFloat()  > 0 && asset.get("balance").getAsFloat() >= amountf ) {
      JsonObject transInfo = mixinApiUser.transfer(AssetID, OCEANONE_BOT,
                                                   aminput,
                                                   OrderMemo);
      System.out.println(String.format("--------------%s Transfer To EXCHANGE Information---------",AssetID));
      System.out.println(transInfo);
      System.out.println(String.format("---Order is %s: ------",transInfo.get("trace_id").getAsString()));
   } else System.out.println(String.format("----------------Not enough %s--------------------------",AssetID));
}
限價掛買單.

新幣掛單后,需要等一分鐘左右,等OceanOne來初始化新幣的相關數據.

if ( subinput.equals("x1") ) {
  MakeTheBuyOrder(ERC20_BENZ,USDT_ASSET_ID);
}
public static void MakeTheBuyOrder(String AssetID, String BaseAssetID) {
  System.out.print(String.format("Please input the %s price of %s: ",AssetID,BaseAssetID));
  String pinput = System.console().readLine();
  System.out.println(pinput);

  System.out.print(String.format("Please input the %s amount: ",BaseAssetID));
  String aminput = System.console().readLine();
  System.out.println(aminput);
  float amountf = Float.valueOf(aminput.trim()).floatValue();

  String OrderMemo = GenerateOrderMemo("B",AssetID,pinput);
  MixinAPI mixinApiUser = generateAPI_FromCSV();
  // UUID usdtUUID         =  UUID.fromString(USDT_ASSET_ID);
  // String memoTarget     = encodeUUID(usdtUUID);
  System.out.println("------------------Ocean.one--EXCHANGE----------------------------");
  System.out.println(OrderMemo);
  JsonObject asset = mixinApiUser.getAsset(BaseAssetID);
  System.out.println(asset);
  System.out.println(asset.get("balance").getAsFloat());
  if ( asset.get("balance").getAsFloat()  > 0 && asset.get("balance").getAsFloat() >= amountf ) {
      JsonObject transInfo = mixinApiUser.transfer(BaseAssetID, OCEANONE_BOT,
                                                   aminput,
                                                   OrderMemo);
       System.out.println(String.format("--------------%s Transfer To EXCHANGE Information---------",BaseAssetID));
       System.out.println(transInfo);
       System.out.println(String.format("---Order is %s: ------",transInfo.get("trace_id").getAsString()));
    } else System.out.println(String.format("----------------Not enough %s--------------------------",BaseAssetID));
}
讀取幣的價格列表

讀取幣的價格列表,來確認掛單是否成功!

if ( subinput.equals("x") ) {
  FetchOceanMarketInfos(ERC20_BENZ,XIN_ASSET_ID);
}
private static void FetchOceanMarketInfos(String targetAssetID, String baseAssetID) {
  OkHttpClient client = new OkHttpClient();
  String baseUrl = "https://events.ocean.one/markets/%s-%s/book ";
  String fullUrl = String.format(baseUrl,targetAssetID,baseAssetID);
  // String fullUrl = baseUrl + url;
  System.out.println(fullUrl);
  Request request = new Request.Builder()
                             .url(fullUrl)
                             .build();
  try {
     Response response = client.newCall(request).execute();
     if (!response.isSuccessful()) {
       throw new IOException("Unexpected code " + response);
     }
     String res = response.body().string();
     // System.out.println(res);
     JsonParser parser = new JsonParser();
     JsonElement jsonTree = parser.parse(res);
     JsonObject orders;
     orders =  jsonTree.getAsJsonObject();
     JsonArray asksOrders = orders.get("data").getAsJsonObject().
                                   get("data").getAsJsonObject().
                                   get("asks").getAsJsonArray();
     JsonArray bidsOrders = orders.get("data").getAsJsonObject().
                                   get("data").getAsJsonObject().
                                   get("bids").getAsJsonArray();
     // System.out.println(orders.get("data").getAsJsonObject().get("data").getAsJsonObject().get("bids").getAsJsonArray());
     System.out.println("--Side--Price--Amount--Funds---");
     asksOrders.forEach((element) ->  {
        JsonObject jsonObj = element.getAsJsonObject();
        System.out.println(jsonObj.get("side").getAsString() + " " +
                           jsonObj.get("price").getAsString() + " " +
                           jsonObj.get("amount").getAsString() + " " +
                           jsonObj.get("funds").getAsString() );
     });
     bidsOrders.forEach((element) ->  {
        JsonObject jsonObj = element.getAsJsonObject();
        System.out.println(jsonObj.get("side").getAsString() + " " +
                           jsonObj.get("price").getAsString() + " " +
                           jsonObj.get("amount").getAsString() + " " +
                           jsonObj.get("funds").getAsString() );
     });
     System.out.println("----endo--of--btc/usdt----");
     return;
   } catch(Exception e) { e.printStackTrace(); }
   return;
}
ERC20相關的操作指令

Commands list of this source code:

trb:Transfer ERC20 from Bot to Wallet

trm:Transfer ERC20 from Wallet to Master

o: Ocean.One Exchange

Make your choose(eg: q for Exit!):

x: Orders-Book of ERC20/USDT

x1: Buy ERC20 pay USDT

x2: Sell ERC20 get USDT

c: Cancel the order

q: Exit

完整的代碼

文章版權歸作者所有,未經允許請勿轉載,若此文章存在違規行為,您可以聯系管理員刪除。

轉載請注明本文地址:http://specialneedsforspecialkids.com/yun/24669.html

相關文章

  • Ruby在去中心交易OceanOne掛單買賣任意ERC20 token

    摘要:在上一課中,我們介紹了如何在交易比特幣。支持交易任何上的,包括所有的和,不需要任何手續和費用,直接掛單即可。下面介紹如何將將一個掛上交易在掌握了之后,就可以把任何在上買賣。此處我們用一個叫做的為例。 showImg(https://segmentfault.com/img/remote/1460000019329775?w=1201&h=660); 在上一課中,我們介紹了如何在Ocea...

    用戶83 評論0 收藏0
  • PHP在去中心交易OceanOne掛單買賣任意ERC20 token

    摘要:在上一課中,我們介紹了如何在交易比特幣。支持交易任何上的,包括所有的和,不需要任何手續和費用,直接掛單即可。下面介紹如何將將一個掛上交易此處我們用一個叫做的為例。 showImg(https://segmentfault.com/img/remote/1460000018419614?w=1200&h=659); 在上一課中,我們介紹了如何在OceanOne交易比特幣。OceanOne...

    DevWiki 評論0 收藏0
  • PHP在去中心交易OceanOne掛單買賣任意ERC20 token

    摘要:在上一課中,我們介紹了如何在交易比特幣。支持交易任何上的,包括所有的和,不需要任何手續和費用,直接掛單即可。下面介紹如何將將一個掛上交易此處我們用一個叫做的為例。 showImg(https://segmentfault.com/img/remote/1460000018419614?w=1200&h=659); 在上一課中,我們介紹了如何在OceanOne交易比特幣。OceanOne...

    luckyw 評論0 收藏0
  • 通過 Go 在去中心交易OceanOne掛單買賣任意ERC20 token

    摘要:在上一課中,我們介紹了如何在交易比特幣。支持交易任何上的,包括所有的和,不需要任何手續和費用,直接掛單即可。下面介紹如何將將一個掛上交易在掌握了之后,就可以把任何在上買賣。 showImg(https://segmentfault.com/img/remote/1460000018378805?w=1200&h=659); 在上一課中,我們介紹了如何在OceanOne交易比特幣。Oce...

    ivydom 評論0 收藏0
  • PHP比特幣開發教程:在去中心交易OceanOne掛單買賣比特幣

    摘要:方案二掛單交易所是基于的去中心化交易所,它性能一流。完整的步驟如下檢查比特幣或的余額,錢包地址。比特幣的到帳時間是個區塊的高度,約分鐘。 showImg(https://segmentfault.com/img/remote/1460000018419614?w=1200&h=659);上一章介紹了Exincore,你可以1秒完成資產的市價買賣。如果你想限定價格買賣,或者買賣一些exi...

    only_do 評論0 收藏0

發表評論

0條評論

最新活動
閱讀需要支付1元查看
<