Python 3.x 将实时流媒体数据重新采样到15m时出错
我在将流媒体直播数据重新采样到15米的时间范围时收到了多次错误信息,如果我删除了我们删除的重新采样代码,程序运行良好Python 3.x 将实时流媒体数据重新采样到15m时出错,python-3.x,database,pandas,dataframe,pandas-resample,Python 3.x,Database,Pandas,Dataframe,Pandas Resample,我在将流媒体直播数据重新采样到15米的时间范围时收到了多次错误信息,如果我删除了我们删除的重新采样代码,程序运行良好 import time,os,datetime,math import xlwings as xw from time import sleep import
import time,os,datetime,math
import xlwings as xw
from time import sleep
import logging
from alice_blue import *
import pandas as pd
import datetime
import pdb
from pandas.io.json import json_normalize
############################################################################
logging.basicConfig(level=logging.DEBUG)
access_token = open('access_token.txt','r').read().strip()
alice = AliceBlue(username='username', password='password', access_token=access_token, master_contracts_to_download=['NFO'])
#############################################################################
token = 0
ltp = 0
open_price=0
high_price=0
low_price=0
close_price=0
t_stamp=0
row_no =2
socket_opened = False
def event_handler_quote_update(message):
# print(f"quote update {message}")
global row_no
global token
global ltp
global open_price
global high_price
global close_price
global low_price
global t_stamp
token = message['token']
ltp = message['ltp']
open_price = message['open']
high_price = message['high']
low_price = message['low']
close_price = message['close']
t_stamp = message['exchange_time_stamp']
####################################################################################
wb = xw.Book('TickData.xlsx')
sht = wb.sheets['Sheet1']
sht.range('A' + str(row_no)).value = token
sht.range('B' + str(row_no)).value = datetime.datetime.fromtimestamp(int(t_stamp)).strftime('%Y-%m-%d %H:%M:%S')
sht.range('C' + str(row_no)).value = ltp
sht.range('D' + str(row_no)).value = open_price
sht.range('E' + str(row_no)).value = high_price
sht.range('F' + str(row_no)).value = low_price
sht.range('G' + str(row_no)).value = close_price
row_no = row_no + 1
# print(token, t_stamp, ltp, open_price, high_price, low_price, close_price)
####################################################################################
def open_callback():
global socket_opened
socket_opened = True
alice.start_websocket(subscribe_callback=event_handler_quote_update,
socket_open_callback=open_callback,
run_in_background=True)
while(socket_opened==False):
pass
df=pd.read_excel('TickData.xlsx', names=['token','t_stamp','ltp','open_price','high_price','low_price','close_price'], index_col=1, parse_dates=True)
df=pd.DataFrame(df)
data=df['ltp'].resample('1min').ohlc()
print(data)
data.to_excel('a.xlsx')
alice.subscribe(alice.get_instrument_by_symbol('NFO', 'BANKNIFTY SEP FUT'), LiveFeedType.MARKET_DATA)
sleep(0.200)
# print(token, t_stamp, open_price, high_price, low_price, close_price)
sleep(4000)
####################################################################################
我已要求对收到的每1500万条投诉和基本实时数据进行OHLC重采样
此外,我们可以在一个excel中执行同样的操作,并且/或者不将数据保存到任何csv/xls
谢谢你的进步&很抱歉我的编码技巧