forked from maxme/bitcoin-arbitrage
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharbitrage_test.py
76 lines (66 loc) · 2.47 KB
/
arbitrage_test.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
import sys
sys.path.append('src/')
sys.path.append('../src/')
import unittest
import arbitrage
depths1 = {
'BitcoinCentralEUR':
{'asks': [{'amount': 4, 'price': 32.8},
{'amount': 8, 'price': 32.9},
{'amount': 2, 'price': 33.0},
{'amount': 3, 'price': 33.6}],
'bids': [{'amount': 2, 'price': 31.8},
{'amount': 4, 'price': 31.6},
{'amount': 6, 'price': 31.4},
{'amount': 2, 'price': 30}]},
'MtGoxEUR':
{'asks': [{'amount': 1, 'price': 34.2},
{'amount': 2, 'price': 34.3},
{'amount': 3, 'price': 34.5},
{'amount': 3, 'price': 35.0}],
'bids': [{'amount': 2, 'price': 33.2},
{'amount': 3, 'price': 33.1},
{'amount': 5, 'price': 32.6},
{'amount': 10, 'price': 32.3}]}}
depths2 = {
'BitcoinCentralEUR':
{'asks': [{'amount': 4, 'price': 32.8},
{'amount': 8, 'price': 32.9},
{'amount': 2, 'price': 33.0},
{'amount': 3, 'price': 33.6}]},
'MtGoxEUR':
{'bids': [{'amount': 2, 'price': 33.2},
{'amount': 3, 'price': 33.1},
{'amount': 5, 'price': 32.6},
{'amount': 10, 'price': 32.3}]}}
depths3 = {
'BitcoinCentralEUR':
{'asks': [{'amount': 1, 'price': 34.2},
{'amount': 2, 'price': 34.3},
{'amount': 3, 'price': 34.5},
{'amount': 3, 'price': 35.0}]},
'MtGoxEUR':
{'bids': [{'amount': 2, 'price': 33.2},
{'amount': 3, 'price': 33.1},
{'amount': 5, 'price': 32.6},
{'amount': 10, 'price': 32.3}]}}
class TestArbitrage(unittest.TestCase):
def setUp(self):
self.arbitrer = arbitrage.Arbitrer()
def test_getprofit1(self):
self.arbitrer.depths = depths2
profit, vol, wb, ws = self.arbitrer.get_profit_for(0, 0, 'BitcoinCentralEUR', 'MtGoxEUR')
assert(80 == int(profit * 100))
assert(vol == 2)
def test_getprofit2(self):
self.arbitrer.depths = depths2
profit, vol, wb, ws = self.arbitrer.get_profit_for(2, 1, 'BitcoinCentralEUR', 'MtGoxEUR')
assert(159 == int(profit * 100))
assert(vol == 5)
def test_getprofit3(self):
self.arbitrer.depths = depths3
profit, vol, wb, ws = self.arbitrer.get_profit_for(2, 1, 'BitcoinCentralEUR', 'MtGoxEUR')
assert(profit == 0)
assert(vol == 0)
if __name__ == '__main__':
unittest.main()