def jqdownloadMinuteBarBySymbol(symbol, startDate, endDate): """下载某一合约的分钟线数据""" start = time() cl = dbMinute[symbol] cl.ensure_index([('datetime', ASCENDING)], unique=True) # 添加索引 df = jq.get_price(setting[symbol], start_date=startDate, end_date=endDate, frequency='1m', fields=FIELDS, skip_paused=True) for ix, row in df.iterrows(): bar = generateVtBar(row, symbol) d = bar.__dict__ flt = {'datetime': bar.datetime} cl.replace_one(flt, d, True) end = time() cost = (end - start) * 1000 print(u'合约%s的分钟K线数据下载完成%s - %s,耗时%s毫秒' % (symbol, df.index[0], df.index[-1], cost)) print(jq.get_query_count())
def download_minute_bar(name, start_date, end_date, ac): """下载某一合约的分钟线数据""" print(f"开始下载合约数据{name}") symbol_info = ac[ac.name == name] symbol = name vt_symbol = symbol_info.index[0] exchange = ex_jq2vn.get(vt_symbol[-4:]) print(f"{symbol, exchange}") symbol_info = ac[ac.name == name] vt_symbol = symbol_info.index[0] start = time() df = jq.get_price( vt_symbol, start_date=start_date, end_date=end_date, frequency="1m", fields=FIELDS, ) bars = [] for ix, row in df.iterrows(): bar = generateVtBar(row, symbol, exchange) bars.append(bar) database_manager.save_bar_data(bars) end = time() cost = (end - start) * 1000 print("合约%s的分钟K线数据下载完成%s - %s,耗时%s毫秒" % (symbol, df.index[0], df.index[-1], cost)) print(jq.get_query_count())
def downloadAllMinuteBar(self, days=0): """下载所有配置中的合约的分钟线数据""" if days == 0: days = self.setting["days"] startDt = datetime.today() - days * timedelta(1) enddt = datetime.today() print('-' * 50) print(u'开始下载合约分钟线数据') print('-' * 50) if 'Bar.Min' in self.setting: l = self.setting["Bar.Min"] for VNSymbol in l: dt0 = time.process_time() symbol = VNSymbol.split(".")[0] exchange = Exchange(VNSymbol.split(".")[1]) self.query_history(symbol, exchange, startDt, enddt, interval='1m') cost = (time.process_time() - dt0) print(u'合约%s的分钟K线数据下载完成%s - %s,耗时%s秒' % (symbol, startDt, enddt, cost)) print(jq.get_query_count()) print('-' * 50) print u'合约分钟线数据下载完成' print('-' * 50) return None
def login(): print("login JQDATA servering") account = "15210089516" password = "******" jq.auth(account, password) print("login successed!") remain_query = jq.get_query_count() print("remain query times for jqdata: ", remain_query)
def get_data(): import jqdatasdk jqdatasdk.auth('18374980021', 'asdfasdf1') codes = ['000905.XSHG', '000001.XSHE', '600001.XSHG', '600547.XSHG'] df = jqdatasdk.get_price(codes, start_date='2020-01-01', end_date='2020-03-01') df.to_csv('sample_data.csv') print(jqdatasdk.get_query_count())
def check_api_quote(): quote = jq.get_query_count() spare = quote["spare"] if spare < 500: #流量不足,为了避免API抛错,我们等到明天 today = datetime.now() this_day = today.day while datetime.now().day == this_day: time.sleep(30) # 30 seconds print "."
def initJq(self, ): print("login JQDATA servering") account = "15210089516" #"15210089516" password = "******" account = "13132110856" # "18620156503" password = "******" #"3DKkypzN6uPj" account = "18620156503" password = "******" jq.auth(account, password) print("login successed!") remain_query = jq.get_query_count() print("remain query times for jqdata: ", remain_query)
def login(): print("login JQDATA servering") jq.auth(account, password) print("login successed!") remain_query = jq.get_query_count() print("remain query times for jqdata: ", remain_query)
def remainder(): login() count = jq.get_query_count() print(count)
pass if __name__ == '__main__': #password = pd.DataFrame({'host':['jqdatasdk'], # 'username':['13981813381'], # 'password':['813381']}, columns=['host', # 'username', # 'password']) # 用上面的代码保存密码到用户配置 .GolemQ 目录下面 password = load_settings('password.hdf5') auth(password.username[0], password.password[0]) #ID是申请时所填写的手机号;Password为聚宽官网登录密码,新申请用户默认为手机号后6位 asset = u'000001.XSHE' is_auth = is_auth() # 查询当日剩余可调用条数 print(get_query_count()) print(is_auth) codelist = ['000876'] code = codelist[0] # 创建数据下载目录 index_path = mkdirs(os.path.join(mkdirs('datastore'), 'kline', 'index')) print(index_path) for year in range(2005, 2017): start_date = '{}-01-01' end_date = '{}-01-02' for code in indexlist: #his = jqapi.get_price(asset, start_date, end_date, frequency='60m') data_day = QA.QA_fetch_stock_min_adv(codelist,
# -*- coding: utf-8 -*- """ Created on Tue Jun 2 13:52:25 2020 @author: lenovo """ import pandas as pd import numpy as np from factor_analyzer import data, analyze, prepare, utils from datetime import datetime import statsmodels.api as sm import jqdatasdk as jd jd.auth('17854120489', 'shafajueduan28') print(jd.get_query_count()) #%% ''' 获取数据,并处理一下 ''' factor_data = pd.read_csv('D:\\spyder_code\\jqfactor_analyzer01\\华泰单因子测试之估值类因子\\处理后因子pe.csv',\ index_col='Unnamed: 0') factor_data.index = pd.to_datetime(factor_data.index) #减少数据量 factor_data = factor_data.loc[datetime(2018, 1, 1):, ] #%% api = data.DataApi(fq='pre', industry='jq_l1', weight_method='ln_mktcap') api.auth('17854120489', 'shafajueduan28') pe_factor = analyze.FactorAnalyzer(factor_data,prices=api.get_prices,groupby=api.get_groupby,\ weights=api.get_weights,bins=5,periods=(1,10,20))
listDate = jq.get_trade_days(start_date=sdate, end_date=edate, count=None) #filePath= path.join(cfg.jqDataPath, 'trade_days.csv') listDate = pd.Series(listDate) #pd.Series(listDate).to_csv(filePath,header= 0, index= 0) listDate = listDate.map(lambda x: x.strftime("%Y%m%d")) return list(listDate) def stimeToStr(stime): return stime.strftime('%Y-%m-%d %H:%M:%S') if __name__ == '__main__': t0 = ti.time() jq.auth(cfg.jqUser, cfg.jqPwd) jq.get_query_count() localSQL = cfg.MSSQL(cfg.host, cfg.user, cfg.pwd, cfg.lcdb) localSQL.Connect() if not localSQL.isConnect: print(localSQL.host + ' not connect') else: #sdate= '20200806' #jqID= listJQID[0] edate = cfg.getStrToday() listDate = syncListTradeDay('20190101', edate) for sdate in listDate: print('deal date: ' + sdate) for jqID in listJQID: if len(localSQL.getDateData(jqID, int(sdate))) < 10: #if len(localSQL.getDateData(jqID, int(sdate)))== 0:
# -*- coding: utf-8 -*- """ Created on Tue May 5 20:05:55 2020 @author: 17854 """ import jqdatasdk as jd jd.auth('17854120489','shafajueduan28') count=jd.get_query_count() print(count) import pandas as pd import matplotlib.pyplot as plt ''' 申万指数在2014-02-21有一次大改,删除了6个一级行业,并增加了11个一级行业。故: date < 2014-02-21 申万一级行业有23个 date = 2014-02-21 申万一级行业有34个 date > 2014-02-21 申万一级行业有28个 #date='2014-02-20',23个 code1 = jd.get_industries(name='sw_l1', date='2013-01-20') #date='2014-02-21'有34个 code2 = jd.get_industries(name='sw_l1', date='2014-02-21') #date='2014-02-22'有28个 code3 = jd.get_industries(name='sw_l1', date='2015-02-22') ''' def get_sw1_valuation(start_date=None, end_date=None):
def remain_count(self): count = jq.get_query_count() return count
def jq_get_query_count(): if is_auth(): count = get_query_count() return count['spare'] return 0
import jqdatasdk as jq import datetime from pymongo import MongoClient jq.auth('15804268950','3834259hanK') print(jq.get_query_count()) """ **Table: share_flo** --- ##### stock_a_db['share_flo'].find_one() ```python {'_id': ObjectId('5d5f4f3492600ddf9285d516'), 'index': '000001.XSHE', 'share_flow': 8258245083.0, # 流通股(单位 股) 'day': '2019-08-01'} ``` """ client = MongoClient('127.0.0.1', 27017) stock_a_db = client["stock_a"] def get_real_share(stock): # 10大流通股东加和 #print(stock._name) merge_df = jq.finance.run_query(jq.query(jq.finance.STK_SHAREHOLDER_FLOATING_TOP10).filter( jq.finance.STK_SHAREHOLDER_FLOATING_TOP10.code == stock._name).limit(10))
def __local_run(): return jq.get_query_count()
def _get_count(self): self._count = jq.get_query_count() if jq.is_auth() else None
password = load_settings('jqdatasdk_pwd.pickle') else: password = input_settings( pattern=password, filename='jqdatasdk_pwd.pickle', ) save_settings('jqdatasdk_pwd.pickle', password) #ID是申请时所填写的手机号;Password为聚宽官网登录密码,新申请用户默认为手机号后6位 auth(password.username[0], password.password[0]) asset = u'000001.XSHE' is_auth = is_auth() # 查询当日剩余可调用条数 print(get_query_count()) print(is_auth) # 创建数据下载目录 frequence = '60min' stock_path = mkdirs( os.path.join(mkdirs('datastore'), 'kline', 'stock', frequence)) print(stock_path) frequence = '60min' blockname = [ 'MSCI中国', 'MSCI成份', 'MSCI概念', '三网融合', '上证180', '上证380', '沪深300', '上证380', '深证300', '上证50', '上证电信', '电信等权', '上证100', '上证150', '沪深300', '中证100', '中证500', '全指消费', '中小板指', '创业板指', '综企指数', '1000可选', '国证食品', '深证可选', '深证消费', '深成消费', '中证酒', '中证白酒', '行业龙头', '白酒', '证券', '消费100', '消费电子', '消费金融', '富时A50', '银行', '中小银行', '证券', '军工', '白酒', '啤酒', '医疗器械',
def valid(self): # 如果该账号没有可用数据条数了就返回False if jq.get_query_count()['spare'] > 0: return True else: return False
# In[1]: """ 使用JQData调取金融数据 """ from datetime import datetime import jqdatasdk as jq jq.auth('username', 'password') # In[2]: count=jq.get_query_count() print("当日可调用数据总条数为:",count['total']) print("当日剩余可调用条数为:",count['spare']) # In[3]: # 获取平安银行股票数据,XSHE 深圳交易所 XSHG 上海交易所 jq.get_price("000001.XSHE", start_date="2021-01-01", end_date="2021-03-05") # In[4]: # valuation是内置市值数据对象(这里表示查询valuation下所有的属性)
def login(): # jqdatasdk.logout() jqdatasdk.auth(jq_config.account, jq_config.password) print(jqdatasdk.get_query_count())
import jqdatasdk as jq account = "18620156503" password = "******" jq.auth(account, password) print("login successed!") remain_query = jq.get_query_count() print("remain query times for jqdata: ", remain_query) def p_perday_var(start_date, end_date): tradeable_days = get_trade_days(start_date=start_date, end_date=end_date) for trade_day in tradeable_days: stock_code_list = jq.get_all_securities(date=trade_day) result = jq.get_price(list(stock_code_list), start_date=trade_day, end_date=trade_day, frequency='daily', fields=['close'], skip_paused=False, fq='pre', count=None, panel=True, fill_paused=True)
def login(): # jqdatasdk.logout() jqdatasdk.auth(Config.jq_account, Config.jq_password) # print(jqdatasdk.__version__) print(jqdatasdk.get_query_count())
return msg if util.isFutureTradingTime(nowTimeString=nowTimeString ) is False or util.isFutureCommonTradingTime( security=security, nowTimeString=nowTimeString) is False: return msg msg = loop(security=security, frequency=frequency, nowTimeString=nowTimeString, msg=msg) return msg removeTreses() jqdatasdk.auth('13824472562', '472562') print(jqdatasdk.get_query_count()) for nowTimeString in timeArr: msg = action(msg=msg, nowTimeString=nowTimeString) # # class MyStrategy(CtaTemplate): # author = 'nobody' # # fast_window = 10 # slow_window = 20 # # fast_ma0 = 0.0 # fast_ma1 = 0.0 # # slow_ma0 = 0.0 # slow_ma1 = 0.0
from pyecharts.globals import CurrentConfig, NotebookType CurrentConfig.NOTEBOOK_TYPE = NotebookType.JUPYTER_LAB # ID是申请时所填写的手机号;Password为聚宽官网登录密码,新申请用户默认为手机号后6位 jqdatasdk.auth('18605712083', 'sbbuzhidaomima') # # In[] # all_securities = jqdatasdk.get_all_securities(['stock', 'fund', 'index', 'futures', 'options', 'etf', 'lof', # 'fja', 'fjb', 'open_fund', 'bond_fund', 'stock_fund', 'QDII_fund', 'money_market_fund', 'mixture_fund']) # In[] a = pd.read_csv("./data/csv/all_securities.csv") jqdatasdk.get_query_count() # In[] all_index = a[a["type"] == "index"] for security in all_index.iloc[:, 0]: if os.path.exists( "./data/csv/daily/{security}.csv".format(security=security)): continue security_bar = jqdatasdk.get_bars( "000016.XSHG", 3650, unit='1d', fields=['date', 'open', 'close', 'high', 'low', 'volume', 'money'],
'avg': 0 } for x in range(0, num): if (dictValue['high'] < values['high'][x]): dictValue['high'] = values['high'][x] if (dictValue['low'] > values['low'][x]): dictValue['low'] = values['low'][x] dictValue['volume'] += values['volume'][x] dictValue['money'] += values['money'][x] dictValue['avg'] = dictValue['money'] / dictValue['volume'] return dictValue #缓存全局对象 gol._Set_Value('quoteSource_API_JqData', Source_JQData_API()) #实例 行情对象 myDebug.Debug(jqdatasdk.get_query_count()) #打印当日可请求条数 #主启动程序 if __name__ == "__main__": # 提取标的信息 pSource = gol._Get_Value('quoteSource_API_JqData', None) print(pSource.getOptInfos()) print(pSource.getSecurities()) print(pSource.getSecurities('index')) values = pSource.getPrice(security="600332.XSHG", frequency='1m', start_date='2020-02-05 09:00:00', end_date='2020-02-05 15:00:00') lstPrices = [] strList = ""
import pandas as pd import numpy as np import jqdatasdk as jq from jqdatasdk import auth, get_query_count, get_price, opt, query, get_fundamentals, finance, get_trade_days, \ valuation, get_security_info, get_index_stocks, get_bars, bond from tqdm import tqdm from datetime import datetime, time, timedelta import matplotlib.pyplot as plt import os from sklearn.preprocessing import StandardScaler from sklearn.linear_model import LinearRegression from basic_funcs.basic_function import * import talib auth('15951961478', '961478') get_query_count() import warnings warnings.filterwarnings('ignore') def get_short_ma_order(close, n1, n2, n3): ma1 = close.rolling(n1).mean() ma2 = close.rolling(n2).mean() ma3 = close.rolling(n3).mean() return (ma1 < ma2) & (ma2 < ma3) & (ma1 < ma3) dateparse = lambda x: pd.datetime.strptime(x, '%Y-%m-%d') plt.rcParams['font.sans-serif'] = ['Songti SC'] plt.rcParams['axes.unicode_minus'] = False # 用来正常显示负号
def connect_jq(id, pw): jq.auth(id, pw) print(jq.get_query_count())