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

資訊專欄INFORMATION COLUMN

如何用 PHP 買賣Bitcoin

Chaz / 2532人閱讀

摘要:比特幣的到帳時間是個區塊的高度,約分鐘。請注意,比特幣與的地址是一樣的。

方案一: 通過ExinCore API進行幣幣交易

Exincore 提供了基于Mixin Network的幣幣交易API.

你可以支付USDT給ExinCore, ExinCore會以最低的價格,最優惠的交易費將你購買的比特幣轉給你, 每一幣交易都是匿名的,并且可以在區塊鏈上進行驗證,交易的細節只有你與ExinCore知道!

ExinCore 也不知道你是誰,它只知道你的UUID.

預備知識:

你先需要創建一個機器人, 方法在 教程一.

安裝依賴包

正如教程一里我們介紹過的, 我們需要依賴 mixin-sdk-php, 你應該先安裝過它了, 這兒我們再安裝 uuid, msgpack 兩個軟件包.

  composer require ramsey/uuid
  composer require rybakit/msgpack
充幣到 Mixin Network, 并讀出它的余額.

ExinCore可以進行BTC, USDT, EOS, ETH 等等交易, 這兒演示如果用 USDT購買BTC 或者 用BTC購買USDT, 交易前,先檢查一下錢包地址!
完整的步驟如下:

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

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

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

請注意,比特幣與USDT的地址是一樣的。

