Skip to content

Commit fb17338

Browse files
committed
Refine ClientTest
1 parent 62d1d54 commit fb17338

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

tests/config/config.ini.template

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
host=localhost
33
port=8888
44
key=
5+
client=
56

67
[JoinQuant]
78
username=

tests/shipane_sdk/test_client.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,55 +17,57 @@
1717

1818

1919
class ClientTest(unittest.TestCase):
20-
def setUp(self):
20+
@classmethod
21+
def setUpClass(cls):
2122
logging.basicConfig(level=logging.DEBUG)
2223
config = ConfigParser()
2324
dir_path = os.path.dirname(os.path.realpath(__file__))
2425
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()
2729

2830
def test_get_account(self):
2931
try:
30-
self.client.get_account()
32+
self.client.get_account(self.client_param)
3133
except HTTPError as e:
3234
self.fail()
3335

3436
def test_get_positions(self):
3537
try:
36-
data = self.client.get_positions()
38+
data = self.client.get_positions(self.client_param)
3739
sub_accounts = data['sub_accounts']
38-
self.assertGreater(sub_accounts['总资产']['人民币'], 0)
40+
self.assertGreaterEqual(sub_accounts['余额']['人民币'], 0)
3941
positions = data['positions']
4042
self.assertIsNotNone(positions['证券代码'][0])
4143
except HTTPError as e:
4244
self.fail()
4345

4446
def test_buy_stock(self):
4547
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)
4749
self.assertIsNotNone(order['id'])
4850
except HTTPError as e:
4951
result = e.response.json()
5052
self.assertIsNotNone(result['message'])
5153

5254
def test_sell_stock(self):
5355
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)
5557
self.assertIsNotNone(order['id'])
5658
except HTTPError as e:
5759
result = e.response.json()
5860
self.assertIsNotNone(result['message'])
5961

6062
def test_cancel_all(self):
6163
try:
62-
self.client.cancel_all()
64+
self.client.cancel_all(self.client_param)
6365
except HTTPError as e:
6466
self.fail()
6567

6668
def test_query(self):
6769
try:
68-
df = self.client.query(None, '查询>资金股份')
70+
df = self.client.query(self.client_param, '查询>资金股份')
6971
self.assertIsNotNone(df['证券代码'][0])
7072
except HTTPError as e:
7173
self.fail()

0 commit comments

Comments
 (0)