diff --git a/README.md b/README.md index c0be4d69f..81e9b9c2d 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,7 @@ Currently supported exchanges to get data: - Paymium (EUR) - BTC-e (USD, EUR) - Bitfinex (USD, EUR) + - bitFlyer (USD, EUR) - Kraken (USD, EUR) - OkCoin (CNY) - CampBX (USD) diff --git a/arbitrage/config.py-example b/arbitrage/config.py-example index 43b211708..5be4a30ab 100644 --- a/arbitrage/config.py-example +++ b/arbitrage/config.py-example @@ -1,11 +1,13 @@ markets = [ + "BitFlyerEUR", + "BitFlyerUSD", "BitfinexEUR", "BitfinexUSD", "BitstampEUR", "BitstampUSD", "CampBXUSD", - "CEXUSD", "CEXEUR", + "CEXUSD", "GDAXEUR", "GDAXUSD", "GeminiUSD", diff --git a/arbitrage/public_markets/_bitflyer.py b/arbitrage/public_markets/_bitflyer.py new file mode 100644 index 000000000..e9ba91c81 --- /dev/null +++ b/arbitrage/public_markets/_bitflyer.py @@ -0,0 +1,59 @@ +import urllib.request +import urllib.error +import urllib.parse +import json +import logging +from arbitrage.public_markets.market import Market + + +# { +# "mid_price": 33320, +# "bids": [ +# { +# "price": 30000, +# "size": 0.1 +# }, +# { +# "price": 25570, +# "size": 3 +# } +# ], +# "asks": [ +# { +# "price": 36640, +# "size": 5 +# }, +# { +# "price": 36700, +# "size": 1.2 +# } +# ] +# } +class BitFlyer(Market): + def __init__(self, currency, code): + super().__init__(currency) + self.code = code + self.update_rate = 20 + + def update_depth(self): + res = urllib.request.urlopen( + 'https://api.bitflyer.com/v1/board?product_code=' + self.code) + jsonstr = res.read().decode('utf8') + try: + depth = json.loads(jsonstr) + except Exception: + logging.error("%s - Can't parse json: %s" % (self.name, jsonstr)) + self.depth = self.format_depth(depth) + + def sort_and_format(self, l, reverse=False): + l.sort(key=lambda x: float(x["price"]), reverse=reverse) + r = [] + for i in l: + r.append({'price': float(i['price']), + 'amount': float(i['size'])}) + return r + + def format_depth(self, depth): + bids = self.sort_and_format(depth['bids'], True) + asks = self.sort_and_format(depth['asks'], False) + return {'asks': asks, 'bids': bids} diff --git a/arbitrage/public_markets/bitflyereur.py b/arbitrage/public_markets/bitflyereur.py new file mode 100644 index 000000000..d36bcacd0 --- /dev/null +++ b/arbitrage/public_markets/bitflyereur.py @@ -0,0 +1,6 @@ +from arbitrage.public_markets._bitflyer import BitFlyer + +class BitFlyerEUR(BitFlyer): + def __init__(self): + super().__init__("EUR", "BTC_EUR") + diff --git a/arbitrage/public_markets/bitflyerusd.py b/arbitrage/public_markets/bitflyerusd.py new file mode 100644 index 000000000..8c0cc672a --- /dev/null +++ b/arbitrage/public_markets/bitflyerusd.py @@ -0,0 +1,6 @@ +from arbitrage.public_markets._bitflyer import BitFlyer + +class BitFlyerUSD(BitFlyer): + def __init__(self): + super().__init__("USD", "BTC_USD") +