Counterpartyd Order APIを使ってAssetの売り注文を出す

f:id:yzono:20141113155254j:plain

はじめに

前回Counterpartyd Send APIを使ってAssetの送信を行いましたが、Order APIを使ってAssetの売り注文を出します。

目次

  • 使用するアドレスと残高
  • Order API実行
  • 注文結果を確認

使用するアドレスと残高

売り買い注文に使用するアドレスを整理します。注文を出す側は手数料としてビットコインを持っておく必要があります。

売り注文を出すアドレス

(ビットコインインスタンス)自分のサーバー

(ビットコインアドレス)1A31xhRp9FyQZXG57hXczaVLkH5Dm3m9jy

(持っているアセット)

$ curl http://127.0.0.1:4000/api/ --user rpc:xcppw1234 -H 'Content-Type: application/json; charset=UTF-8' -H 'Accept: application/json, text/javascript' --data-binary '{"jsonrpc":"2.0", "id":0, "method":"get_balances", "params":{"filters": {"field": "address", "op": "==", "value": "1A31xhRp9FyQZXG57hXczaVLkH5Dm3m9jy"}}}'

{"jsonrpc": "2.0", "id": 0, "result": [{"address": "1A31xhRp9FyQZXG57hXczaVLkH5Dm3m9jy", "asset": "XZCOIN", "quantity": 9}]}
$ bitcoind listunspent
[
    {
        "txid" : "47e7d7201a1dbf43089b25eb53f95ad77adcb23315b6f86e52aaaff7a5fdbcbd",
        "vout" : 0,
        "address" : "1KMdf7VWLEBdCo9iwmtpW7kJaSzSAUz2zJ",
        "scriptPubKey" : "76a914c9592ee30658db40b4075f00a03ee48f32ba016288ac",
        "amount" : 0.00078000,
        "confirmations" : 247
    },
    {
        "txid" : "ac2e92b74008f048d94c29b51ef8caf96b267af07677c8bfe7bb0fb0bf99fa7e",
        "vout" : 2,
        "address" : "1A31xhRp9FyQZXG57hXczaVLkH5Dm3m9jy",
        "account" : "",
        "scriptPubKey" : "76a914631ac3fdba7d888adc1a8e928092e95eed08341f88ac",
        "amount" : 0.00174402,
        "confirmations" : 232
    },
    {
        "txid" : "e9d7d4b24ff1f997993b769c5a8bb0005dacb8744d70cb8c11e0e2bdb7dacdc9",
        "vout" : 0,
        "address" : "1A31xhRp9FyQZXG57hXczaVLkH5Dm3m9jy",
        "account" : "",
        "scriptPubKey" : "76a914631ac3fdba7d888adc1a8e928092e95eed08341f88ac",
        "amount" : 0.00010000,
        "confirmations" : 258
    },
    {
        "txid" : "eafc5f769481e058686199d4077dd6640ee3427f8462296b094b943692c65841",
        "vout" : 0,
        "address" : "1A31xhRp9FyQZXG57hXczaVLkH5Dm3m9jy",
        "account" : "",
        "scriptPubKey" : "76a914631ac3fdba7d888adc1a8e928092e95eed08341f88ac",
        "amount" : 0.00007800,
        "confirmations" : 237
    }
]

買い注文を出すアドレス(この記事では買い注文はしません)

(ビットコインインスタンス)counterwallet.io

(ビットコインアドレス)17sdLuNtD7ZpFCVZ3Doz58fwxFF6i6CKk2

(持っているアセット)

curl http://127.0.0.1:4000/api/ --user rpc:xcppw1234 -H 'Content-Type: application/json; charset=UTF-8' -H 'Accept: application/json, text/javascript' --data-binary '{"jsonrpc":"2.0", "id":0, "method":"get_balances", "params":{"filters": {"field": "address", "op": "==", "value": "17sdLuNtD7ZpFCVZ3Doz58fwxFF6i6CKk2"}}}'

