def setUp(self):
     logging.basicConfig(level=logging.DEBUG)
     config = ConfigParser()
     dir_path = os.path.dirname(os.path.realpath(__file__))
     config.read('{}/../config/config.ini'.format(dir_path))
     self.client = Client(logging.getLogger(),
                          host=config.get('ShiPanE', 'host'))
class ClientTest(unittest.TestCase):
    def setUp(self):
        logging.basicConfig(level=logging.DEBUG)
        config = ConfigParser()
        dir_path = os.path.dirname(os.path.realpath(__file__))
        config.read('{}/../config/config.ini'.format(dir_path))
        self.client = Client(logging.getLogger(),
                             host=config.get('ShiPanE', 'host'),
                             key=config.get('ShiPanE', 'key'))
        self.client.start_clients()

    def test_get_account(self):
        try:
            self.client.get_account()
        except HTTPError as e:
            self.fail()

    def test_get_positions(self):
        try:
            data = self.client.get_positions()
            sub_accounts = data['sub_accounts']
            self.assertGreater(sub_accounts['总资产']['人民币'], 0)
            positions = data['positions']
            self.assertIsNotNone(positions['证券代码'][0])
        except HTTPError as e:
            self.fail()

    def test_buy_stock(self):
        try:
            order = self.client.buy(symbol='000001', price=8.11, amount=100)
            self.assertIsNotNone(order['id'])
        except HTTPError as e:
            result = e.response.json()
            self.assertIsNotNone(result['message'])

    def test_sell_stock(self):
        try:
            order = self.client.sell(symbol='000001', price=9.51, amount=100)
            self.assertIsNotNone(order['id'])
        except HTTPError as e:
            result = e.response.json()
            self.assertIsNotNone(result['message'])

    def test_cancel_all(self):
        try:
            self.client.cancel_all()
        except HTTPError as e:
            self.fail()

    def test_query(self):
        try:
            df = self.client.query(None, '查询>资金股份')
            self.assertIsNotNone(df['证券代码'][0])
        except HTTPError as e:
            self.fail()

    def test_purchase_new_stocks(self):
        pass
示例#3
0
    def __init__(self):
        logging.basicConfig(
            level=logging.INFO,
            format='%(asctime)-15s %(levelname)-6s %(message)s')
        self._logger = logging.getLogger()

        config_path = os.path.join(os.path.expanduser('~'), '.shipane_sdk',
                                   'config', 'scheduler.ini')
        self._logger.info('Config path: %s', config_path)
        self._config = ConfigParser()
        self._config.readfp(codecs.open(config_path, "r", "utf_8_sig"))

        self._client = Client(self._logger,
                              host=self._config.get('ShiPanE', 'host'),
                              port=self._config.get('ShiPanE', 'port'),
                              key=self._config.get('ShiPanE', 'key'))
        self._jq_client = JoinQuantClient(
            username=self._config.get('JoinQuant', 'username'),
            password=self._config.get('JoinQuant', 'password'),
            backtest_id=self._config.get('JoinQuant', 'backtest_id'))
        self._rq_client = RiceQuantClient(
            username=self._config.get('RiceQuant', 'username'),
            password=self._config.get('RiceQuant', 'password'),
            run_id=self._config.get('RiceQuant', 'run_id'))

        self._new_stock_purchase_job = NewStockPurchaseJob(
            self._config, self._client,
            self.__filter_client_aliases('NewStocks'))
        self._jq_following_job = self.__create_following_job('JoinQuant')
        self._rq_following_job = self.__create_following_job('RiceQuant')
示例#4
0
 def setUpClass(cls):
     logging.basicConfig(level=logging.DEBUG)
     config = ConfigParser()
     dir_path = os.path.dirname(os.path.realpath(__file__))
     config.read('{}/../config/config.ini'.format(dir_path))
     cls.client = Client(logging.getLogger(), **dict(config.items('ShiPanE')))
     cls.client_param = config.get('ShiPanE', 'client')
class ClientManagementTest(unittest.TestCase):
    def setUp(self):
        logging.basicConfig(level=logging.DEBUG)
        config = ConfigParser()
        dir_path = os.path.dirname(os.path.realpath(__file__))
        config.read('{}/../config/config.ini'.format(dir_path))
        self.client = Client(logging.getLogger(), host=config.get('ShiPanE', 'host'), key=config.get('ShiPanE', 'key'))

    def test_start_clients(self):
        try:
            self.client.start_clients()
        except HTTPError as e:
            self.fail()

    def test_shutdown_clients(self):
        try:
            self.client.shutdown_clients()
        except HTTPError as e:
            self.fail()
