Futurize older examples/F*,J*,S*,T*

This commit is contained in:
cclauss 2018-04-16 09:48:46 +02:00
parent 50277d79a5
commit 9b3492d88a
12 changed files with 64 additions and 44 deletions

View File

@ -1,5 +1,6 @@
# encoding: UTF-8 # encoding: UTF-8
from __future__ import print_function
import sys import sys
import json import json
from datetime import datetime, timedelta from datetime import datetime, timedelta
@ -56,7 +57,7 @@ def downMinuteBarBySymbol(symbol):
code, data = quote.get_history_kline(symbol, start=startDate, ktype='K_1M') code, data = quote.get_history_kline(symbol, start=startDate, ktype='K_1M')
if code: if code:
print u'合约%s数据下载失败:%s' %(symbol, data) print(u'合约%s数据下载失败:%s' %(symbol, data))
return return
data = data.sort_index() data = data.sort_index()
@ -70,24 +71,24 @@ def downMinuteBarBySymbol(symbol):
end = time() end = time()
cost = (end - start) * 1000 cost = (end - start) * 1000
print u'合约%s数据下载完成%s - %s,耗时%s毫秒' %(symbol, data.iloc[0]['time_key'], print(u'合约%s数据下载完成%s - %s,耗时%s毫秒' %(symbol, data.iloc[0]['time_key'],
data.iloc[-1]['time_key'], cost) data.iloc[-1]['time_key'], cost))
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def downloadAllMinuteBar(): def downloadAllMinuteBar():
"""下载所有配置中的合约的分钟线数据""" """下载所有配置中的合约的分钟线数据"""
print '-' * 50 print('-' * 50)
print u'开始下载合约分钟线数据' print(u'开始下载合约分钟线数据')
print '-' * 50 print('-' * 50)
# 添加下载任务 # 添加下载任务
for symbol in SYMBOLS: for symbol in SYMBOLS:
downMinuteBarBySymbol(str(symbol)) downMinuteBarBySymbol(str(symbol))
print '-' * 50 print('-' * 50)
print u'合约分钟线数据下载完成' print(u'合约分钟线数据下载完成')
print '-' * 50 print('-' * 50)

View File

@ -3,6 +3,7 @@
""" """
定时服务可无人值守运行实现每日自动下载更新历史行情数据到数据库中 定时服务可无人值守运行实现每日自动下载更新历史行情数据到数据库中
""" """
from __future__ import print_function
import time import time
import datetime import datetime
@ -27,6 +28,6 @@ if __name__ == '__main__':
# 更新任务完成的日期 # 更新任务完成的日期
taskCompletedDate = t.date() taskCompletedDate = t.date()
else: else:
print u'当前时间%s,任务定时%s' %(t, taskTime) print(u'当前时间%s,任务定时%s' %(t, taskTime))
time.sleep(60) time.sleep(60)

View File

@ -2,8 +2,11 @@
# 重载sys模块设置默认字符串编码方式为utf8 # 重载sys模块设置默认字符串编码方式为utf8
import sys import sys
reload(sys) try:
reload(sys) # Python 2
sys.setdefaultencoding('utf8') sys.setdefaultencoding('utf8')
except NameError:
pass # Python 3
from time import sleep from time import sleep

View File

@ -2,8 +2,11 @@
# 重载sys模块设置默认字符串编码方式为utf8 # 重载sys模块设置默认字符串编码方式为utf8
import sys import sys
reload(sys) try:
reload(sys) # Python 2
sys.setdefaultencoding('utf8') sys.setdefaultencoding('utf8')
except NameError:
pass # Python 3
# 判断操作系统 # 判断操作系统
import platform import platform

View File

@ -2,8 +2,11 @@
# 重载sys模块设置默认字符串编码方式为utf8 # 重载sys模块设置默认字符串编码方式为utf8
import sys import sys
reload(sys) try:
reload(sys) # Python 2
sys.setdefaultencoding('utf8') sys.setdefaultencoding('utf8')
except NameError:
pass # Python 3
# 判断操作系统 # 判断操作系统
import platform import platform

View File

@ -2,8 +2,11 @@
# 重载sys模块设置默认字符串编码方式为utf8 # 重载sys模块设置默认字符串编码方式为utf8
import sys import sys
reload(sys) try:
reload(sys) # Python 2
sys.setdefaultencoding('utf8') sys.setdefaultencoding('utf8')
except NameError:
pass # Python 3
from time import sleep from time import sleep

View File

@ -1,5 +1,6 @@
# encoding: UTF-8 # encoding: UTF-8
from __future__ import print_function
import json import json
import time import time
import datetime import datetime
@ -57,7 +58,7 @@ def downMinuteBarBySymbol(symbol, num):
l = api.getHisBar(symbol, num, period=PERIOD_1MIN) l = api.getHisBar(symbol, num, period=PERIOD_1MIN)
if not l: if not l:
print u'%s数据下载失败' %symbol print(u'%s数据下载失败' %symbol)
return return
for d in l: for d in l:
@ -69,23 +70,23 @@ def downMinuteBarBySymbol(symbol, num):
end = time.time() end = time.time()
cost = (end - start) * 1000 cost = (end - start) * 1000
print u'合约%s数据下载完成%s - %s,耗时%s毫秒' %(symbol, generateVtBar(l[0]).datetime, print(u'合约%s数据下载完成%s - %s,耗时%s毫秒' %(symbol, generateVtBar(l[0]).datetime,
generateVtBar(l[-1]).datetime, cost) generateVtBar(l[-1]).datetime, cost))
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def downloadAllMinuteBar(num): def downloadAllMinuteBar(num):
"""下载所有配置中的合约的分钟线数据""" """下载所有配置中的合约的分钟线数据"""
print '-' * 50 print('-' * 50)
print u'开始下载合约分钟线数据' print(u'开始下载合约分钟线数据')
print '-' * 50 print('-' * 50)
for symbol in SYMBOLS: for symbol in SYMBOLS:
downMinuteBarBySymbol(symbol, num) downMinuteBarBySymbol(symbol, num)
time.sleep(1) time.sleep(1)
print '-' * 50 print('-' * 50)
print u'合约分钟线数据下载完成' print(u'合约分钟线数据下载完成')
print '-' * 50 print('-' * 50)

