ビットコインとシステムトレード (Bitcoin & Automated Algorithmic Trading)

ビットコインの自動売買システム構築とトレード実践結果 (Automatic Bitcoin Trading System Implementation and Trading Result)

Quoine, BtcBox, coincheck, zaif, そしてbitFlyer その2 - The latest situation of Japanese Bitcoin exchange competition Part 2

f:id:deshita:20170304180508j:plain

以前にエントリを書いてから状況が変わってきたので、その2として書きます。

主観がかなり入っております。

bitcoin-system-trading.hatenablog.com

2月・3月は出来高に関して下記のような構図が続くと思われます。

bitFlyer >>> Quoine > coincheck = zaif >>> BTCBOX >>> Kraken

1ヶ月の間に構図が大きく変わってきて、現時点ではこのような感じかと。

Quoine = coincheck = zaif > bitFlyer >>> BtcBox >>> Kraken

  • bitFlyerはFX部分で解決すべき問題があるはずで、FXはここでは考慮から除外。
  • Quoineは恒常的に割安だったことが多く、そこがトレーダーの不安を掻き立てていた部分があったかと。最近は落ち着いてきて、不安が払拭されつつある(はず)。トレード画面の使い勝手は良いが、痒いところに手が届いていない印象。
  • coincheckは読みどおり躍進。地道な改良を積み重ねて攻めモード。
  • zaifは正直どの部分が支持されているのか、まだあまりわかっていません。。
  • BtcBox/Krakenは今後の取引所競争に勝ち抜いていくにはもう厳しいのではないか(撤退もありえる?)

また、海外に目を向けるとCNY圏崩壊後、価格について下記のような構図が続いている模様。Fiatからの両替・送金手数料・所要日数を考えると効果的な裁定取引ができるのかは未知。ここはもう少し検証を続けていきたいところです。

KRW > JPY > USD = EUR > CNY

As the situation in JP Bitcoin market has been changed since I wrote my previous entry , I wrote this part 2 post. My forecast was that in February and March it seemed that the following volume-share composition would continue.

BitFlyer >>> Quoine > coincheck = zaif >>> BTCBOX >>> Kraken

However, it has changed significantly just in one month, and at this time it looks like this.

Quoine = coincheck = zaif > bitFlyer >>> BtcBox >>> Kraken

  • Since bitFlyer seems to have problems to be solved in the FX part, FX is excluded from consideration here.
  • Quoine's price was often cheap on a permanent basis, and there was a part that was stirring up traders' anxiety. Recently it has calmed down, anxiety is being dispelled (should be). Usability of the trade screen is good, but my impression that hands have not reached the itchy place.
  • Coincheck has increased its presence as I expected. Steady improvements are accumulated and they are in attacking mode.
  • Honestly speaking about Zaif, I am not sure what part is supported by traders..
  • Is not BtcBox / Kraken severe enough to win exchange competition. (I think there is a possiblity of exit from JP market)

Also, looking overseas, after the collapse of the CNY zone, it seems that the following price composition is continuing. It is unsure whether effective arbitrage transaction can be done considering deposit from fiat, overseas remmittance fee, and the required number of days for overseas remittance. This is the topic I want to continue verifying more.

KRW > JPY > USD = EUR > CNY

日本のビットコイン相場を暴落させるために必要な資金量 - The amount of funds necessary to crash Japanese largest bitcoin market

f:id:deshita:20170225020133j:plain

じわりじわりと上昇を続けての暴落(ガラ)。ビットコインらしい動きです。安定した決済通貨として利用できる日はいつの日やら。。

参考までに、いったいどれだけの資金量があれば相場にそれだけのインパクトが与えられるのか、板情報(bitFlyer現物)を元に計算してみました。

結果は下記の通りで、成行で一気に売りを浴びせた場合。実際は他者の追随もあるので、必要な資金量はもっと少ないかもしれません。

1.5億円あれば10%下げさせることができ、4億円もあれば3割減に持っていけます。思ったよりも少ないというのが印象です。豊富な中国マネーが流れ込んでいると考えられる今、そういった操縦で一時的に市場を混乱させるという行動もありえるかもしれませんね。

Crash after continued rising. It is a typical movement in bitcoin market. Does the day when we can use bitcoin as stable settlement currency come. .?

For your reference, I tried calculating based on the board information (bitFlyer spot) as to how much amount of funds is required to give such a crash impact to its market price.

The result is as follows and it is a case where we execute market sell orders at a time. Actually, others' reaction may boost it, so the necessary amount of funds may be less.

