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

資訊專欄INFORMATION COLUMN

通過 Nodejs 買賣Bitcoin

fsmStudy / 3599人閱讀

摘要:上一章介紹了,你可以秒完成資產(chǎn)的市價(jià)買賣。如果你想限定價(jià)格買賣,或者買賣一些不支持的資產(chǎn),你需要。方案二掛單交易所是基于的去中心化交易所,它性能一流。完整的步驟如下檢查比特幣或的余額,錢包地址。比特幣的到帳時(shí)間是個(gè)區(qū)塊的高度,約分鐘。


上一章介紹了Exincore,你可以1秒完成資產(chǎn)的市價(jià)買賣。如果你想限定價(jià)格買賣,或者買賣一些exincore不支持的資產(chǎn),你需要OceanOne。

方案二: 掛單Ocean.One交易所

Ocean.one是基于Mixin Network的去中心化交易所,它性能一流。
你可以在OceanOne上交易任何資產(chǎn),只需要將你的幣轉(zhuǎn)給OceanOne, 將交易信息寫在交易的memo里,OceanOne會(huì)在市場(chǎng)里列出你的交易需求,
交易成功后,會(huì)將目標(biāo)幣轉(zhuǎn)入到你的MixinNetwork帳上,它有三大特點(diǎn)與優(yōu)勢(shì):

不需要在OceanOne注冊(cè)

不需要存幣到交易所

支持所有Mixin Network上能夠轉(zhuǎn)賬的資產(chǎn),所有的ERC20 EOS代幣。

預(yù)備知識(shí):

你先需要?jiǎng)?chuàng)建一個(gè)機(jī)器人, 方法在 教程一.

安裝依賴包

我們需要依賴 msgpack5 and mixin-node-client ,第四章 已經(jīng)做過介紹, 你應(yīng)該先安裝過它了.

充幣到 Mixin Network, 并讀出它的余額.

此處演示用 USDT購(gòu)買BTC 或者 用BTC購(gòu)買USDT。交易前,先檢查一下錢包地址。
完整的步驟如下:

檢查比特幣或USDT的余額,錢包地址。并記下錢包地址。

從第三方交易所或者你的冷錢包中,將幣充到上述錢包地址。

再檢查一下幣的余額,看到帳與否。(比特幣的到帳時(shí)間是5個(gè)區(qū)塊的高度,約100分鐘)。

比特幣與USDT的充值地址是一樣的。

if ( args.type === TYPE_WALLET_ASSETS_INFO ) {
  const assetsInfo = await newUserClient.getUserAssets();
  console.log("-AssetID--Asset--Balance--public_key--");
  assetsInfo.forEach(function(element) {
     console.log(element.asset_id + "  " +
                 element.symbol + "  " +
                 element.balance + "  " +
                 element.public_key + " " +
                 element.account_name + "  " +
                 element.account_tag
               );
   });
  // console.log(assetsInfo);
}
取得Ocean.one的市場(chǎng)價(jià)格信息

如何來查詢Ocean.one市場(chǎng)的價(jià)格信息呢?你要先了解你交易的基礎(chǔ)幣是什么,如果你想買比特幣,賣出USDT,那么基礎(chǔ)貨幣就是USDT;如果你想買USDT,賣出比特幣,那么基礎(chǔ)貨幣就是比特幣.

if ( args.type === TYPE_OO_FETCH_BTC_USDT ) {
  FetchOceanOneMarketInfos(BTC_ASSET_ID, USDT_ASSET_ID);
}
function FetchOceanOneMarketInfos(asset_id, base_asset) {
  var instance = axios.create({
  baseURL: "https://events.ocean.one/markets/" + asset_id + "-" + base_asset + "/book",
  timeout: 3000,
  headers: {"X-Custom-Header": "foobar"}
  });
  instance.get()
  .then(function(response) {
    console.log("--Price--Amount--Funds--Side")
    response.data.data.data.asks.forEach(function(element) {
       console.log(element.price + "     " +
                   element.amount + "     " +
                   element.funds + "     " +
                   element.side);
     });
     response.data.data.data.bids.forEach(function(element) {
        console.log(element.price + "     " +
                    element.amount + "     " +
                    element.funds + "     " +
                    element.side);
      });
    // console.log(response.data.data.data.asks);
  });
}
交易前,創(chuàng)建一個(gè)Memo!

在第二章里,基于Mixin Network的 Nodejs 比特幣開發(fā)教程: 機(jī)器人接受比特幣并立即退還用戶, 我們學(xué)習(xí)過轉(zhuǎn)帳,這兒我們介紹如何告訴Ocean.one,我們給它轉(zhuǎn)帳的目的是什么,信息全部放在memo里.

Side 方向,"B" 或者 "A", "B"是購(gòu)買, "A"是出售.

AssetUuid 目標(biāo)虛擬資產(chǎn)的UUID.

