jq.get_price这个函数是错误的
时间: 2023-05-31 15:01:33 浏览: 73
我不确定您正在谈论的是哪个编程语言或软件库,但是如果您说的是JavaScript和jQuery库中的jq.get_price函数,则可能是因为它并不存在。jQuery库中没有名为jq.get_price的函数,因此如果您尝试使用它,可能会导致错误。
相关问题
self.main_ui.pushButton_2.clicked.connect(self.thing1) 没反应是为什么 class Worker(QtCore.QThread): sinOut = pyqtSignal(str) def __init__(self, parent=None): super(Worker, self).__init__(parent) # 设置工作状态与初始num数值 self.working = True self.num = 0 #def __del__(self): # 线程状态改变与线程终止 #self.working = False #self.wait() def stop(self): #线程状态改变与线程终止 self.working = False self.wait() def run(self): self.working = True while self.working == True: #file_str = 'File index{0}'.format(self.num) self.num += 1 # 发射信号 #self.sinOut.emit(file_str) self.sinOut.emit('1') # 线程休眠2秒 self.msleep(5) class parentWindow(QMainWindow): def __init__(self): QMainWindow.__init__(self) self.main_ui = JQ.Ui_MainWindow() self.main_ui.setupUi(self) self.thread1 = Worker() self.main_ui.pushButton_2.clicked.connect(self.thing1) self.thread1.sinOut.connect(self.printt) def thing1(self): #self.main_ui.pushButton.setEnabled(False) print('9999999999') self.thread1.start() print('123') #self.sleep(2) def printt(self): print('7777') def ok(): print('ok') # def hourstest(): # thread1 = Worker() # thread1.start() # com = JQ.Ui_MainWindow().comboBox_2.currentText() # ser = serial.Serial('com3', 1200, timeout=1) # data = bytes.fromhex( # '68 01 00 20 00 00 00 00 00 34 04 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 33 F4 16 ') # ser.write(data) if __name__ == "__main__": app = QtWidgets.QApplication(sys.argv) widget = QtWidgets.QMainWindow() widget = parentWindow() ui = JQ.Ui_MainWindow() # 这是原py中的类,因人而异哦 ui.setupUi(widget) ui.discoverSerial() #串口发现 #ui.pushButton_2.clicked.connect(widget.thing1) widget.show() sys.exit(app.exec_())
首先,你的连接语句应该是正确的。但是,你的槽函数`thing1`中启动了一个线程并且没有等待该线程完成。因此,当你再次点击`pushButton_2`时,会创建一个新的线程,导致出现问题。
你需要在`thing1`函数中添加`self.thread1.wait()`语句来等待线程完成。这样,当你再次点击`pushButton_2`时,它会等待线程完成后再启动一个新的线程。
另外,你在`ok`函数中定义了一个serial对象,但是没有使用它。如果你想使用该对象,你需要在该函数中添加相关代码。
以下是修改后的代码:
```
class parentWindow(QMainWindow):
def __init__(self):
QMainWindow.__init__(self)
self.main_ui = JQ.Ui_MainWindow()
self.main_ui.setupUi(self)
self.thread1 = Worker()
self.thread1.sinOut.connect(self.printt)
self.main_ui.pushButton_2.clicked.connect(self.thing1)
def thing1(self):
print('9999999999')
self.thread1.start()
self.thread1.wait() # 等待线程完成
print('123')
def printt(self):
print('7777')
def ok():
print('ok')
com = JQ.Ui_MainWindow().comboBox_2.currentText()
ser = serial.Serial('com3', 1200, timeout=1)
data = bytes.fromhex('68 01 00 20 00 00 00 00 00 34 04 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 33 F4 16 ')
ser.write(data)
```
import tushare as ts import datetime def has_five_consecutive_rises(data): close = data['close'] if len(close) < 5 or any(close[-5:] != close.iloc[-1]): return False for i in range(1, 5): if close.iloc[-i-1] >= close.iloc[-i]: return False return True today = datetime.datetime.now().strftime('%Y-%m-%d') three_months_ago = (datetime.datetime.now() - datetime.timedelta(days=90)).strftime('%Y-%m-%d') data = ts.get_hist_data('hs300', start=three_months_ago, end=today) for code in data.index: stock_data = ts.get_hist_data(code, start=three_months_ago, end=today) if has_five_consecutive_rises(stock_data): print(code)用聚宽运行上述代码
上述代码使用了tushare包,需要在聚宽中先安装tushare包并且获取tushare的token。同时,聚宽提供的get_price函数可以获取股票历史价格数据,可以用来替代tushare包中的get_hist_data函数。下面是修改后的代码:
```
import jqdatasdk as jq
import datetime
def has_five_consecutive_rises(data):
close = data['close']
if len(close) < 5 or any(close[-5:] != close.iloc[-1]):
return False
for i in range(1, 5):
if close.iloc[-i-1] >= close.iloc[-i]:
return False
return True
jq.auth('账号', '密码')
today = datetime.datetime.now().strftime('%Y-%m-%d')
three_months_ago = (datetime.datetime.now() - datetime.timedelta(days=90)).strftime('%Y-%m-%d')
data = jq.get_price('000300.XSHG', start_date=three_months_ago, end_date=today)
for code in data.index:
stock_data = jq.get_price(code, start_date=three_months_ago, end_date=today)
if has_five_consecutive_rises(stock_data):
print(code)
```
需要注意的是,聚宽为收费平台,使用聚宽平台需要注册账号并且购买相应的服务。