View File

@ -3,6 +3,7 @@
""" """
定时服务可无人值守运行实现每日自动下载更新历史行情数据到数据库中 定时服务可无人值守运行实现每日自动下载更新历史行情数据到数据库中
""" """
from __future__ import print_function
from dataService import * from dataService import *
@ -25,6 +26,6 @@ if __name__ == '__main__':
# 更新任务完成的日期 # 更新任务完成的日期
taskCompletedDate = t.date() taskCompletedDate = t.date()
else: else:
print u'当前时间%s,任务定时%s' %(t, taskTime) print(u'当前时间%s,任务定时%s' %(t, taskTime))
time.sleep(60) time.sleep(60)

View File

@ -1,5 +1,6 @@
# encoding: UTF-8 # encoding: UTF-8
from __future__ import print_function
import sys import sys
import json import json
from datetime import datetime from datetime import datetime
@ -67,7 +68,7 @@ def onChart(symbol, seconds):
start = datetime.fromtimestamp(l[0]['datetime']/1000000000) start = datetime.fromtimestamp(l[0]['datetime']/1000000000)
end = datetime.fromtimestamp(l[-1]['datetime']/1000000000) end = datetime.fromtimestamp(l[-1]['datetime']/1000000000)
print u'合约%s下载完成%s - %s' %(symbol, start, end) print(u'合约%s下载完成%s - %s' %(symbol, start, end))
# 移除已经完成的任务 # 移除已经完成的任务
if symbol in taskList: if symbol in taskList:
@ -81,9 +82,9 @@ def downMinuteBarBySymbol(symbol, num):
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def downloadAllMinuteBar(num, symbols): def downloadAllMinuteBar(num, symbols):
"""下载所有配置中的合约的分钟线数据""" """下载所有配置中的合约的分钟线数据"""
print '-' * 50 print('-' * 50)
print u'开始下载合约分钟线数据' print(u'开始下载合约分钟线数据')
print '-' * 50 print('-' * 50)
# 添加下载任务 # 添加下载任务
taskList.extend(symbols) taskList.extend(symbols)
@ -96,9 +97,9 @@ def downloadAllMinuteBar(num, symbols):
# 如果任务列表为空,则说明数据已经全部下载完成 # 如果任务列表为空,则说明数据已经全部下载完成
if not taskList: if not taskList:
print '-' * 50 print('-' * 50)
print u'合约分钟线数据下载完成' print(u'合约分钟线数据下载完成')
print '-' * 50 print('-' * 50)
return return

View File

@ -5,6 +5,7 @@
注意: 请确保本程序运行时, 本机天勤终端 (0.8.0 以上版本)正在运行中 注意: 请确保本程序运行时, 本机天勤终端 (0.8.0 以上版本)正在运行中
""" """
from __future__ import print_function
import time import time
import datetime import datetime
@ -34,6 +35,6 @@ if __name__ == '__main__':
# 更新任务完成的日期 # 更新任务完成的日期
taskCompletedDate = t.date() taskCompletedDate = t.date()
else: else:
print u'当前时间%s,任务定时%s' %(t, taskTime) print(u'当前时间%s,任务定时%s' %(t, taskTime))
time.sleep(60) time.sleep(60)

View File

@ -1,5 +1,6 @@
# encoding: UTF-8 # encoding: UTF-8
from __future__ import print_function
import sys import sys
import json import json
from datetime import datetime from datetime import datetime
@ -72,23 +73,23 @@ def downMinuteBarBySymbol(symbol):
end = time() end = time()
cost = (end - start) * 1000 cost = (end - start) * 1000
print u'合约%s数据下载完成%s - %s,耗时%s毫秒' %(symbol, df.index[0], df.index[-1], cost) print(u'合约%s数据下载完成%s - %s,耗时%s毫秒' %(symbol, df.index[0], df.index[-1], cost))
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def downloadAllMinuteBar(): def downloadAllMinuteBar():
"""下载所有配置中的合约的分钟线数据""" """下载所有配置中的合约的分钟线数据"""
print '-' * 50 print('-' * 50)
print u'开始下载合约分钟线数据' print(u'开始下载合约分钟线数据')
print '-' * 50 print('-' * 50)
# 添加下载任务 # 添加下载任务
for symbol in SYMBOLS: for symbol in SYMBOLS:
downMinuteBarBySymbol(str(symbol)) downMinuteBarBySymbol(str(symbol))
print '-' * 50 print('-' * 50)
print u'合约分钟线数据下载完成' print(u'合约分钟线数据下载完成')
print '-' * 50 print('-' * 50)

View File

@ -3,6 +3,7 @@
""" """
定时服务可无人值守运行实现每日自动下载更新历史行情数据到数据库中 定时服务可无人值守运行实现每日自动下载更新历史行情数据到数据库中
""" """
from __future__ import print_function
import time import time
import datetime import datetime
@ -27,6 +28,6 @@ if __name__ == '__main__':
# 更新任务完成的日期 # 更新任务完成的日期
taskCompletedDate = t.date() taskCompletedDate = t.date()
else: else:
print u'当前时间%s,任务定时%s' %(t, taskTime) print(u'当前时间%s,任务定时%s' %(t, taskTime))
time.sleep(60) time.sleep(60)