聚宽mysql_财经数据(2)-聚宽数据

该博客展示了如何使用JoinQuant接口获取股票列表、竞价数据和龙虎榜数据,并将这些数据存储到MySQL数据库中。主要函数包括获取股票列表的`allStock()`,获取竞价数据的`jjQuant()`,以及获取龙虎榜数据的`topInst()`。
摘要由CSDN通过智能技术生成

#-*- coding: utf-8 -*-

importpandas as pdfrom jqdatasdk import *

importtimefrom sqlalchemy importcreate_engineimportdatetime#====================JoinQuant股票列表======================================================================================================================

defallStock():print("----------------------------------")print("开始从JoinQuant接口获取股票列表数据")

stock_list= list(get_all_securities(types=['stock']).index)print(stock_list)returnstock_list#====================JoinQuant竞价数据======================================================================================================================

def jjQuant(stock, engine, *args):print("----------------------------------")print("开始从JoinQuant接口获取股票竞价数据")#创建空DataFrame

bids =pd.DataFrame()for stk instock_list:

bidding= get_call_auction(security=stk, start_date=start, end_date=end, fields=['time', 'current', 'money'])

bids=bids.append(bidding)

bids['code'] = bids['code'].apply(lambda x: x[:6])

bids['money'] = bids['money'].apply(lambda x: round(x / 10000, 2))

bids.to_sql('call_auction', engine, if_exists='append', index=False)print(bids)print("本次存储JoinQuant股票竞价数据%s条" %bids.shape[0])#====================JoinQuant龙虎榜数据======================================================================================================================

def topInst(stcok, engine, *args):print("----------------------------------")print("开始从JoinQuant接口获取龙虎榜数据")

top= get_billboard_list(stock_list=stcok, start_date=start, end_date=end)

top['code'] = top['code'].map(lambda x: x[:6])

top['buy_value'] = top['buy_value'].map(lambda x: round(x / 10000, 2))

top['sell_value'] = top['sell_value'].map(lambda x: round(x / 10000, 2))

top['net_value'] = top['net_value'].map(lambda x: round(x / 10000, 2))

top= top.drop(['abnormal_code', 'abnormal_name', 'buy_rate', 'sell_rate', 'amount'], axis=1)

top.to_sql('quant_top_inst', engine, if_exists='append', index=False)print(top)print("本次存储JoinQuant龙虎榜数据%s条" %top.shape[0])print("--------------------------------------------")#====================主函数====================================================================================================================================

if __name__ == '__main__':print("JoinQuant接口程序开始执行")print("--------------------------------------------")

begin=time.time()#创建Pandas读写数据库引擎

engine = create_engine('mysql://root:123456@127.0.0.1/quant?charset=utf8')#获取起始及截止日期,如果获取当天数据,则start=end即可

start = input("时间格式如:1949-10-01,请输入起始日期:")

end= input("时间格式如:1949-10-01,请输入截止日期:")#ID是申请时所填写的手机号;Password为聚宽官网登录密码,新申请用户默认为手机号后6位

auth('18829345691', '345691')#查询是否登录/连接成功

is_auth =is_auth()

stock_list= allStock() #获取JoinQuant股票列表

jjQuant(stock_list, engine, start, end) #获取JoinQuant竞价数据

topInst(stock_list, engine, start, end) #获取JoinQuant龙虎榜数据

ed=time.time()

count=get_query_count()print('JoinQuant接口程序共执行%0.2f秒.' % ((ed -begin)))print("JoinQuant当天剩余可请求数据情况为:"%count)print("JoinQuant接口程序执行完成")

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值