示例#6
0
    def __init__(self):
        self._logger = logging.getLogger()

        config_path = os.path.join(os.path.expanduser('~'), '.shipane_sdk', 'config', 'scheduler.ini')
        self._logger.info('Config path: %s', config_path)
        self._config = configparser.RawConfigParser()
        self._config.readfp(codecs.open(config_path, encoding="utf_8_sig"), )

        self._scheduler = BackgroundScheduler()
        self._client = Client(self._logger, **dict(self._config.items('ShiPanE')))
    def __init__(self):
        logging.basicConfig(level=logging.INFO, format='%(asctime)-15s %(levelname)-6s %(message)s')
        self._logger = logging.getLogger()

        config_path = os.path.join(os.path.expanduser('~'), '.shipane_sdk', 'config', 'scheduler.ini')
        self._logger.info('Config path: %s', config_path)
        self._config = ConfigParser()
        self._config.readfp(codecs.open(config_path, encoding="utf_8_sig"))

        self._scheduler = BackgroundScheduler()
        self._client = Client(self._logger, **dict(self._config.items('ShiPanE')))
示例#8
0
    def __init__(self):
        self._logger = logging.getLogger()

        config_path = os.path.join(BASE_PATH, 'conf', 'scheduler.ini')
        self._logger.info('Config path: %s', config_path)
        self._config = configparser.RawConfigParser()
        self._config.readfp(codecs.open(config_path, encoding="utf_8_sig"), )

        self._scheduler = BackgroundScheduler()
        self._client = Client(self._logger,
                              **dict(self._config.items('ShiPanE')))

        self._db_path = os.path.join(BASE_PATH, 'db', 'Trader.db')
示例#9
0
class ClientTest(unittest.TestCase):
    def setUp(self):
        config = ConfigParser()
        dir_path = os.path.dirname(os.path.realpath(__file__))
        config.read('{}/../config/config.ini'.format(dir_path))
        self.client = Client(host=config.get('ShiPanE', 'host'))

    def test_get_account(self):
        response = self.client.get_account()
        print(inspect.stack()[0][3] + ' - ' + response.text)
        self.assertEqual(response.status_code, 200)

    def test_get_positions(self):
        response = self.client.get_positions()
        print(inspect.stack()[0][3] + ' - ' + response.text)
        self.assertEqual(response.status_code, 200)

    def test_buy_stock(self):
        response = self.client.buy(symbol='000001', price=8.11, amount=100)
        print(inspect.stack()[0][3] + ' - ' + response.text)
        json = response.json()
        if response.status_code == 200:
            self.assertTrue(json['id'])
        elif response.status_code == 400:
            self.assertTrue(json['message'])
        else:
            self.fail()

    def test_sell_stock(self):
        response = self.client.sell(symbol='000001', price=9.51, amount=100)
        print(inspect.stack()[0][3] + ' - ' + response.text)
        json = response.json()
        if response.status_code == 200:
            self.assertTrue(json['id'])
        elif response.status_code == 400:
            self.assertTrue(json['message'])
        else:
            self.fail()

    def test_cancel_all(self):
        response = self.client.cancel_all()
        print(inspect.stack()[0][3] + ' - ' + response.text)
        self.assertEqual(response.status_code, 200)

    def test_query(self):
        response = self.client.query(None, '查询>资金股份')
        print(inspect.stack()[0][3] + ' - ' + response.text)
        self.assertEqual(response.status_code, 200)
示例#10
0
 def setUp(self):
     config = ConfigParser()
     dir_path = os.path.dirname(os.path.realpath(__file__))
     config.read('{}/../config/config.ini'.format(dir_path))
     self.client = Client(host=config.get('ShiPanE', 'host'))
示例#11
0
if six.PY2:
    ConfigParser = configparser.RawConfigParser
else:
    ConfigParser = configparser.ConfigParser

from shipane_sdk import Client
from shipane_sdk.joinquant.client import JoinQuantClient
from shipane_sdk.joinquant.runner import JoinQuantRunner

if __name__ == "__main__":
    logging.basicConfig(level=logging.INFO,
                        format='%(asctime)-15s %(levelname)-6s %(message)s')

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

    config = ConfigParser()
    config.read('{}/config/config.ini'.format(dir_path))

    shipane_client = Client(host=config.get('ShiPanE', 'host'),
                            port=config.get('ShiPanE', 'port'),
                            key=config.get('ShiPanE', 'key'))
    jq_client = JoinQuantClient(username=config.get('JoinQuant', 'username'),
                                password=config.get('JoinQuant', 'password'),
                                backtest_id=config.get('JoinQuant',
                                                       'backtestId'))
    jq_client.login()
    runner = JoinQuantRunner(shipane_client, jq_client, interval=15)

    runner.run()