If we spend 150 million yen it can fall by 10%, if it is 400 million yen it can be dropped by 30%. My impression is that it is less than I expected. Now that it is thought that abundant Chinese money is flowing into JP BTC market, it may be possible to act to temporarily confuse the market with such maneuvering. 

f:id:deshita:20170225024400p:plain

f:id:deshita:20170225024409p:plain

ビットコインのHFT(高頻度取引)は可能か? その2 - Is Bitcoin HFT (high frequency trading) possible in Japan? Part 2

f:id:deshita:20170213215958j:plain

各取引所のAPI提供元ホストがどのロケーションに登録されているかを調べてみました。

  • bitFlyer/QuoineがCalifornia、
  • Zaif/coincheck/BtcBoxがTokyo(AWS)

という結果でした。

これはあくまでもリクエストの入り口がどこにあるかというだけで、その奥の物理構成がどうなっているかまでを示すものではありません。しかし、通信のレイテンシーボトルネックになってくるようであれば、リクエスト元(VPS等)のロケーションと極力揃えるなど、考慮に入れてもよいかもしれません。

I examined which location the API provider's host of each Japanese bitcoin exchange is registered. Here is the result.

  • BitFlyer / Quoine is California,
  • Zaif / coincheck / BtcBox is Tokyo ( AWS )

This is just where the entry point of requests is and does not indicate how the physical backend composition is built. However, if response latency seems to be a bottleneck , it may need to be taken into consideration, as your reference, such as aligning with the location of the request source ( VPS etc.) as close as possible.

www.iplocationfinder.com

HostHostnameISPCityRegion
api.bitflyer.jp 107.154.248.134.ip.incapdns.net Incapsula Redwood City California
api.quoine.com 104.20.0.28 (IP) CloudFlare San Francisco California
api.zaif.jp ec2-52-69-226-84.ap-northeast-1.compute.amazonaws.com Amazon Technologies Tokyo Tokyo
coincheck.com ec2-52-68-5-65.ap-northeast-1.compute.amazonaws.com Amazon Technologies Tokyo Tokyo
www.btcbox.co.jp ec2-52-69-156-194.ap-northeast-1.compute.amazonaws.com Amazon Technologies Tokyo Tokyo

ビットコインのHFT(高頻度取引)は可能か? - Is Bitcoin HFT (high frequency trading) possible in Japan?

f:id:deshita:20170205210955j:plain

日本のビットコイン取引所でHFT(高頻度取引)は可能なのか、検証してみました。

条件

  • 国内最大規模で取引所システム性能が最も良いであろうbitFlyerが対象
  • Public APIの基本であるTicker取得を利用
  • 非同期処理で400ms間隔で100回のリクエストを送信(100〜300msでリクエストを投げても結果が返ってこず。取引所側でリクエスト制限を設けている模様)
  • 取引所が正常稼働している状態で測定(=gethealthで取得した取引所の状態がNORMAL)

結果

左側:timestampの値とその回数(同じ値が何度も返ってきている)

右側:各秒間において何種類の値が返ってきたかのカウント

f:id:deshita:20170205191552p:plain

右側をグラフ化しました。400ms間隔で投げているので、理論上は1秒間に最低2種類の値が返ってくるはず。しかし、取引所が提供するticker情報の更新はそこまで高速ではないようです。おおよそTPS(ticker per second)=1〜2程度です。

f:id:deshita:20170205185549p:plain

ticker取得でこの速度であるため、板情報取得や注文などはもっと遅いでしょうね。もっとも、内部で膨大な量のオーダーマッチングを行っているわけで、これでも莫大なサーバリソースが投入された末に実現されていることでしょうが。。

結論

株式市場で行われているようなミリ秒レベルのHFTは現状無理。現実的なところは、せいぜい1秒間隔での取引(Realtime APIを駆使すれば多少違うかも)。

気が向いたら日本国内取引所間の比較を行ってみて、「その2」として記事にします。

I tried to verify whether HFT (High Frequency Trading) is possible at the bitcoin exchange in Japan.

Conditions

  • For bitFlyer that is the largest in Japan and would have the best exchange system performance
  • Use Ticker acquisition which is the basis of Public API
  • Sending 100 requests at asynchronous processing at 400 ms intervals (Results are not returned even if I throw requests in 100 - 300 ms , it seems that exchanges have request limits)
  • Measurement with exchanges operating normally (= the state of the exchange acquired with = gethealth is NORMAL)

