可转债PYTHON

QQ截图20180405173212.png

通过您可转债的代码:
#setting文件

import os
import MySQLdb
from sqlalchemy import create_engine
MYSQL_USER = "root"
MYSQL_PASSWORD = 1234
MYSQL_HOST ="127.0.0.1"
MYSQL_PORT =3306

def get_engine(db):
    engine = create_engine('mysql+pymysql://{}:{}@{}:{}/{}?charset=utf8'.format(MYSQL_USER, MYSQL_PASSWORD, MYSQL_HOST, MYSQL_PORT, db))
    return engine


#-*-coding=utf-8
'''
可转债
pip install pymysql
'''
import tushare as ts
from setting import get_engine
engine = get_engine('new_schema')
import pandas as pd
import datetime
class ConvertBond():

    def __init__(self):
        self.conn=ts.get_apis()
        self.allBonds=ts.new_cbonds(pause=2)
        self.onSellBond=self.allBonds.dropna(subset=['marketprice'])
        self.today=datetime.datetime.now().strftime('%Y-%m-%d %H:%M')

    def stockPrice(self,code):
        stock_df = ts.get_realtime_quotes(code)
        price = float(stock_df['price'].values[0])
        return price

    def dataframe(self):
        price_list=
        for code in self.onSellBond['scode']:
            price_list.append(self.stockPrice(code))
        self.onSellBond['stock_price']=price_list
        self.onSellBond['ratio'] = (
self.onSellBond['marketprice']
/(self.onSellBond['stock_price'] / self.onSellBond['convprice'])-1)*100
        self.onSellBond['Updated']=self.today
        self.onSellBond.to_sql('tb_bond',engine,if_exists='append')

    def closed(self):
        ts.close_apis(self.conn)

def main():
    bond=ConvertBond()
    bond.dataframe()
    bond.closed()
if __name__=='__main__':
    main()



运行后很久都结束不了,而且也没有获取数据成功。
QQ截图20180405173602.png

 
这是什么原因,哪里错了吗?
已邀请:

李魔佛 - 左手的厨子

赞同来自:

代码可以格式化一下? 不好判断

要回复问题请先登录注册