Skip to content

Commit 8e6effa

Browse files
committed
Support timeout when querying orders from online quant sites
1 parent 8e0cf84 commit 8e6effa

File tree

3 files changed

+15
-11
lines changed

3 files changed

+15
-11
lines changed

shipane_sdk/joinquant/client.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ def __init__(self, **kwargs):
1818
self._username = kwargs.get('username', None)
1919
self._password = kwargs.get('password', None)
2020
self._backtest_id = kwargs.get('backtest_id', None)
21+
self._timeout = kwargs.pop('timeout', (5.0, 10.0))
2122

2223
def login(self):
2324
self._session.headers = {
@@ -30,12 +31,12 @@ def login(self):
3031
'Origin': self.BASE_URL,
3132
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
3233
}
33-
self._session.get(self.BASE_URL)
34+
self._session.get(self.BASE_URL, timeout=self._timeout)
3435
response = self._session.post('{}/user/login/doLogin?ajax=1'.format(self.BASE_URL), data={
3536
'CyLoginForm[username]': self._username,
3637
'CyLoginForm[pwd]': self._password,
3738
'ajax': 1
38-
})
39+
}, timeout=self._timeout)
3940
self._session.headers.update({
4041
'cookie': response.headers['Set-Cookie']
4142
})
@@ -48,7 +49,7 @@ def query(self):
4849
'backtestId': self._backtest_id,
4950
'date': today_str,
5051
'ajax': 1
51-
})
52+
}, timeout=self._timeout)
5253
transaction_detail = response.json()
5354
raw_transactions = transaction_detail['data']['transaction']
5455
transactions = []

shipane_sdk/ricequant/client.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,16 @@ class RiceQuantClient(BaseQuantClient):
1010
def __init__(self, **kwargs):
1111
super(RiceQuantClient, self).__init__('RiceQuant')
1212

13-
self._rq_client = RQOpenClient(kwargs.get('username', None), kwargs.get('password', None))
13+
self._rq_client = RQOpenClient(kwargs.get('username', None), kwargs.get('password', None),
14+
timeout=kwargs.pop('timeout', (5.0, 10.0)))
1415
self._run_id = kwargs.get('run_id', None)
1516

1617
def login(self):
17-
self._rq_client.login()
18+
self._rq_client.login(timeout=self._timeout)
1819
super(RiceQuantClient, self).login()
1920

2021
def query(self):
21-
response = self._rq_client.get_day_trades(self._run_id)
22+
response = self._rq_client.get_day_trades(self._run_id, timeout=self._timeout)
2223
raw_transactions = response['resp']['trades']
2324
transactions = []
2425
for raw_transaction in raw_transactions:

shipane_sdk/uqer/client.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ def __init__(self, **kwargs):
1818
self._username = kwargs.get('username', None)
1919
self._password = kwargs.get('password', None)
2020
self._strategy = kwargs.get('strategy', None)
21+
self._timeout = kwargs.pop('timeout', (5.0, 10.0))
2122

2223
def login(self):
2324
self._session.headers = {
@@ -30,12 +31,12 @@ def login(self):
3031
'Origin': self.BASE_URL,
3132
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
3233
}
33-
self._session.get(self.BASE_URL)
34+
self._session.get(self.BASE_URL, timeout=self._timeout)
3435
response = self._session.post('{}/usermaster/authenticate/v1.json'.format(self.BASE_URL), data={
3536
'username': self._username,
3637
'password': self._password,
3738
'rememberMe': 'false'
38-
})
39+
}, timeout=self._timeout)
3940
self._session.headers.update({
4041
'cookie': response.headers['Set-Cookie']
4142
})
@@ -44,9 +45,10 @@ def login(self):
4445

4546
def query(self):
4647
today_str = datetime.today().strftime('%Y-%m-%d')
47-
response = self._session.get('{}/mercury_trade/strategy/{}/order'.format(self.BASE_URL, self._strategy), params={
48-
'date': today_str,
49-
})
48+
response = self._session.get('{}/mercury_trade/strategy/{}/order'.format(self.BASE_URL, self._strategy),
49+
params={
50+
'date': today_str,
51+
}, timeout=self._timeout)
5052
raw_transactions = response.json()
5153
transactions = []
5254
for raw_transaction in raw_transactions:

0 commit comments

Comments
 (0)