Result

Left side: timestamp value and its number (same value has been returned many times)

Right side: Count of how many kinds of distinct values ​​are returned in each second

I graphed the right side. Since it is thrown with intervals of 400 ms, in theory at least two kinds of values ​​will be returned in one second. However, it seems that updating the ticker information provided by the exchange is not so fast. Approximately TPS (ticker per second) = about 1 to 2.

Because this speed is acquired by ticker acquisition , board information acquisition and buy/sell order etc might be slower. However, the exchange are doing an enormous amount of order matching internally, so even this performance is achieved after huge server resource introduction. .

Conclusion

Millisecond level HFT as it is done in stock markets is impossible at present. The realistic thing is that at most, trading at 1 second intervals (it may differ somewhat if Realtime API is used).

If you feel like it, I will try comparing performance among domestic exchanges in Japan and write it as "Part 2".

bitFlyer自動取引botのコア部分(発注機能)Rubyソースコード

ビットコインをbitFlyer上で自動取引するbotのコア部分である発注機能(成行注文版)のRubyソースコードを公開します(エラーハンドリングが甘いですが、、間違いや改善点があれば教えてくださいm(_ _)m)。指値注文も、LIMITとpriceを指定すれば簡単に実装できます。product_codeを指定することで、現物にもFXにも使えます。ササッとアイデアを実装に落とし込めるのは、やはりRubyの強みですね。

lightning.bitflyer.jp

#!/usr/bin/ruby

require 'uri'
require 'net/http'
require 'time'
require 'securerandom'
require 'base64'
require 'json'

 

API_KEY = '{{ YOUR API KEY }}'
API_SECRET = '{{ YOUR API SECRET }}'

 

def order(product_code, buy_sell, size)
    timestamp = Time.now.to_i.to_s
    uri = URI.parse("https://api.bitflyer.jp")
    uri.path = "/v1/me/sendchildorder"

    body = '{
        "product_code" : "' + product_code + '",
        "child_order_type" : "MARKET",
        "side" : "' + buy_sell + '",
        "size" : ' + size.to_s + ',
        "minute_to_expire" : 10000,
        "time_in_force" : "GTC"
    }'

    text = timestamp + 'POST' + uri.request_uri + body
    sign = OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new("sha256"), API_SECRET, text)
    options = Net::HTTP::Post.new(uri.request_uri, initheader = {
        "ACCESS-KEY" => API_KEY,
        "ACCESS-TIMESTAMP" => timestamp,
        "ACCESS-SIGN" => sign,
        "Content-Type" => "application/json"
    });
    options.body = body
    https = Net::HTTP.new(uri.host, uri.port)
    https.use_ssl = true
    response = https.request(options)
    result = JSON.parse(response.body)

    if (result['status'] == -201) then
        puts ' ' + product_code + ' ' + buy_sell + " You have reached the maximum amount of trades for your account class."
        return false
    end
    if (result['child_order_acceptance_id'] == nil) then
        puts ' ' + product_code + ' ' + buy_sell + " Insufficient funds"
        return false
    end
    if (result['child_order_acceptance_id'] != nil) then
        puts ' ' + product_code + ' ' + buy_sell + " id:" + result['child_order_acceptance_id'] + " size:" + size.to_s
    end
    return true
end

 

 

詐欺コインの蔓延がbotトレーダーを生かす - Fraud coin spread keeps on Bitcoin bot traders alive

ビットコイン」というと世間一般ではまだ「訳のわからない怪しい金融商品」ではないでしょうか?最近はプラットフォームも整備されてきたので、誰でも簡単に独自の仮想通貨を作れる時代。そのため、詐欺・ねずみ講的な仮想通貨も生まれています(もちろん同時に消えてもいる)。

doublehash.me

仮想通貨は詐欺師業界でホット(を通り越して「過去最高」とも言われるよう)な一大商材。そもそも実体があるものではないし、過去の値上がり類似事例(ビットコイン含む)も豊富。「ビットコインは価格が上昇し切っています。われわれ代理店が先行販売するこのコインなら・・・」

ビットコイン( or 世界取引高がせいぜい10位以内の仮想通貨)を取引されている情強トレーダーの皆様方には無縁でしょう。でもこれ、botトレーダーにとっては結構喜ばしいことではないでしょうか?

