1
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

仮想通貨とPythonではじめる裁定取引 その1(準備編)

Posted at

Python×仮想通貨でアービトラージシステムをつくろう

海外大手3取引所で取引されている多種の通貨ペアに着目して、裁定取引の機会を検証します。
手始めに、対象となる通貨ペアを洗い出しましょう。

ライブラリインストールをしましょう。

pip install cryptojp

下記のコードを実行して裁定取引対象のペアを探しましょう。

from cryptojp import NewExchange
import itertools
import time

exchanges = ["hitbtc", "binance", "poloniex"]
exchanges_combinations = list(itertools.combinations(exchanges, 2))


class ArbitragePair(object):
    exchange_a = ""
    exchange_b = ""
    trading = ""
    settlement = ""

    def __init__(self, a, b, trading, settlement):
        self.exchange_a = a
        self.exchange_b = b
        self.trading = trading
        self.settlement = settlement

    def __str__(self):
        return "[%s-%s] %s_%s" % (self.exchange_a, self.exchange_b, self.trading, self.settlement)


arb_pairs = []
for ec in exchanges_combinations:
    cli0 = NewExchange(ec[0], "", "")
    cli1 = NewExchange(ec[1], "", "")
    ms0 = cli0.markets()
    ms1 = cli1.markets()
    for m0 in ms0:
        for m1 in ms1:
            if m0.trading == m1.trading and m0.settlement == m1.settlement:
                arb_pair = ArbitragePair(
                    ec[0], ec[1], m0.trading, m0.settlement)
                arb_pairs.append(arb_pair)

print(arb_pairs)

実行してみましょう。

[hitbtc-binance] DASH_BTC
[hitbtc-binance] ETH_BTC
[hitbtc-binance] LSK_BTC
[hitbtc-binance] STRAT_ETH
[hitbtc-binance] XEM_ETH
[hitbtc-binance] BQX_BTC
...
[binance-poloniex] LTC_USDT
[binance-poloniex] NAV_BTC
[binance-poloniex] STEEM_BTC
[binance-poloniex] STEEM_ETH
[binance-poloniex] VIA_BTC
[binance-poloniex] XEM_BTC

上記のような結果が得られるはずです。
次回は、裁定取引が可能な合計186の通貨ペアから、
価格検証を行っていきます。

1
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?