65 views
0

把历史数据补为一个CSV文件.

quotesT= datetime.datetime.fromtimestamp(ks[s][i][“datetime”]/1e9)
OSError: [Errno 22] Invalid argument

就是上面这个错误.但多运行几次就会对一次.而且如果SYMBOL代码多,这个错误就会多一些.有何方法处理吗

Traceback (most recent call last):
File “C:\Users\CarreyXu\AppData\Local\Programs\Python\Python36-32\Lib\site-packages\tqsdk\demo\DDE era Single backfill.py”, line 71, in <module>
quotesT= datetime.datetime.fromtimestamp(ks[s][i][“datetime”]/1e9)
OSError: [Errno 22] Invalid argument
>>>
RESTART: C:\Users\CarreyXu\AppData\Local\Programs\Python\Python36-32\Lib\site-packages\tqsdk\demo\DDE era Single backfill.py
Traceback (most recent call last):
File “C:\Users\CarreyXu\AppData\Local\Programs\Python\Python36-32\Lib\site-packages\tqsdk\demo\DDE era Single backfill.py”, line 71, in <module>
quotesT= datetime.datetime.fromtimestamp(ks[s][i][“datetime”]/1e9)
OSError: [Errno 22] Invalid argument
>>>
RESTART: C:\Users\CarreyXu\AppData\Local\Programs\Python\Python36-32\Lib\site-packages\tqsdk\demo\DDE era Single backfill.py
Traceback (most recent call last):
File “C:\Users\CarreyXu\AppData\Local\Programs\Python\Python36-32\Lib\site-packages\tqsdk\demo\DDE era Single backfill.py”, line 71, in <module>
quotesT= datetime.datetime.fromtimestamp(ks[s][i][“datetime”]/1e9)
OSError: [Errno 22] Invalid argument

import datetime
import csv
 #!/usr/bin/env python
#  -*- coding: utf-8 -*-
from tqsdk import TqApi, TqSim
import datetime
api = TqApi(TqSim())
SYMS = {
      'R1': 'KQ.m@SHFE.ag',
     'R5': 'KQ.m@SHFE.ni',
  'R6': 'KQ.m@DCE.j',
   'R7': 'KQ.m@DCE.pp',
  'R8': 'CZCE.AP001',
   'R9': 'CZCE.TA001',
  'R11': 'KQ.m@SHFE.ru',    
 'R12': 'KQ.m@DCE.eg',
  'R13': 'CZCE.MA001',
   'R14': 'KQ.m@CZCE.CF',
    'R15': 'KQ.m@CZCE.CJ',
   'R17': 'DCE.i2001',
  'R18': 'DCE.y2001',
    'R19': 'DCE.p2001',
     'R21': 'KQ.m@DCE.jd',
   'R23': 'KQ.m@CZCE.SR',
   'R27': 'KQ.m@CZCE.OI',
  'R28': 'DCE.jm2001',
     }
def get_key (dict, value):
    return [k for k, v in dict.items() if v == value]
 i=-8000
ks = {}
 first_time = True
 for s in SYMS:
    ks[s] = api.get_kline_serial( SYMS[s],60,8199)
 while not all([ks[s].is_ready() for s in ks]):
            api.wait_update()
    if api.is_changing(ks[s][i], 'close'):
                             while i<=-1:
                    for s in SYMS:
                        quotesC=ks[s][i]["close"]
                        quotesO=ks[s][i]["open"]
                        quotesH=ks[s][i]["high"]
                        quotesL=ks[s][i]["low"]
                        quotesV=ks[s][i]["volume"]
                        quotesT= datetime.datetime.fromtimestamp(ks[s][i]["datetime"]/1e9)
                         with open("C:\\Docu Dontdel\\ChinaFut.csv","a",newline='') as csvfile: 
                                    writer = csv.writer(csvfile, dialect='excel')
                                    writer.writerow([str(get_key (SYMS, SYMS[s])).replace(' ', '')[2:-2].upper(),str(quotesT).replace(' ', '')[0:-8],str(quotesT).replace(' ', '')[10:],quotesO,quotesH,quotesL,quotesC,quotesV])
                                    csvfile.close()

Answered question
0

百度关键报错即可查到对应解决方案,可以看看能否解决你的问题

https://blog.csdn.net/u012561176/article/details/82107350

Posted new comment

里面的方法试了,都没有用.另外有一个细节.文中报错是指出了是 with open这一段. 所以,作者针对这个语句修改解决了问题.
但我的报错这指出了这一行:
quotesT= datetime.datetime.fromtimestamp(ks[s][i][“datetime”]/1e9)
OSError: [Errno 22] Invalid argument
这是一个转换时间并赋值的语句.应该要修改这一行.但不知如何改

You are viewing 1 out of 1 answers, click here to view all answers.