forked from ericjang/cryptocurrency_arbitrage
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFXBTC.py
111 lines (98 loc) · 3.81 KB
/
FXBTC.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# exchange class for FXBTC - I expect that there will be more arb opportunities
# since chinese and US markets are fundamentally mispriced.
# NOTE: all rates and currencies multiplied by 10^8 to avoid floating point!
# this will be a very important consideration
from Exchange import Exchange
from fxbtc import fx
from myutils import get_swapped_order
from order import Order
class FXBTC(Exchange):
def __init__(self, api_key, secret):
# self.api = fx(api_key, secret)
super(FXBTC, self).__init__()
self.name = 'FXBTC'
self.trading_fee = 0.002 # TODO - check this
self.marketids = {}
def get_tradeable_pairs(self):
pass
# tradeable_pairs = []
# self.pairIDs = {} # also initialize pairID reference while we're at it
# trade_pairs = self.api.get_trade_pairs()
# for pair in trade_pairs["trade_pairs"]:
# pairID = str(pair["id"])
# currencies = pair["url_slug"].split("_")
# base = currencies[0].upper()
# alt = currencies[1].upper()
# tradeable_pairs.append((base, alt))
# slug = base + "_" + alt
# self.pairIDs[slug] = pairID
# return tradeable_pairs
def get_depth(self, base, alt):
pass
# """
# coinEx does not support retrieving all depths! GRRRR
# TODO - need to also append orderID!!!
# """
# pair0 = (base, alt)
# pair, swapped = self.get_validated_pair(pair0)
# newbase, newalt = pair
# pairID = self.get_pairID(newbase, newalt)
# orders = self.api.get_orders(pairID)
# book = { "bids" : [], "asks" : [] }
# for data in orders["orders"]:
# if not data["complete"]:
# price = float(data["rate"]*1e-8)
# volume = float(data["amount"]*1e-8)
# order = Order(price, volume, orderID=data['id'], timestamp=data['created_at'])
# if not swapped:
# if data['bid']: # buy order
# book['bids'].append(order)
# else: # sell order
# book['asks'].append(order)
# else: # is swapped
# order = get_swapped_order(order)
# if data['bid']:
# book['asks'].append(order)
# else:
# book['bids'].append(order)
#
# return book
def get_balance(self, currency):
pass
# '''
# warning: dont call this too often.
# use get_all_balances instead
# '''
# balances = self.api.get_balances()
# for c in balances["balances"]:
# if currency == c["currency_name"]:
# return c["amount"] * 1e-8
# return 0.0
def get_all_balances(self):
pass
# data = self.api.get_balances()
# balances = {c["currency_name"] : c["amount"]*1e-8 for c in data['balances']}
# return balances
def submit_order(self, gc, gv, rc, rv):
return NotImplemented
# pair0 = (gc, rc)
# pair, swapped = self.get_validated_pair(pair0)
# newbase, newalt = pair
# pairID = self.get_pairID(newbase, newalt)
# TODO, do maths here
# self.api.submit_order(self, pairID, amount, order_type, rate)
def confirm_order(self, orderID):
pass
#data = self.api.get_order_status(orderID)
# TODO
# borrowed from Cryptsy API
def get_pairID(self, base, alt):
pass
# if (base, alt) in self.tradeable_pairs:
# slug = base + "_" + alt
# return self.pairIDs[slug]
# elif (alt, base) in self.tradeable_pairs:
# slug = alt + "_" + base
# return self.pairIDs[slug]
# else:
# return 'ERROR!'