|
17 | 17 |
|
18 | 18 |
|
19 | 19 | class ClientTest(unittest.TestCase): |
20 | | - def setUp(self): |
| 20 | + @classmethod |
| 21 | + def setUpClass(cls): |
21 | 22 | logging.basicConfig(level=logging.DEBUG) |
22 | 23 | config = ConfigParser() |
23 | 24 | dir_path = os.path.dirname(os.path.realpath(__file__)) |
24 | 25 | config.read('{}/../config/config.ini'.format(dir_path)) |
25 | | - self.client = Client(logging.getLogger(), host=config.get('ShiPanE', 'host'), key=config.get('ShiPanE', 'key')) |
26 | | - self.client.start_clients() |
| 26 | + cls.client = Client(logging.getLogger(), **dict(config.items('ShiPanE'))) |
| 27 | + cls.client_param = config.get('ShiPanE', 'client') |
| 28 | + cls.client.start_clients() |
27 | 29 |
|
28 | 30 | def test_get_account(self): |
29 | 31 | try: |
30 | | - self.client.get_account() |
| 32 | + self.client.get_account(self.client_param) |
31 | 33 | except HTTPError as e: |
32 | 34 | self.fail() |
33 | 35 |
|
34 | 36 | def test_get_positions(self): |
35 | 37 | try: |
36 | | - data = self.client.get_positions() |
| 38 | + data = self.client.get_positions(self.client_param) |
37 | 39 | sub_accounts = data['sub_accounts'] |
38 | | - self.assertGreater(sub_accounts['总资产']['人民币'], 0) |
| 40 | + self.assertGreaterEqual(sub_accounts['余额']['人民币'], 0) |
39 | 41 | positions = data['positions'] |
40 | 42 | self.assertIsNotNone(positions['证券代码'][0]) |
41 | 43 | except HTTPError as e: |
42 | 44 | self.fail() |
43 | 45 |
|
44 | 46 | def test_buy_stock(self): |
45 | 47 | try: |
46 | | - order = self.client.buy(symbol='000001', price=8.11, amount=100) |
| 48 | + order = self.client.buy(self.client_param, symbol='000001', price=8.11, amount=100) |
47 | 49 | self.assertIsNotNone(order['id']) |
48 | 50 | except HTTPError as e: |
49 | 51 | result = e.response.json() |
50 | 52 | self.assertIsNotNone(result['message']) |
51 | 53 |
|
52 | 54 | def test_sell_stock(self): |
53 | 55 | try: |
54 | | - order = self.client.sell(symbol='000001', price=9.51, amount=100) |
| 56 | + order = self.client.sell(self.client_param, symbol='000001', price=9.51, amount=100) |
55 | 57 | self.assertIsNotNone(order['id']) |
56 | 58 | except HTTPError as e: |
57 | 59 | result = e.response.json() |
58 | 60 | self.assertIsNotNone(result['message']) |
59 | 61 |
|
60 | 62 | def test_cancel_all(self): |
61 | 63 | try: |
62 | | - self.client.cancel_all() |
| 64 | + self.client.cancel_all(self.client_param) |
63 | 65 | except HTTPError as e: |
64 | 66 | self.fail() |
65 | 67 |
|
66 | 68 | def test_query(self): |
67 | 69 | try: |
68 | | - df = self.client.query(None, '查询>资金股份') |
| 70 | + df = self.client.query(self.client_param, '查询>资金股份') |
69 | 71 | self.assertIsNotNone(df['证券代码'][0]) |
70 | 72 | except HTTPError as e: |
71 | 73 | self.fail() |
|
0 commit comments