Price 價(jià)格,如果操作方向是"B", 價(jià)格就是AssetUUID的價(jià)格; 如果操作方向是"B", 價(jià)格就是轉(zhuǎn)給Ocean.one幣的價(jià)格.

function GenerateOceanMemo(targetAsset,side,price) {
  const bytes = Buffer.from(
    targetAsset.replace(/-/g, ""),
    "hex"
  );
  const memo = msgpack
    .encode({
      S: side,
      A: bytes,
      P: price,
      T: "L",
    })
    .toString("base64");
  console.log(memo);
  return memo;
}

買入XIN的代碼如下:

else if ( args.type === TYPE_OO_BUY_XIN_USDT ) {
  var prompts = [
    {
      name: "price",
      type: "input",
      message: "Input the price of XIN/USDT: ",
    },
  ];
  price = await inquirer.prompt(prompts);
  var prompts = [
    {
      name: "amount",
      type: "input",
      message: "Input the amount of USDT: ",
    },
  ];
  amount = await inquirer.prompt(prompts);
  console.log(price);
  console.log(amount);
  const memo = GenerateOceanMemo(XIN_ASSET_ID,"B",price.price);
  const assetInfo = await newUserClient.getUserAsset(USDT_ASSET_ID);
  console.log("The Wallet "s USDT balance is ", assetInfo.balance);
  if ( assetInfo.balance >= amount.amount && assetInfo.balance >= 1 ) {
    const Obj = {
      assetId: USDT_ASSET_ID,
      recipientId: OCEANONE_BOT,
        traceId: newUserClient.getUUID(),
        amount: amount.amount,
        memo: memo,
      }
      const transInfo = await newUserClient.transferFromBot(Obj);
      console.log(transInfo);
      console.log("The Order id is " + transInfo.trace_id + " It is needed to cancel the order!");
  } else {
    console.log("Not enough USDT!");
  }
}
出售XIN的例子

轉(zhuǎn)打算出售的XIN給Ocean.one(OCEANONE_BOT),將你打算換回來的目標(biāo)虛擬資產(chǎn)的UUID放入memo.

else if ( args.type === TYPE_OO_SELL_XIN_USDT ) {
  var prompts = [
    {
      name: "price",
      type: "input",
      message: "Input the price of XIN/USDT: ",
    },
  ];
  price = await inquirer.prompt(prompts);
  var prompts = [
    {
      name: "amount",
      type: "input",
      message: "Input the amount of XIN: ",
    },
  ];
  amount = await inquirer.prompt(prompts);
  console.log(price);
  console.log(amount);
  const memo = GenerateOceanMemo(XIN_ASSET_ID,"A",price.price);
  const assetInfo = await newUserClient.getUserAsset(BTC_ASSET_ID);
  console.log("The Wallet "s USDT balance is ", assetInfo.balance);
  if ( assetInfo.balance >= amount.amount ) {
    const Obj = {
      assetId: XIN_ASSET_ID,
      recipientId: OCEANONE_BOT,
        traceId: newUserClient.getUUID(),
        amount: amount.amount,
        memo: memo,
      }
      const transInfo = await newUserClient.transferFromBot(Obj);
      console.log(transInfo);
      console.log("The Order id is " + transInfo.trace_id + " It is needed to cancel the order!");
  } else {
    console.log("Not enough XIN!");
  }
}

一個(gè)成功的掛單如下:

? Input the price of XIN/USDT:  160
? Input the amount of USDT:  1
{ price: "160" }
{ amount: "1" }
hKFToUKhQcQQgVsLGidkNzaPqkLWlPpiCqFQozE2MKFUoUw=
The Wallet "s USDT balance is  1.995101
{
  type: "transfer",
  snapshot_id: "14f144e4-0bd5-43aa-a7d4-70e7d5c695b0",
  opponent_id: "aaff5bef-42fb-4c9f-90e0-29f69176b7d4",
  asset_id: "815b0b1a-2764-3736-8faa-42d694fa620a",
  amount: "-1",
  trace_id: "d34f881b-4460-42d3-af91-551f97b20f74",
  memo: "hKFToUKhQcQQgVsLGidkNzaPqkLWlPpiCqFQozE2MKFUoUw=",
  created_at: "2019-05-10T07:18:21.130357698Z",
  counter_user_id: "aaff5bef-42fb-4c9f-90e0-29f69176b7d4"
}
The Order id is d34f881b-4460-42d3-af91-551f97b20f74 It is needed to cancel the order!
取消掛單

Ocean.one將trace_id當(dāng)做訂單,比如上面的例子, d34f881b-4460-42d3-af91-551f97b20f74 就是訂單號(hào),我們用他來取消訂單。

else if ( args.type === TYPE_OO_CANCEL_ORDER ) {
  const prompts = [
    {
      name: "order_id",
      type: "input",
      message: "Input iso8601 datetime: ",
    },
  ];
  answers = await inquirer.prompt(prompts);
  const memo = GenerateOceanCancelMemo(answers.order_id);
  const assetInfo = await newUserClient.getUserAsset(CNB_ASSET_ID);
  console.log("The Wallet "s USDT balance is ", assetInfo.balance);
  if ( assetInfo.balance >= 0.00000001 ) {
    const Obj = {
      assetId: CNB_ASSET_ID,
      recipientId: OCEANONE_BOT,
        traceId: newUserClient.getUUID(),
        amount: "0.00000001",
        memo: memo,
      }
      const transInfo = await newUserClient.transferFromBot(Obj);
      console.log(transInfo);
  } else {
    console.log("Not enough CNB!");
  }
}
通過讀取資產(chǎn)余額,來確認(rèn)到帳情況
const assetsInfo = await newUserClient.getUserAssets();
console.log("-AssetID--Asset--Balance--public_key--");
assetsInfo.forEach(function(element) {
   console.log(element.asset_id + "  " +
               element.symbol + "  " +
               element.balance + "  " +
               element.public_key + " " +
               element.account_name + "  " +
               element.account_tag
             );
 });
源代碼執(zhí)行

編譯執(zhí)行,即可開始交易了.

源代碼執(zhí)行

編譯執(zhí)行,即可開始交易了.

[x] node bitcoin-wallet-nodejs.js 運(yùn)行.

本代碼執(zhí)行時(shí)的命令列表:

Make your choose(select the uuid for open the specified wallet): 0b10471b-1aed-3944-9eda-5ab947562761
You select the : 0b10471b-1aed-3944-9eda-5ab947562761
You select the wallet 0b10471b-1aed-3944-9eda-5ab947562761
?
Make your choose (Use arrow keys)

? aw: Read Wallet All Asssets Information

ab: Read Bot All Asssets Information

--------------OCean.One-------------------------

19: Fetch BTC/USDT order book

20: Fetch XIN/USDT order book

21: Fetch ERC20/USDT order book

22: Sell BTC/USDT

23: Sell XIN/USDT

24: Sell ERC20/USDT

25: Buy BTC/USDT

26: Buy XIN/USDT

27: Buy ERC20/USDT

28: Cancel the order

Exit

完整代碼

文章版權(quán)歸作者所有,未經(jīng)允許請(qǐng)勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。

轉(zhuǎn)載請(qǐng)注明本文地址:http://specialneedsforspecialkids.com/yun/24683.html

相關(guān)文章

  • Node.js買賣比特幣 教程

    摘要:完整的步驟如下檢查比特幣或的余額,錢包地址。比特幣的到帳時(shí)間是個(gè)區(qū)塊的高度,約分鐘。 通過 Nodejs 買賣Bitcoin showImg(https://segmentfault.com/img/remote/1460000018771566?w=1200&h=659); Github Repo 方案一: 通過ExinCore API進(jìn)行幣幣交易 Exincore 提供了基于Mix...

    Airy 評(píng)論0 收藏0
  • 通過 C# 買賣Bitcoin

    摘要:方案二在去中心化交易所上掛單買賣是基于的去中心化交易所,它性能一流。完整的步驟如下檢查比特幣或的余額,錢包地址。比特幣的到帳時(shí)間是個(gè)區(qū)塊的高度,約分鐘。 showImg(https://github.com/wenewzhang/mixin_labs-csharp-bot/raw/master/BItcoin_C%23.jpg); 上一章介紹了Exincore,你可以1秒完成資產(chǎn)的市價(jià)...

    you_De 評(píng)論0 收藏0
  • 如何用 PHP 買賣Bitcoin

    摘要:比特幣的到帳時(shí)間是個(gè)區(qū)塊的高度,約分鐘。請(qǐng)注意,比特幣與的地址是一樣的。 showImg(https://segmentfault.com/img/remote/1460000018419614?w=1200&h=659); 方案一: 通過ExinCore API進(jìn)行幣幣交易 Exincore 提供了基于Mixin Network的幣幣交易API. 你可以支付USDT給ExinCore...

    Chaz 評(píng)論0 收藏0
  • 通過 Ruby 買賣Bitcoin:使用開放交易所OceanOne

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

    taoszu 評(píng)論0 收藏0
  • 如何用 Ruby 買賣Bitcoin

    摘要:比特幣的到帳時(shí)間是個(gè)區(qū)塊的高度,約分鐘。請(qǐng)注意,比特幣與的地址是一樣的。 showImg(https://segmentfault.com/img/remote/1460000019234638?w=1200&h=659); 方案一: 通過ExinCore API進(jìn)行幣幣交易 Exincore 提供了基于Mixin Network的幣幣交易API. 你可以支付USDT給ExinCore...

    qieangel2013 評(píng)論0 收藏0

發(fā)表評(píng)論

0條評(píng)論

最新活動(dòng)
閱讀需要支付1元查看
<