forked from ericjang/cryptocurrency_arbitrage
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBTCE.py
90 lines (78 loc) · 2.86 KB
/
BTCE.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
from Exchange import Exchange
import btceapi
import os
from order import Order
class BTCE(Exchange):
def __init__(self, keyfile):
keyfile = os.path.abspath(keyfile)
self.keyhandler = btceapi.KeyHandler(keyfile)
key = self.keyhandler.getKeys()[0]
self.conn = btceapi.BTCEConnection()
self.api = btceapi.TradeAPI(key, self.keyhandler)
super(BTCE, self).__init__()
self.name = 'BTCE'
self.trading_fee = 0.002
def get_tradeable_pairs(self):
tradeable_pairs = []
for pair in btceapi.all_pairs:
a, b = pair.split("_")
tradeable_pairs.append((a.upper(), b.upper()))
return tradeable_pairs
def get_depth(self, base, alt):
book = {'bids': [], 'asks': []}
pair, swapped = self.get_validated_pair((base, alt))
if pair is None:
return
pairstr = pair[0].lower() + "_" + pair[1].lower()
if swapped:
bids, asks = btceapi.getDepth(pairstr)
else:
asks, bids = btceapi.getDepth(pairstr)
book['bids'] = [Order(float(b[0]), float(b[1])) for b in bids]
book['asks'] = [Order(float(a[0]), float(a[1])) for a in asks]
return book
def get_balance(self, currency):
data = self.api.getInfo(connection = self.conn)
return getattr(data, 'balance_' + currency.lower())
def get_all_balances(self):
balances = self.api.getBalances(self.conn)
return balances
def submit_order(self, gc, gv, rc, rv):
pair, swapped = self.get_validated_pair((rc, gc))
print swapped
if pair is None:
return
pairstr = pair[0].lower() + "_" + pair[1].lower()
if swapped:
price = rv/gv
self.api.trade(pairstr, 'sell', price, gv)
else:
price = gv/rv
self.api.trade(pairstr, 'buy', price, rv)
def confirm_order(self, orderID):
pass
# def get_min_vol(self, base, alt):
# '''
# returns the minimum required trading volume for the currency
# (buy and sell orders)
# '''
# for slug in btceapi.min_orders:
# b = slug.split("_")[0].upper()
# if b == base:
# return float(btceapi.min_orders[slug])
# return 0.1
def get_min_vol(self, pair, depth):
"""
override default implementation - BTCE has min volumes 0.1 ALT !!!
"""
base, alt = pair
slug = base + "_" + alt
test = self.get_validated_pair(pair)
if test is not None:
true_pair, swapped = test
if not swapped:
return 0.1
else:
# we need to use the depth information to calculate
# how much alt we need to trade to fulfill min base vol
return self.get_clipped_alt_volume(depth, 0.101)