if ($line == "2") {
  if (($handle = fopen("new_users.csv", "r")) !== FALSE) {
  while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
    $mixinSdk_eachAccountInstance = new MixinSDK(GenerateConfigByCSV($data));
    $asset_info = $mixinSdk_eachAccountInstance->Wallet()->readAsset(BTC_ASSET_ID);
    print_r("Bitcoin wallet address is :".$asset_info["public_key"]."
");
    print_r("Bitcoin wallet balance is :".$asset_info["balance"]."
");
  }
    fclose($handle);
  } else print("Create user first
");
}
if ($line == "3") {
  if (($handle = fopen("new_users.csv", "r")) !== FALSE) {
  while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
    $mixinSdk_eachAccountInstance = new MixinSDK(GenerateConfigByCSV($data));
    $asset_info = $mixinSdk_eachAccountInstance->Wallet()->readAsset(USDT_ASSET_ID);
    print_r("USDT wallet address is :".$asset_info["public_key"]."
");
    print_r("USDT wallet balance is :".$asset_info["balance"]."
");
  }
    fclose($handle);
  } else print("Create user first
");
}
查詢ExinCore市場的價格信息

如果來查詢ExinCore市場的價格信息呢?你要先了解你交易的基礎幣是什么,如果你想買比特幣,賣出USDT,那么基礎貨幣就是USDT;如果你想買USDT,賣出比特幣,那么基礎貨幣就是比特幣.

function getExchangeCoins($base_coin) :string {
  $client = new GuzzleHttpClient();
  $res = $client->request("GET", "https://exinone.com/exincore/markets?base_asset=".$base_coin, [
      ]);
  $result = "";
  if ($res->getStatusCode() == "200") {
    // echo $res->getStatusCode() . PHP_EOL;
    $resInfo = json_decode($res->getBody(), true);
    echo "Asset ID | Asset Symbol | Price | Amount | Exchanges" . PHP_EOL;
    $result = "Asset ID | Asset Symbol | Price | Amount | Exchanges" . PHP_EOL;
    foreach ($resInfo["data"] as $key => $coinInfo) {
      echo ($coinInfo["exchange_asset"] ." ".$coinInfo["exchange_asset_symbol"]. "/". $coinInfo["base_asset_symbol"] .
            " ". $coinInfo["price"] ." ". $coinInfo["minimum_amount"] ."-". $coinInfo["maximum_amount"] . " ");
      $result .= $coinInfo["exchange_asset_symbol"]. "/". $coinInfo["base_asset_symbol"] .
                  " ". $coinInfo["price"] ." ". $coinInfo["minimum_amount"] ."-". $coinInfo["maximum_amount"] . " ";
      foreach ($coinInfo["exchanges"] as $key => $exchange) {
        echo $exchange . " ";
        $result .= $exchange . " ";
      }
      echo PHP_EOL;
      $result .= PHP_EOL;
    }
  }
  return $result;
}
交易前,創建一個Memo!

在第二章里,基于Mixin Network的PHP比特幣開發教程: 機器人接受比特幣并立即退還用戶, 我們學習過退還用戶比特幣,在這里,我們除了給ExinCore支付幣外,還要告訴他我們想購買的幣是什么,即將想購買的幣存到memo里。

$memo = base64_encode(MessagePack::pack([
                     "A" => Uuid::fromString($_targetAssetID)->getBytes(),
                     ]));
幣幣交易的完整流程

轉幣給ExinCore時,將memo寫入你希望購買的幣,否則,ExinCore會直接退幣給你!

const EXIN_BOT        = "61103d28-3ac2-44a2-ae34-bd956070dab1";
const BTC_ASSET_ID    = "c6d0c728-2624-429b-8e0d-d9d19b6592fa";
const EOS_ASSET_ID    = "6cfe566e-4aad-470b-8c9a-2fd35b49c68d";
const USDT_ASSET_ID   = "815b0b1a-2764-3736-8faa-42d694fa620a";
coinExchange(BTC_ASSET_ID,"0.0001",USDT_ASSET_ID);

//...........

function coinExchange($_assetID,$_amount,$_targetAssetID) {
  $mixinSdk = new MixinSDK(require "./config.php");
  // print_r();
  $memo = base64_encode(MessagePack::pack([
                       "A" => Uuid::fromString($_targetAssetID)->getBytes(),
                       ]));
  $BotInfo = $mixinSdk->Wallet()->transfer($_assetID,EXIN_BOT,
                                           $mixinSdk->getConfig()["default"]["pin"],$_amount,$memo);
  print_r($BotInfo);
}

如果你想賣出比特幣買入USDT,調用方式如下:

coinExchange($config,BTC_ASSET_ID,"0.0001",USDT_ASSET_ID);

如果你想賣出USDT買入比特幣,調用方式如下:

coinExchange($config,USDT_ASSET_ID,"1",BTC_ASSET_ID);

交易完成后,Exincore會將你需要的幣轉到你的帳上,同樣,會在memo里,記錄成交價格,交易費用等信息!你只需要按下面的方式解開即可!

readUserSnapshots 讀取錢包的交易記錄。

$limit        = 20;
$offset       = "2019-03-10T01:58:25.362528Z";
$snapInfo = $mixinSdk_BotInstance->Wallet()->readUserSnapshots($limit, $offset);
// print_r($networkInfo2);
foreach ($snapInfo as  $record) {
  // echo $key . PHP_EOL;
  // print_r($record);
  if ($record["amount"] > 0 and $record["memo"] != "") {
    echo "------------MEMO:-coin--exchange--------------" . PHP_EOL;
    echo "memo: " . $record["memo"] . PHP_EOL;
    // print_r($dtPay->memo);
    echo "You Get Coins: ". $record["asset_id"]. " " . $record["amount"] . PHP_EOL;
    $memoUnpack = MessagePack::unpack(base64_decode($record["memo"]));
    $feeAssetID = Uuid::fromBytes($memoUnpack["FA"])->toString();
    $OrderID    = Uuid::fromBytes($memoUnpack["O"])->toString();
    if ($memoUnpack["C"] == 1000) {
      echo "Successful Exchange:". PHP_EOL;
      echo "Fee asset ID: " . $feeAssetID . " fee is :" . $memoUnpack["F"] . PHP_EOL;
      echo "Order ID: " . $OrderID . " Price is :" . $memoUnpack["P"] . PHP_EOL;
    } else print_r($memoUnpack);
    echo "--------------memo-record end---------------" . PHP_EOL;
  }
}

一次成功的交易如下:

------------MEMO:-coin--exchange--------------
memo: hqFDzQPooVCnMzg3Mi45N6FGqTAuMDAwNzc0NqJGQcQQgVsLGidkNzaPqkLWlPpiCqFUoUahT8QQIbfeL6p5RVOcEP0mLb+t+g==
You Get Coins: 815b0b1a-2764-3736-8faa-42d694fa620a 0.3857508
Successful Exchange:
Fee asset ID: 815b0b1a-2764-3736-8faa-42d694fa620a fee is :0.0007746
Order ID: 21b7de2f-aa79-4553-9c10-fd262dbfadfa Price is :3872.97
--------------memo-record end---------------
讀取幣的余額

通過讀取幣的余額,來確認交易情況!

$mixinSdk = new MixinSDK(require "./config.php");
$asset_info = $mixinSdk->Wallet()->readAsset(USDT_ASSET_ID);
print_r("USDT wallet balance is :".$asset_info["balance"]."
");
源代碼執行

執行 php call_apis.php 即可開始交易了.

1: Create user and update PIN

2: Read Bitcoin balance & address

3: Read USDT balance & address

4: Read EOS balance

5: Read EOS address

6: Transfer Bitcoin from bot to new user

7: Transfer Bitcoin from new user to Master

8: Withdraw bot"s Bitcoin

9: Withdraw bot"s EOS

qu: Read market price(USDT)

qb: Read market price(BTC)

b: Balance of bot (USDT & BTC)

s: Read Snapshots

tb: Transfer 0.0001 BTC buy USDT

tu: Transfer $1 USDT buy BTC

q: Exit

完整代碼

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

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

相關文章

  • 何用 Ruby 買賣Bitcoin

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

    qieangel2013 評論0 收藏0
  • php 比特幣教程大更新,包括交易和閃兌

    摘要:課程簡介創建一個機器人機器人接受比特幣并立即退還用戶創建比特幣錢包買賣實時兌換買賣在自由市場掛單買賣買賣任意在自由市場掛單買賣其他編程語言比特幣開發教程如下比特幣開發教程比特幣開發教程比特幣開發教程比特幣開發教程比特幣開發教程比特幣開發教程 showImg(https://segmentfault.com/img/bVboFQ6?w=1200&h=659); 課程簡介 PHP 創建一...

    avwu 評論0 收藏0
  • php 比特幣教程大更新,包括交易和閃兌

    摘要:課程簡介創建一個機器人機器人接受比特幣并立即退還用戶創建比特幣錢包買賣實時兌換買賣在自由市場掛單買賣買賣任意在自由市場掛單買賣其他編程語言比特幣開發教程如下比特幣開發教程比特幣開發教程比特幣開發教程比特幣開發教程比特幣開發教程比特幣開發教程 showImg(https://segmentfault.com/img/bVboFQ6?w=1200&h=659); 課程簡介 PHP 創建一...

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

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

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

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

    APICloud 評論0 收藏0

發表評論

0條評論

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