{"jsonrpc": "2.0", "id": 0, "result": [{"address": "17sdLuNtD7ZpFCVZ3Doz58fwxFF6i6CKk2", "asset": "XCP", "quantity": 29000000}, {"address": "17sdLuNtD7ZpFCVZ3Doz58fwxFF6i6CKk2", "asset": "XZCOIN", "quantity": 99791}]}

counterwallet.ioからコピペ

Bal: 0.004354

API実行

create_order API実行

注文を実行します。注文内容は以下です。

(対象アセット)XZCOIN

(価格)0.01 XCP

(数量)1

(手数料forマイナー)20000satoshi(約8円)

"method":"create_order"を実行します。

curl http://127.0.0.1:4000/api/ --user rpc:xcppw1234 -H 'Content-Type: application/json; charset=UTF-8' -H 'Accept: application/json, text/javascript' --data-binary '{"jsonrpc":"2.0", "id":0, "method":"create_order", "params":{"source":"1A31xhRp9FyQZXG57hXczaVLkH5Dm3m9jy", "give_quantity":1, "give_asset":"XZCOIN", "get_quantity":1000000, "get_asset":"XCP", "expiration":1000, "fee_required":20000 }}'

{"result": "01000000017efa99bfb00fbbe7bfc87776f07a266bf9caf81eb5294cd948f00840b7922eac020000001976a914631ac3fdba7d888adc1a8e928092e95eed08341f88acffffffff02781e00000000000069512103d350d66ebb21e3006a8853f9d2c593e0d42de0d53acc6ab2f16eb010b8a5b86621034ddcf141a1116b35df7970c8672b83e2daf2de1a94a808a1abc8008ccad1551a2102d87f26c0a4a56e0172516cdf7139f383d93e76d17455b66f45e41404a93643d353aeba630200000000001976a914631ac3fdba7d888adc1a8e928092e95eed08341f88ac00000000", "jsonrpc": "2.0", "id": 0}

sign_tx API実行

curl http://127.0.0.1:4000/api/ --user rpc:xcppw1234 -H 'Content-Type: application/json; charset=UTF-8' -H 'Accept: application/json, text/javascript' --data-binary '{"jsonrpc":"2.0", "id":0, "method":"sign_tx", "params":{"unsigned_tx_hex":"01000000017efa99bfb00fbbe7bfc87776f07a266bf9caf81eb5294cd948f00840b7922eac020000001976a914631ac3fdba7d888adc1a8e928092e95eed08341f88acffffffff02781e00000000000069512103d350d66ebb21e3006a8853f9d2c593e0d42de0d53acc6ab2f16eb010b8a5b86621034ddcf141a1116b35df7970c8672b83e2daf2de1a94a808a1abc8008ccad1551a2102d87f26c0a4a56e0172516cdf7139f383d93e76d17455b66f45e41404a93643d353aeba630200000000001976a914631ac3fdba7d888adc1a8e928092e95eed08341f88ac00000000"}}'

{"result": "01000000017efa99bfb00fbbe7bfc87776f07a266bf9caf81eb5294cd948f00840b7922eac020000006b483045022100a5378b44d4c895c6d6fbd57194ecc1e6de44ef500c58857d37b967560d27c4ee02207622d87d2508d6944f4510bcfd3c7603dc0652adbae92f4c36cc83fb98bbcf41012102d87f26c0a4a56e0172516cdf7139f383d93e76d17455b66f45e41404a93643d3ffffffff02781e00000000000069512103d350d66ebb21e3006a8853f9d2c593e0d42de0d53acc6ab2f16eb010b8a5b86621034ddcf141a1116b35df7970c8672b83e2daf2de1a94a808a1abc8008ccad1551a2102d87f26c0a4a56e0172516cdf7139f383d93e76d17455b66f45e41404a93643d353aeba630200000000001976a914631ac3fdba7d888adc1a8e928092e95eed08341f88ac00000000", "jsonrpc": "2.0", "id": 0}

