|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | +import json |
| 3 | +import logging |
| 4 | +from datetime import datetime |
| 5 | + |
| 6 | +from shipane_sdk.stock import * |
| 7 | + |
| 8 | + |
| 9 | +class NewStockPurchaseJob(object): |
| 10 | + def __init__(self, config, client): |
| 11 | + self._log = logging.getLogger() |
| 12 | + self._config = config |
| 13 | + self._client = client |
| 14 | + |
| 15 | + def __call__(self): |
| 16 | + all_client_aliases = dict(self._config.items('ClientAliases')) |
| 17 | + client_aliases = self._config.get('NewStocks', 'clients').split(',') |
| 18 | + today = datetime.strftime(datetime.today(), '%Y-%m-%d') |
| 19 | + df = StockUtils.new_stocks() |
| 20 | + df = df[(df.ipo_date == today)] |
| 21 | + for client_alias in client_aliases: |
| 22 | + client = all_client_aliases[client_alias.strip()] |
| 23 | + self._log.info(u'客户端[%s(%s)]开始新股申购', client_alias, client) |
| 24 | + for index, row in df.iterrows(): |
| 25 | + try: |
| 26 | + order = { |
| 27 | + 'symbol': row['code'], 'type': 'LIMIT', 'price': row['price'], 'amountProportion': 'ALL' |
| 28 | + } |
| 29 | + self._log.info(u'下单:%s', json.dumps(order)) |
| 30 | + response = self._client.buy(client, **order) |
| 31 | + if response is not None: |
| 32 | + self._log.info(u'[实盘易] 回复如下:\nstatus_code: %d\ntext: %s', |
| 33 | + response.status_code, response.text) |
| 34 | + else: |
| 35 | + self._log.error('[实盘易] 未回复') |
| 36 | + except Exception as e: |
| 37 | + self._log.exception('账户[%s(%s)]申购新股[%s(%s)]失败', client_alias, client, row['name'], row['code']) |
| 38 | + self._log.info(u'客户端[%s(%s)]结束新股申购', client_alias, client) |
0 commit comments