-
Notifications
You must be signed in to change notification settings - Fork 857
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for bitflyer EUR and USD
- Loading branch information
Showing
3 changed files
with
71 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
|