In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
Xiaobian to share with you how to use Joinquant data source to add futures market data for vnpy, I hope you have something to gain after reading this article, let's discuss it together!
Use Joinquant data source JQData to add futures quotes data for vnpy
Code on two files, a config.json mainly put login user name and futures varieties name correspondence table, because futures varieties in the poly wide name is not the same.
JQDataload.py is a minute-level download method, and a futures variety name comparison list from the poly wide download.
Jukuan provides 1 million data downloads a day, so there will be a countdown at the end of each download. In fact, the code is very simple, the only difficulty is that vnpy is the starting point of 9:00 every day, and the convergence is the starting point of 9:01 every day; vnpy has been solved before copying.
structured as follows
-JDDataService
|--config.json
|--JQDataload.py
In fact, it is very simple to use, the steps are as follows:
1. Run pip install jqdatasdk to install sdk for jqdata
2. Register trial data on Jukuan platform, link: https://www.joinquant.com/default/index/sdk
3. Maintain logins and passwords in config.json.
4. Run JQDataload.py
config.json code is as follows:
{ "Username":"", "Password": "Widening Application", "rb1910":"RB1910.XSGE", "zn1807": "ZN1807.XSGE", "rb0000": "RB9999.XSGE"}
The JQDataload.py code is as follows:
# encoding: UTF-8 from __future__ import print_functionimport sysimport jsonfrom datetime import datetime,date,timedeltafrom time import time, sleep from pymongo import MongoClient, ASCENDINGimport pandas as pd from vnpy.trader.vtObject import VtBarData, VtTickDatafrom vnpy.trader.app.ctaStrategy.ctaBase import (MINUTE_DB_NAME, DAILY_DB_NAME, TICK_DB_NAME) import jqdatasdk as jq #load config = open ('config.json')setting = json.load(config) mc = MongoClient() # Mongo Connect dbMinute = mc[MINUTE_DB_NAME] #Database # dbDaily = mc[DAILY_DB_NAME]# dbTick = mc[TICK_DB_NAME] USERNAME = setting <$'Username ']PASSWORD = setting <$'Password']jq.auth (USERNAME, PASSWORD) FIELDS = ['open', 'high', 'low', 'close', 'volume'] # ----------------------------------------------------------------------def generateVtBar(row, symbol): """Generate K Line""" bar = VtBarData() bar.symbol = symbol bar.exchange = "SHFE" bar.vtSymbol = bar.vtSymbol = '. '.join([bar.symbol, bar.exchange]) bar.open = row['open'] bar.high = row['high'] bar.low = row['low'] bar.close = row['close'] bar.volume = row['volume'] bardatetime = row.name bar.date = bardatetime.strftime("%Y%m%d") bar.time = bardatetime.strftime("%H%M%S") #Change bar time to 1 minute earlier hour = bar.time[0:2] minute = bar.time[2:4] sec = bar.time[4:6] if minute == "00": minute = "59" h = int(hour) if h == 0: h = 24 hour = str(h - 1).rjust(2, '0') else: minute = str(int(minute) - 1).rjust(2, '0') bar.time = hour + minute + sec bar.datetime = datetime.strptime(' '.join([bar.date, bar.time]), '%Y%m%d %H%M%S') return bar # ----------------------------------------------------------------------def jqdownloadMinuteBarBySymbol(symbol,startDate,endDate): """Download Minute Line Data for a Contract""" start = time() cl = dbMinute[symbol] cl.ensure_index([('datetime ', ASCENDING)], unique=True) #Add index 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'contract %s min K line data download completed %s - %s, time %s ms' % (symbol, df.index[0], df.index[-1], cost)) print(jq.get_query_count()) def jqdownloadMappingExcel(exportpath = "C:\Project\\"): getfuture = jq.get_all_securities(types=['futures'], date=None) # list: Types used to filter securities, list elements optional: 'stock',' fund','index',' futures','etf',' lof','fja',' fjb'. When types is empty, returns all stocks, excluding funds, indices and futures getfuture.to_excel( exportpath + "Mapping" + str(date.today()) + "futures.xls", index=True, header=True) # ----------------------------------------------------------------------def downloadAllMinuteBar(days=10): """Download Minute Line Data for Contracts in All Configurations""" print('-' * 50) print(u'Start downloading contract minute line data') print('-' * 50) startDt = datetime.today() - days * timedelta(1) startDate = startDt.strftime('%Y-%m-%d') #Add download task enddt = datetime.today() endDate = enddt.strftime('%Y-%m-%d %H:%M:%S') jqdownloadMinuteBarBySymbol('rb1910', startDate, endDate) print('-' * 50) print u'contract minute line data download complete' print('-' * 50) if __name__ == '__main__': # jqdownloadMappingExcel() #Download the main contract downloadAllMinuteBar(days=10) #Download individual varieties # jqdownloadMinuteBarBySymbol ('510050.XSHG', startDate,endDate) After reading this article, I believe you have a certain understanding of "how to use Joinquant data source to add futures market data for vnpy". If you want to know more about this knowledge, please pay attention to the industry information channel. Thank you for reading!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.