forked from shidenggui/easytrader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_easytrader.py
101 lines (71 loc) · 2.9 KB
/
test_easytrader.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
# coding: utf-8
import os
import sys
import time
import unittest
sys.path.append('.')
import easytrader
TEST_CLIENTS = os.environ.get('EZ_TEST_CLIENTS', 'yh')
@unittest.skipUnless('yh' in TEST_CLIENTS, 'skip yh test')
class TestYhClientTrader(unittest.TestCase):
@classmethod
def setUpClass(cls):
if 'yh' not in TEST_CLIENTS:
return
# input your test account and password
cls._ACCOUNT = os.environ.get('EZ_TEST_YH_ACCOUNT') or 'your account'
cls._PASSWORD = os.environ.get('EZ_TEST_YH_password') or 'your password'
cls._user = easytrader.use('yh_client')
cls._user.prepare(user=cls._ACCOUNT, password=cls._PASSWORD)
def test_balance(self):
time.sleep(3)
result = self._user.balance
def test_today_entrusts(self):
result = self._user.today_entrusts
def test_today_trades(self):
result = self._user.today_trades
def test_cancel_entrusts(self):
result = self._user.cancel_entrusts
def test_cancel_entrust(self):
result = self._user.cancel_entrust('123456789')
def test_invalid_buy(self):
with self.assertRaises(easytrader.exceptions.TradeError):
result = self._user.buy('511990', 1, 1e10)
def test_invalid_sell(self):
with self.assertRaises(easytrader.exceptions.TradeError):
result = self._user.sell('162411', 200, 1e10)
def test_auto_ipo(self):
self._user.auto_ipo()
@unittest.skipUnless('ht' in TEST_CLIENTS, 'skip ht test')
class TestHTClientTrader(unittest.TestCase):
@classmethod
def setUpClass(cls):
if 'ht' not in TEST_CLIENTS:
return
# input your test account and password
cls._ACCOUNT = os.environ.get('EZ_TEST_HT_ACCOUNT') or 'your account'
cls._PASSWORD = os.environ.get('EZ_TEST_HT_password') or 'your password'
cls._COMM_PASSWORD = os.environ.get('EZ_TEST_HT_comm_password') or 'your comm password'
cls._user = easytrader.use('ht_client')
cls._user.prepare(user=cls._ACCOUNT, password=cls._PASSWORD, comm_password=cls._COMM_PASSWORD)
def test_balance(self):
time.sleep(3)
result = self._user.balance
def test_today_entrusts(self):
result = self._user.today_entrusts
def test_today_trades(self):
result = self._user.today_trades
def test_cancel_entrusts(self):
result = self._user.cancel_entrusts
def test_cancel_entrust(self):
result = self._user.cancel_entrust('123456789')
def test_invalid_buy(self):
with self.assertRaises(easytrader.exceptions.TradeError):
result = self._user.buy('511990', 1, 1e10)
def test_invalid_sell(self):
with self.assertRaises(easytrader.exceptions.TradeError):
result = self._user.sell('162411', 200, 1e10)
def test_auto_ipo(self):
self._user.auto_ipo()
if __name__ == '__main__':
unittest.main()