Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
maxme committed Feb 4, 2018
2 parents 0664aff + 3e03370 commit 3bce01c
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion arbitrage/config.py-example
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
markets = [
"BitFlyerEUR",
"BitFlyerUSD",
"BitfinexEUR",
"BitfinexUSD",
"BitstampEUR",
"BitstampUSD",
"CampBXUSD",
"CEXUSD",
"CEXEUR",
"CEXUSD",
"GDAXEUR",
"GDAXUSD",
"GeminiUSD",
Expand Down
59 changes: 59 additions & 0 deletions arbitrage/public_markets/_bitflyer.py
Original file line number Diff line number Diff line change
@@ -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}
6 changes: 6 additions & 0 deletions arbitrage/public_markets/bitflyereur.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from arbitrage.public_markets._bitflyer import BitFlyer

class BitFlyerEUR(BitFlyer):
def __init__(self):
super().__init__("EUR", "BTC_EUR")

6 changes: 6 additions & 0 deletions arbitrage/public_markets/bitflyerusd.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from arbitrage.public_markets._bitflyer import BitFlyer

class BitFlyerUSD(BitFlyer):
def __init__(self):
super().__init__("USD", "BTC_USD")

0 comments on commit 3bce01c

Please sign in to comment.