broadcast_tx API実行

curl http://127.0.0.1:4000/api/ --user rpc:xcppw1234 -H 'Content-Type: application/json; charset=UTF-8' -H 'Accept: application/json, text/javascript' --data-binary '{"jsonrpc":"2.0", "id":0, "method":"broadcast_tx", "params":{"signed_tx_hex":"01000000017efa99bfb00fbbe7bfc87776f07a266bf9caf81eb5294cd948f00840b7922eac020000006b483045022100a5378b44d4c895c6d6fbd57194ecc1e6de44ef500c58857d37b967560d27c4ee02207622d87d2508d6944f4510bcfd3c7603dc0652adbae92f4c36cc83fb98bbcf41012102d87f26c0a4a56e0172516cdf7139f383d93e76d17455b66f45e41404a93643d3ffffffff02781e00000000000069512103d350d66ebb21e3006a8853f9d2c593e0d42de0d53acc6ab2f16eb010b8a5b86621034ddcf141a1116b35df7970c8672b83e2daf2de1a94a808a1abc8008ccad1551a2102d87f26c0a4a56e0172516cdf7139f383d93e76d17455b66f45e41404a93643d353aeba630200000000001976a914631ac3fdba7d888adc1a8e928092e95eed08341f88ac00000000"}}'

{"result": "262d61342e01a0045ecb17af3d0788625bab01b2ef61cd6fe9663495482f7ff4", "jsonrpc": "2.0", "id": 0}

注文結果を確認

READ APIを使ってOrder情報を見てみましょう。

curl http://127.0.0.1:4000/api/ --user rpc:xcppw1234 -H 'Content-Type: application/json; charset=UTF-8' -H 'Accept: application/json, text/javascript' --data-binary '{"jsonrpc":"2.0", "id":0, "method":"get_orders", "params":{"filters": {"field": "tx_hash", "op": "==", "value": "262d61342e01a0045ecb17af3d0788625bab01b2ef61cd6fe9663495482f7ff4"}}}'

{"result": [{"get_quantity": 1000000, "tx_index": 10122724, "give_asset": "XZCOIN", "block_index": 335834, "status": "open", "fee_provided": 10000, "source": "1A31xhRp9FyQZXG57hXczaVLkH5Dm3m9jy", "give_quantity": 1, "fee_required": 20000, "give_remaining": 1, "tx_hash": "262d61342e01a0045ecb17af3d0788625bab01b2ef61cd6fe9663495482f7ff4", "expiration": 1000, "fee_provided_remaining": 10000, "get_remaining": 1000000, "fee_required_remaining": 20000, "expire_index": 336834, "get_asset": "XCP"}], "jsonrpc": "2.0", "id": 0}

Blockscan

Blockscanのサイトを見ると、売りの注文が発生していることが分かります。

f:id:yzono:20141226011928p:plain

counterwallet.ioにも注文が反映されています。

curl http://127.0.0.1:4000/api/ --user rpc:xcppw1234 -H 'Content-Type: application/json; charset=UTF-8' -H 'Accept: application/json, text/javascript' --data-binary '{"jsonrpc":"2.0", "id":0, "method":"get_balances", "params":{"filters": {"field": "address", "op": "==", "value": "1A31xhRp9FyQZXG57hXczaVLkH5Dm3m9jy"}}}'

{"result": [{"asset": "XCP", "quantity": 1000000, "address": "1A31xhRp9FyQZXG57hXczaVLkH5Dm3m9jy"}, {"asset": "XZCOIN", "quantity": 8, "address": "1A31xhRp9FyQZXG57hXczaVLkH5Dm3m9jy"}], "jsonrpc": "2.0", "id": 0}

アセットも9->8に減っていることが分かります。

まとめ

注文はできました。次回は買い注文を出します。