慈善や産業振興と絡めたバリエーションなど、正直、出尽くした感はありますが、詐欺師と情弱が繰り広げる世界はこれからも数年は続いていき、詐欺は摘発・HYIPは崩壊。業界は浄化されつつも、ニュースで報じられる度にビットコインのイメージは引きずられて悪化、、、、。「うん、大歓迎。」そんなトレーダーの方々は意外と多いと想像しております。

世の中にはビットコインのイメージを良くする要素と悪くする要素があって、悪くする要素は価格のボラティリティを上げるわけです。トレーダーにとっては、煽りはしないまでも、静観する方が多いのかな、と。

ビットコインのイメージを悪くする要素(長期的なボラティリティを上げる)

  • やましい使い方(資金洗浄や資産逃避)
  • ねずみ講まがいの詐欺コインやHYIP
  • 取引所の破綻やハッキング事件

ビットコインのイメージを良くする要素(長期的なボラティリティを下げる)

  • 中国政府による規制
  • ネット上の正義(検証サイトなど)による詐欺の浄化・啓蒙活動
  • 取引所による政府に対するロビー活動

イメージと信頼のアップダウンを繰り返しつつも、

  • 大手資本によるFintechの後押し
  • FXからのプレイヤー流入
  • 大手FX業者がビットコイン取引所を開設
    (ただし、手数料を0%にしないと取引量が増えず、ひたすら消耗)
  • 取引手法の情報商材化が進行
  • bot開発者が武器商人化し、botがEA化

といった未来を経て、長期的には新興国法定通貨レベルの安定性を獲得し、FX並みの市民権を得る投機ツールに落ち着くかと。ただ、そのときには美味しい部分は消え去ってしまっている。。

  • ほど良く胡散臭くて、(ある意味で)まともな人たちは参入できない
  • Mt.Gox事件からの教訓に学び、インフラや法規制が進みつつある
    (ただし、価格に歪みがある)
  • ガチな人(文字通り資本の桁が違うファンドなど)が浮動コイン取引に参入していない

今くらいが、個人botトレーダーにとっての幸せな時代なのかもしれません。

If "Bitcoin" is said to be common in the public in general, isn't it "a dubious financial product we cannot understand"? Recently the platform has been improved, so it is an era when anyone can easily create their own virtual currency. As a result, virtual fraud / ponzi scheme type of virtual currency is also born (of course disappeared at the same time).

The virtual currency is a big business material that is hot in the fraud industry (as it is said to be "the past highest"). In the first place, there is no real entity and there are also plenty of cases of similar price rise (including bitcoin ) in the past. "Bitcoin price has been already rising enough, but for the crypto currency for which we are sales agents..."

It will be immune to the people of the empowerment traders who are trading bitcoins (or virtual currencies with world trading volume at most 10th place). But this is quite happy for bot traders, isn't it?

Although there is a feeling of being honest and exhausted, such as a variation related to charity and industrial promotion, the world which the fraudster and empathy will spread will continue for a few years, fraud is caught · HYIP collapses. While the industry is purifying, the image of bitcoin is dragged out every time it is reported in the news, .... "Yeah, a big welcome." I imagine such traders are surprisingly large.

In the world, there are factors that improve the image of the bitcoin and factors to make it worse, the factor to make it worse boosts the volatility of the price. For traders, I wonder if there are more people to look at, even though they do not agitate it.

Elements that worsen the image of bit coin (increase long-term volatility)

  • Frugal usage (money wash and asset flight)
  • Ponzi Scheme coins and HYIP
  • Exchange bankruptcy and hacking incidents

Elements that improve the image of bit coins (lower long-term volatility)

  • Regulation by the Chinese government
  • Purification and awareness raising of fraud by online justice (verification site etc.)
  • Lobby activity by the bitcoin exchange to the government

While repeating image and trust up / down,

  • Boosting Fintech with major capital
  • Player inflow from FX
  • Major FX operator opens bitcoin exchange
    (However, if you do not decrease the commission to 0% trading volume will not increase, it will be worn out)
  • Advancement of trading method information commercialization progress
  • Bot developers become arms merchants, bot becomes EA in FX industry

After such a future, in the long term, bitcoin will gain stability of the legal currency level of the emerging countries and settle as a speculation tool to obtain citizenship equal to FX . However, at that time the delicious part has disappeared. .

  • It is "properly" shady, (in a sense) decent people can not enter
  • Lessons learned from Mt. Gox case, Infrastructure and regulations are progressing
    (However, price still has distortion for profit)
  • A decent and large capital (literally a fund with different capital digits, etc.) has not entered a floating coin trade

Now it may be a happy time for individual bot traders.