Skip to content

Commit e0d12a5

Browse files
committed
Support both python 2 and python 3
1 parent 5e121fc commit e0d12a5

File tree

7 files changed

+41
-13
lines changed

7 files changed

+41
-13
lines changed

examples/joinquant/simple_runner.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
# -*- coding: utf-8 -*-
22

3-
import ConfigParser
43
import logging
54
import os
65

6+
import six
7+
from six.moves import configparser
8+
9+
if six.PY2:
10+
ConfigParser = configparser.RawConfigParser
11+
else:
12+
ConfigParser = configparser.ConfigParser
13+
714
from shipane_sdk import Client
815
from shipane_sdk.joinquant.client import JoinQuantClient
916
from shipane_sdk.joinquant.runner import JoinQuantRunner
@@ -13,7 +20,7 @@
1320

1421
dir_path = os.path.dirname(os.path.realpath(__file__))
1522

16-
config = ConfigParser.RawConfigParser()
23+
config = ConfigParser()
1724
config.read('{}/config/config.ini'.format(dir_path))
1825

1926
shipane_client = Client(host=config.get('ShiPanE', 'host'),

shipane_sdk/client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# -*- coding: utf-8 -*-
22

33
import copy
4-
import urllib
54

65
import requests
6+
from six.moves.urllib.parse import urlencode
77

88

99
class Client(object):
@@ -104,7 +104,7 @@ def __create_url(self, resource, resource_id=None, **params):
104104
else:
105105
path = '/{}/{}'.format(resource, resource_id)
106106

107-
return '{}{}?{}'.format(self.__create_base_url(), path, urllib.urlencode(all_params))
107+
return '{}{}?{}'.format(self.__create_base_url(), path, urlencode(all_params))
108108

109109
def __create_base_url(self):
110110
return 'http://' + self._host + ':' + str(self._port)

shipane_sdk/joinquant/executor.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def execute(self, order):
5252
self._order_id_map[order.order_id] = response.json()['id'];
5353

5454
return response
55-
except Exception, e:
55+
except Exception as e:
5656
self._log.error("[实盘易] 下单异常:" + str(e))
5757

5858
def cancel(self, order):
@@ -66,5 +66,5 @@ def cancel(self, order):
6666
return self._client.cancel(self._order_id_map[order_id])
6767
else:
6868
self._log.warn('[实盘易] 未找到对应的委托编号')
69-
except Exception, e:
69+
except Exception as e:
7070
self._log.error("[实盘易] 撤单异常:" + str(e))

shipane_sdk/joinquant/runner.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def run(self):
5151
self._log.info(u'实盘易回复:\nstatus_code: %d\ntext: %s', response.status_code, response.text)
5252
else:
5353
self._log.error('实盘易未回复')
54-
except Exception, e:
54+
except Exception as e:
5555
self._log.error("跟单异常:" + str(e))
5656

5757
self._log.info("********** 结束跟单 **********\n")

tests/shipane_sdk/joinquant/test_client.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,22 @@
11
# -*- coding: utf-8 -*-
22

3-
import ConfigParser
43
import os
54
import unittest
65

6+
import six
7+
from six.moves import configparser
8+
9+
if six.PY2:
10+
ConfigParser = configparser.RawConfigParser
11+
else:
12+
ConfigParser = configparser.ConfigParser
13+
714
from shipane_sdk.joinquant.client import JoinQuantClient
815

916

1017
class JoinQuantClientTest(unittest.TestCase):
1118
def setUp(self):
12-
config = ConfigParser.RawConfigParser()
19+
config = ConfigParser()
1320
dir_path = os.path.dirname(os.path.realpath(__file__))
1421
config.read('{}/../../config/config.ini'.format(dir_path))
1522
self._jqClient = JoinQuantClient(username=config.get('JoinQuant', 'username'),

tests/shipane_sdk/joinquant/test_executor.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,27 @@
11
# -*- coding: utf-8 -*-
22

3-
import ConfigParser
43
import collections
54
import inspect
65
import logging
76
import os
87
import unittest
98

9+
import six
10+
from six.moves import configparser
11+
12+
if six.PY2:
13+
ConfigParser = configparser.RawConfigParser
14+
else:
15+
ConfigParser = configparser.ConfigParser
16+
1017
from shipane_sdk import JoinQuantExecutor
1118

1219

1320
class JoinQuantExecutorTest(unittest.TestCase):
1421
def setUp(self):
1522
logging.basicConfig(level=logging.INFO)
1623

17-
config = ConfigParser.RawConfigParser()
24+
config = ConfigParser()
1825
dir_path = os.path.dirname(os.path.realpath(__file__))
1926
config.read('{}/../../config/config.ini'.format(dir_path))
2027
self.Order = collections.namedtuple('Order', ['is_buy', 'security', 'price', 'amount'])

tests/shipane_sdk/test_client.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,23 @@
11
# -*- coding: utf-8 -*-
22

3-
import ConfigParser
43
import inspect
54
import os
65
import unittest
76

7+
import six
8+
from six.moves import configparser
9+
10+
if six.PY2:
11+
ConfigParser = configparser.RawConfigParser
12+
else:
13+
ConfigParser = configparser.ConfigParser
14+
815
from shipane_sdk import Client
916

1017

1118
class ClientTest(unittest.TestCase):
1219
def setUp(self):
13-
config = ConfigParser.RawConfigParser()
20+
config = ConfigParser()
1421
dir_path = os.path.dirname(os.path.realpath(__file__))
1522
config.read('{}/../config/config.ini'.format(dir_path))
1623
self.client = Client(host=config.get('ShiPanE', 'host'))

0 commit comments

Comments
 (0)