def __init__(self, parent=None): super().__init__(parent) self.bottomlay = QtWidgets.QHBoxLayout() self.top_save = QtWidgets.QPushButton("Save", self) self.top_save.clicked.connect(self.btn_save) self.top_load = QtWidgets.QPushButton("Load", self) self.top_load.clicked.connect(self.btn_load) self.bottomlay.addWidget(self.top_save) self.bottomlay.addWidget(self.top_load) self.vlay = QtWidgets.QVBoxLayout(self) self.tab = QtWidgets.QTabWidget() self.vlay.addWidget(self.tab) self.vlay.addLayout(self.bottomlay) self.tick = 0 self.deal_row_index = 0 self.order_row_index = 0 self.deal_record_row_index = 0 self.page = [] self.create_page1() self.create_page2() self.order = {} self.deal = [] self.deal_gain = 0 self.deal_record = [] SignalFactor().sign_run_init.connect(self.run_init) SignalFactor().sign_trade_deal.connect(self.trade_deal) SignalFactor().sign_trade_order_ret.connect(self.trade_order) SignalFactor().sign_reconnect.connect(self.reconnect) SignalFactor().sign_tick_update.connect(self.tick_update)
def action_reveiwRun(self): self.reveiwspeed = 1 id = SettingFactor().getReviewConfigID() month = SettingFactor().getReviewConfigMonth() start_time = SettingFactor().getReviewConfigStartDate( ) + SettingFactor().getReviewConfigStartTime() end_time = SettingFactor().getReviewConfigEndDate() + SettingFactor( ).getReviewConfigEndTime() SignalFactor().sign_run_init.emit({ 'start_time': start_time, 'end_time': end_time }) SignalFactor().sign_review_run.emit(id, month, 1000, start_time, end_time)
def trade_clear(self): gain = 0 count = 0 long_short = True for t in self.trade: if t.long_short: long_short = t.long_short gain = gain + (self.tick.Close - t.price) * t.count self.account.fee = self.account.fee + t.count else: long_short = t.long_short gain = gain + (t.price - self.tick.Close) * t.count self.account.fee = self.account.fee + t.count count = count + t.count if gain != 0: self.account.profit = self.account.profit + gain if count > 0: SignalFactor().sign_trade_deal.emit(self.tick, not long_short, count, gain) self.trade_order_mit_buy_clear() self.trade_order_mit_sell_clear() self.mit = {} self.marekt = {} self.trade = []
def yahoo_config_done(self): SignalFactor().sign_run_init.emit({}) yahoo = YahooAgent() yahoo.init() yahoo.setCallback(self.yahoo_callback_price) yahoo.run_start()
def btn_load(self): filters = ('all file (*.*);;') fileName = QtWidgets.QFileDialog.getOpenFileName(self, 'Open File', './', filter=filters)[0] if fileName: file = QtCore.QFile(fileName) if not file.open(QtCore.QFile.ReadOnly | QtCore.QFile.Text): QtWidgets.QMessageBox.warning( self, "Application", "Cannot read file %s:\n%s." % (fileName, file.errorString())) return self.deal_record = [] if len(self.page) <= self.df_page_deal_record: self.create_page3() else: self.page[self.deal_record_row_index].setRowCount(0) self.deal_record_row_index = 0 inf = QtCore.QTextStream(file) while not inf.atEnd(): line = inf.readLine() #read one line at a time if line[0:2] == "//": continue if 'VER' in line: continue datas = line.split(',') Date_Time = pd.Timestamp(datas[0]) deal = SimpleNamespace( Date_Time=Date_Time, Close=float(datas[1]), LongShort=True if int(datas[2]) > 0 else False, Count=int(datas[3])) self.setUpdatesEnabled(False) self.page[self.df_page_deal_record].insertRow( self.deal_record_row_index) self.deal_record_row_index = self.deal_record_row_index + 1 self.add_deal_record_item(self.df_deal_header_buy_sell, "買" if int(datas[2]) else "賣") self.add_deal_record_item(self.df_deal_header_date, Date_Time.strftime('%H:%M:%S')) self.add_deal_record_item(self.df_deal_header_count, datas[3]) self.add_deal_record_item(self.df_deal_header_price, datas[1]) self.add_deal_record_item(self.df_deal_header_profit, datas[4]) self.add_deal_record_item(self.df_deal_header_note, datas[5]) self.setUpdatesEnabled(True) if hasattr( self.tick, 'Date_Time') and self.tick.Date_Time >= deal.Date_Time: SignalFactor().sign_kbar_deal_mark.emit(deal) else: self.deal_record.append(deal) self.deal_record.reverse() QtWidgets.QMessageBox.information(self, "Load Successful", fileName)
def tick_update(self, tick): self.tick = tick if self.deal_record: deal = self.deal_record[-1] if deal.Date_Time <= self.tick.Date_Time and deal.Close == self.tick.Close: SignalFactor().sign_kbar_deal_mark.emit(deal) self.deal_record.pop()
def deactive(self): SignalFactor().sign_run_init.disconnect(self.run_init) SignalFactor().sign_tick_update.disconnect(self.tick_update) SignalFactor().sign_trade_order_market.disconnect( self.trade_order_market) SignalFactor().sign_trade_order_limit_market.disconnect( self.trade_order_limit_market) SignalFactor().sign_trade_order_market_buy_clear.disconnect( self.trade_order_market_buy_clear) SignalFactor().sign_trade_order_market_sell_clear.disconnect( self.trade_order_market_sell_clear) SignalFactor().sign_trade_order_mit.disconnect(self.trade_order_mit) SignalFactor().sign_trade_order_mit_buy_clear.disconnect( self.trade_order_mit_buy_clear) SignalFactor().sign_trade_order_mit_sell_clear.disconnect( self.trade_order_mit_sell_clear) SignalFactor().sign_trade_clear.disconnect(self.trade_clear)
def action_saveFile(self): filters = ('PNG (*.png);;') filename = QtWidgets.QFileDialog.getSaveFileName(self.mainwindow, 'Save File', './', filter=filters)[0] SignalFactor().sign_savefile.emit(filename) QtWidgets.QMessageBox.about(self.mainwindow, "Message", "Save File Finish")
def action_openFile(self): filters = ('default (*.rpt *.csv);;' 'all file (*.*);;') filename = QtWidgets.QFileDialog.getOpenFileName(self.mainwindow, 'Open File', './', filter=filters)[0] SignalFactor().sign_loadfile.emit(filename) QtWidgets.QMessageBox.about(self.mainwindow, "Message", "Open File Finish")
def rightClicked(self, e): pos = e.pos() item = self.tablewidget.itemAt(pos) if item is None: return row = item.row() column = item.column() header = [ PriceLadderWidget.df_header_bid, PriceLadderWidget.df_header_ask, PriceLadderWidget.df_header_mit_buy, PriceLadderWidget.df_header_mit_sell ] if not column in header: return price_tiem = self.tablewidget.item(row, PriceLadderWidget.df_header_price) if is_digit(price_tiem.text()) == False: return price = float(price_tiem.text()) if column == PriceLadderWidget.df_header_bid or column == PriceLadderWidget.df_header_ask: SignalFactor().sign_trade_order_limit_market.emit( price, -self.run_position, column == PriceLadderWidget.df_header_bid) elif column == PriceLadderWidget.df_header_mit_buy or column == PriceLadderWidget.df_header_mit_sell: if not price in self.run_mit_list[column]: self.run_mit_list[column][price] = 0 return value = self.run_mit_list[column][ price] = self.run_mit_list[column][price] - self.run_position if self.run_mit_list[column][price] < 0: self.run_mit_list[column][price] = 0 value = 0 SignalFactor().sign_trade_order_mit.emit( price, value, column == PriceLadderWidget.df_header_mit_buy) self.update_mit_header()
def dde_callback_price(self, value, item): values = value.split(';') Open = High = Low = Close = float( re.match('[+-]?([0-9]*[.])?[0-9]+', values[2]).group()) tick = SimpleNamespace(Date_Time=pd.Timestamp(values[0] + ' ' + values[1]), Close=Close, High=High, Low=Low, Open=Open) SignalFactor().sign_tick_update.emit(tick)
def review_interval(self): old_tick_idx = self.review_tick_idx self.review_tick_idx = self.review_tick_idx + 1 data_len = self.review_tick.shape[0] if self.review_tick_idx >= data_len: self.review_timer.stop() return new_tick = self.review_tick.iloc[self.review_tick_idx] if old_tick_idx >= 0: old_tick = self.review_tick.iloc[old_tick_idx] if new_tick.Date_Time != old_tick.Date_Time: #ProfilerFactor().timer_elapsed () self.review_sec() if old_tick_idx != self.review_tick_idx: SignalFactor().sign_tick_update.emit(new_tick) else: SignalFactor().sign_time_update.emit(self.curr_time)
def trade_order_market(self, price, count, long_short): #""" if not self.trade or self.trade[-1].long_short == long_short: trade = SimpleNamespace() trade.price = self.tick.Close trade.long_short = long_short trade.count = count self.trade.append(trade) SignalFactor().sign_trade_deal.emit(self.tick, long_short, trade.count, 0) else: tmp_trade = [] market_count = count for t in self.trade: if market_count <= 0: tmp_trade.append(t) continue if t.count > market_count: if long_short: gain = (t.price - self.tick.Close) * market_count else: gain = (self.tick.Close - t.price) * market_count self.account.profit = self.account.profit + gain SignalFactor().sign_trade_deal.emit( self.tick, long_short, market_count, gain) self.account.fee = self.account.fee + market_count t.count = t.count - market_count market_count = 0 tmp_trade.append(t) else: if long_short: gain = (t.price - self.tick.Close) * t.count else: gain = (self.tick.Close - t.price) * t.count self.account.profit = self.account.profit + gain self.account.fee = self.account.fee + t.count SignalFactor().sign_trade_deal.emit( self.tick, long_short, t.count, gain) market_count = market_count - t.count self.trade = tmp_trade """
def init(self, mainwindow): self.mainwindow = mainwindow self.mit = {} self.market = {} self.trade = [] self.account = SimpleNamespace(profit=0, fee=0) SignalFactor().sign_run_init.connect(self.run_init) SignalFactor().sign_tick_update.connect(self.tick_update) SignalFactor().sign_trade_order_market.connect(self.trade_order_market) SignalFactor().sign_trade_order_limit_market.connect( self.trade_order_limit_market) SignalFactor().sign_trade_order_market_buy_clear.connect( self.trade_order_market_buy_clear) SignalFactor().sign_trade_order_market_sell_clear.connect( self.trade_order_market_sell_clear) SignalFactor().sign_trade_order_mit.connect(self.trade_order_mit) SignalFactor().sign_trade_order_mit_buy_clear.connect( self.trade_order_mit_buy_clear) SignalFactor().sign_trade_order_mit_sell_clear.connect( self.trade_order_mit_sell_clear) SignalFactor().sign_trade_clear.connect(self.trade_clear)
def review_prev(self): old_tick_idx = self.review_tick_idx curr_time = self.review_tick.iat[old_tick_idx, 5] curr_epoch = curr_time.timestamp() - SettingFactor().KBarInterval lefttime = int(curr_epoch) % SettingFactor().KBarInterval curr_epoch = curr_epoch - lefttime prev_time = pd.Timestamp(curr_epoch, unit='s') df = self.review_tick[self.review_tick['Date_Time'] < prev_time] self.review_tick_idx = df.shape[0] curr_time = self.review_tick.iat[self.review_tick_idx, 5] SignalFactor().sign_review_prev_done.emit(curr_time) self.next_time = curr_time self.review_tick_idx = self.review_tick_idx - 1 self.review_timer.setInterval(0)
def clickedOK(self): enable = self.endable_checkbox.isChecked() service = self.service.text() topic = self.topic.text() advise_price = self.advise_price.text() advise_ask = self.advise_ask.text() advise_bid = self.advise_bid.text() SettingFactor().setDDEEnable("True" if enable else "") SettingFactor().setDDEService(service) SettingFactor().setDDETopic(topic) SettingFactor().setDDEAdvisePrice(advise_price) SettingFactor().setDDEAdviseAsk(advise_ask) SettingFactor().setDDEAdviseBid(advise_bid) SignalFactor().sign_dde_config_done.emit(enable)
def review_next(self): if self.run_review_old_next_tick == self.review_tick_idx: self.review_tick_idx = self.review_tick_idx + 1 old_tick_idx = self.review_tick_idx curr_time = self.review_tick.iat[old_tick_idx, 5] curr_epoch = curr_time.timestamp() next_epoch = curr_time.timestamp() + SettingFactor().KBarInterval lefttime = int(curr_epoch) % SettingFactor().KBarInterval curr_epoch = curr_epoch - lefttime curr_time = pd.Timestamp(curr_epoch, unit='s') next_time = pd.Timestamp(next_epoch, unit='s') df_curr = self.review_tick[self.review_tick['Date_Time'] < curr_time] df_next = self.review_tick[self.review_tick['Date_Time'] < next_time] start_idx = df_curr.shape[0] end_idx = df_next.shape[0] ticks = [] tick = None for i in range(start_idx, end_idx): curr = self.review_tick.iloc[i] if not tick is None: if tick.Date_Time.timestamp() - curr.Date_Time.timestamp( ) >= SettingFactor().KBarInterval: ticks.append(tick) tick = None else: tick.Close = curr.Close tick.High = max(tick.High, curr.Close) tick.Low = min(tick.Low, curr.Close) if tick is None: tick = SimpleNamespace(Date_Time=curr.Date_Time, Close=curr.Close, High=curr.High, Low=curr.Low, Open=curr.Open) if tick: ticks.append(tick) self.review_tick_idx = i - 1 self.run_review_old_next_tick = self.review_tick_idx self.next_time = curr.Date_Time self.review_timer.setInterval(0) SignalFactor().sign_review_next_done.emit(ticks)
def dde_run(self): if self.dde: del self.dde self.dde = None #self.dde = DDEClient("XQLite", "Quote") #self.dde.advise("FITXN*1.TF-TradingDate,Time,Price", self.dde_callback_price) #self.dde.advise("FITXN*1.TF-BestBid1,BestBidSize1,BestBid2,BestBidSize2,BestBid3,BestBidSize3,BestBid4,BestBidSize4,BestBid5,BestBidSize5", self.dde_callback_best_bid) #self.dde.advise("FITXN*1.TF-BestAsk1,BestAskSize1,BestAsk2,BestAskSize2,BestAsk3,BestAskSize3,BestAsk4,BestAskSize4,BestAsk5,BestAskSize5", self.dde_callback_best_ask) self.dde = DDEClient(SettingFactor().getDDEService(), SettingFactor().getDDETopic()) self.dde.advise(SettingFactor().getDDEAdvisePrice(), self.dde_callback_price) if SettingFactor().getDDEAdviseAsk() != "": self.dde.advise(SettingFactor().getDDEAdviseAsk(), self.dde_callback_best_ask) if SettingFactor().getDDEAdviseBid() != "": self.dde.advise(SettingFactor().getDDEAdviseBid(), self.dde_callback_best_bid) SignalFactor().sign_run_init.emit( {'start_time': datetime.datetime.now().strftime("%Y%m%d%H%M")})
def __init__(self, mainwindow): self.mainwindow = mainwindow self.toolbar = QtWidgets.QToolBar() self.mainwindow.addToolBar(self.toolbar) self.toolbar.setIconSize(QtCore.QSize(16, 16)) self.btn = [None] * ToolBar.df_btn_max action_factor = ActionFactor() btn = QtWidgets.QToolButton() btn.setDefaultAction(action_factor.openfile) self.toolbar.addWidget(btn) self.btn[ToolBar.df_btn_open] = btn btn = QtWidgets.QToolButton() btn.setDefaultAction(action_factor.savefile) self.toolbar.addWidget(btn) self.btn[ToolBar.df_btn_save] = btn self.toolbar.addSeparator() btn = QtWidgets.QToolButton() btn.setDefaultAction(action_factor.connectconfig) btn.setCheckable(True) self.toolbar.addWidget(btn) self.btn[ToolBar.df_btn_connect_config] = btn btn = QtWidgets.QToolButton() btn.setDefaultAction(action_factor.reconnect) btn.setCheckable(True) self.toolbar.addWidget(btn) self.btn[ToolBar.df_btn_reconnect] = btn self.toolbar.addSeparator() btn = QtWidgets.QToolButton() btn.setDefaultAction(action_factor.reviewconfig) self.toolbar.addWidget(btn) self.btn[ToolBar.df_btn_reviewconfig] = btn btn = QtWidgets.QToolButton() btn.setDefaultAction(action_factor.reveiwrun) btn.setCheckable(True) self.toolbar.addWidget(btn) self.btn[ToolBar.df_btn_reveiwrun] = btn btn = QtWidgets.QToolButton() btn.setDefaultAction(action_factor.reveiwsuspend) btn.setCheckable(True) action_factor.reveiwsuspend.triggered.connect( self.click_btn_reveiwsuspend) self.toolbar.addWidget(btn) self.btn[ToolBar.df_btn_reveiwsuspend] = btn btn = QtWidgets.QToolButton() btn.setDefaultAction(action_factor.reveiwstop) self.toolbar.addWidget(btn) self.btn[ToolBar.df_btn_reveiwstop] = btn btn = QtWidgets.QToolButton() btn.setDefaultAction(action_factor.reveiwprev) self.toolbar.addWidget(btn) self.btn[ToolBar.df_btn_reveiwprev] = btn btn = QtWidgets.QToolButton() btn.setDefaultAction(action_factor.reveiwnext) self.toolbar.addWidget(btn) self.btn[ToolBar.df_btn_reveiwnext] = btn btn = QtWidgets.QToolButton() btn.setDefaultAction(action_factor.reveiwslower) self.toolbar.addWidget(btn) self.btn[ToolBar.df_btn_reveiwslower] = btn btn = QtWidgets.QToolButton() btn.setDefaultAction(action_factor.reveiwfaster) self.toolbar.addWidget(btn) self.btn[ToolBar.df_btn_reveiwfaster] = btn self.reviewspeed = QtWidgets.QLabel("1x") self.toolbar.addWidget(self.reviewspeed) self.toolbar.addSeparator() self.timeedit = Time24Edit() self.timeedit.setMaximumWidth(150) self.timeedit.setTime(QtCore.QTime(9, 0, 0)) self.toolbar.addWidget(self.timeedit) btn = QtWidgets.QPushButton() btn.clicked.connect(action_factor.reviewgoto.triggered) btn.setMaximumWidth(30) btn.setText('Go') self.toolbar.addWidget(btn) action_factor.reviewgoto.triggered.connect(self.click_btn_reviewgoto) self.toolbar.addSeparator() btn = QtWidgets.QToolButton() btn.setDefaultAction(action_factor.zome_x) btn.setCheckable(True) btn.setChecked(True) action_factor.zome_x.triggered.connect(self.click_btn_zome_x) self.toolbar.addWidget(btn) self.btn[ToolBar.df_btn_zoom_x] = btn btn = QtWidgets.QToolButton() btn.setDefaultAction(action_factor.zome_y) btn.setCheckable(True) btn.setChecked(True) action_factor.zome_y.triggered.connect(self.click_btn_zome_y) self.toolbar.addWidget(btn) self.btn[ToolBar.df_btn_zoom_y] = btn btn = QtWidgets.QToolButton() btn.setDefaultAction(action_factor.mark) btn.setCheckable(True) btn.setChecked(True) action_factor.mark.triggered.connect(self.click_btn_mark) self.toolbar.addWidget(btn) self.btn[ToolBar.df_btn_mark] = btn btn = QtWidgets.QToolButton() btn.setDefaultAction(action_factor.hline) self.toolbar.addWidget(btn) self.btn[ToolBar.df_btn_hline] = btn self.toolbar.addSeparator() btn = QtWidgets.QToolButton() btn.setDefaultAction(action_factor.k30s) btn.setCheckable(True) btn.triggered.connect(self.connect_btn_k30s) self.toolbar.addWidget(btn) self.btn[ToolBar.df_btn_k30s] = btn self.toolbar.addSeparator() btn = QtWidgets.QToolButton() btn.setDefaultAction(action_factor.k1m) btn.setCheckable(True) btn.setChecked(True) btn.triggered.connect(self.connect_btn_k1m) self.toolbar.addWidget(btn) self.btn[ToolBar.df_btn_k1m] = btn self.toolbar.addSeparator() btn = QtWidgets.QToolButton() btn.setDefaultAction(action_factor.k5m) btn.setCheckable(True) btn.triggered.connect(self.connect_btn_k5m) self.toolbar.addWidget(btn) self.btn[ToolBar.df_btn_k5m] = btn SignalFactor().sign_run_init.connect(self.run_init) SignalFactor().sign_review_speed_change.connect( self.review_speed_change) SignalFactor().sign_connect_config_done.connect( self.connect_config_done)
def click_btn_reviewgoto(self): go_time = self.timeedit.time() SignalFactor().sign_review_goto.emit(go_time)
def clickedDel (self): value = self.line_number.text() SignalFactor ().sign_hline_change.emit (value, -1) self.close ()
def clickedOK (self): SignalFactor ().sign_connect_config_done.emit () self.close ()
def reconnect_trade_order_ret_done(self): for trade in self.reconnect_trade_order_deal: SignalFactor().reconnect_trade_order_deal.emit( trade.price, trade.long_short, trade.count, 0)
def __init__(self, parent=None): super().__init__(parent) self.run_left_bar = 0 self.run_show_bar = self.df_show_bar self.run_tick_range_left = 0 self.run_volumn_offset = 0 self.run_start_time = 0 self.trade = SimpleNamespace(count=0, long_short=True) self.record_trade = SimpleNamespace(count=0, long_short=True) self.candlesTick = CandlestickItem() self.pricePosition = PricePositionItem(self.candlesTick) self.pricePosition.setvisible(True) self.priceRecordPosition = PricePositionItem(self.candlesTick) self.priceRecordPosition.setvisible(True) self.axis_x_datetime = TimeStringAxis(orientation='bottom') self.axis_x_datetime.setTickSpacing(10, 5) vb = CustomViewBox() self.plotwidget = pg.PlotWidget( viewBox=vb, axisItems={'bottom': self.axis_x_datetime}, enableMenu=False) self.plotwidget.addItem(self.candlesTick) #self.plotwidget.addItem (self.pricePosition) self.plotwidget.showGrid(x=True, y=True) self.axis_volumn_left = self.plotwidget.getAxis('left') self.axis_volumn_left.setTickSpacing(10, 1) self.hLineDict = {} #self.top_line = pg.InfiniteLine(angle=0, movable=False, ) #self.bottom_line = pg.InfiniteLine(angle=0, movable=False, ) #self.plotwidget.addItem (self.top_line, ignoreBounds=True) #self.plotwidget.addItem (self.bottom_line, ignoreBounds=True) self.top_label = pg.TextItem(anchor=(0, 1)) self.bottom_label = pg.TextItem() self.plotwidget.addItem(self.top_label, ignoreBounds=True) self.plotwidget.addItem(self.bottom_label, ignoreBounds=True) self.scrollbar_x = QtWidgets.QScrollBar(QtCore.Qt.Horizontal) self.scrollbar_x.setMinimum(0) self.scrollbar_x.setMaximum(self.df_max_bar - self.df_show_bar - 1) self.scrollbar_x.sliderMoved.connect(self.onAxisSliderXMoved) self.slider_x = QtWidgets.QSlider(QtCore.Qt.Horizontal) self.slider_x.setRange(-self.df_left_bar, self.df_max_bar - self.df_show_bar) self.slider_x.setValue(0) self.slider_x.sliderMoved.connect(self.onZoomSliderXMoved) self.scrollbar_y = QtWidgets.QScrollBar(QtCore.Qt.Vertical) self.scrollbar_y.setMinimum(-500) self.scrollbar_y.setMaximum(500) self.scrollbar_y.setValue(0) self.scrollbar_y.sliderMoved.connect(self.onAxisSliderYMoved) self.slider_y = QtWidgets.QSlider(QtCore.Qt.Vertical) self.slider_y.setRange(-100, 100) self.slider_y.setValue(-19) self.slider_y.sliderMoved.connect(self.onZoomSliderYMoved) hlay = QtWidgets.QHBoxLayout() for w in (self.plotwidget, self.scrollbar_y, self.slider_y): hlay.addWidget(w) vlay = QtWidgets.QVBoxLayout(self) vlay.addLayout(hlay) for w in (self.scrollbar_x, self.slider_x): vlay.addWidget(w) self.info_lable = pg.TextItem() self.plotwidget.addItem(self.info_lable) self.vLine = pg.InfiniteLine( angle=90, movable=False, ) self.hLine = pg.InfiniteLine( angle=0, movable=False, ) self.plotwidget.addItem(self.vLine, ignoreBounds=True) self.plotwidget.addItem(self.hLine, ignoreBounds=True) self.line_label = pg.TextItem(anchor=(0, 1)) self.plotwidget.addItem(self.line_label, ignoreBounds=True) self.move_slot = pg.SignalProxy(self.plotwidget.scene().sigMouseMoved, rateLimit=60, slot=self.print_slot) SignalFactor().sign_savefile.connect(self.savefile) SignalFactor().sign_run_init.connect(self.run_init) SignalFactor().sign_tick_update.connect(self.update_tick) SignalFactor().sign_zoom_x_visible.connect(self.zoom_x_visible) SignalFactor().sign_zoom_y_visible.connect(self.zoom_y_visible) SignalFactor().sign_mark.connect(self.mark) SignalFactor().sign_trade_deal.connect(self.trade_deal) SignalFactor().sign_review_goto_init.connect(self.review_goto_init) SignalFactor().sign_review_goto_done.connect(self.review_goto_done) SignalFactor().sign_review_prev_done.connect(self.review_prev_done) SignalFactor().sign_review_next_done.connect(self.review_next_done) SignalFactor().sign_hline_change.connect(self.hline_change) SignalFactor().sign_reconnect.connect(self.reconnect) SignalFactor().sign_reconnect_trade_order_ret.connect( self.reconnect_trade_order_ret) SignalFactor().sign_reconnect_trade_order_ret_done.connect( self.reconnect_trade_order_ret_done) SignalFactor().sign_kbar_interval_change_init.connect( self.kbar_interval_change_init) SignalFactor().sign_kbar_deal_mark.connect(self.kbar_deal_mark)
def btn_sell(self): price = self.tick.Close - self.run_better_size SignalFactor().sign_trade_order_market.emit(price, self.run_position, False)
def trade_order_mit_sell_clear(self): for price in self.mit: if False in self.mit[price]: del self.mit[price][False] SignalFactor().sign_trade_order_mit_ret.emit(price, False, 0)
def trade_order_mit_buy_clear(self): for price in self.mit: if True in self.mit[price]: del self.mit[price][True] SignalFactor().sign_trade_order_mit_ret.emit(price, True, 0)
def trade_exec(self): if not self.tick.Close in self.mit and not self.tick.Close in self.market: return market = None if self.tick.Close in self.market: market = self.market[self.tick.Close] else: self.market[self.tick.Close] = {} self.market[self.tick.Close][True] = SimpleNamespace(count=0) self.market[self.tick.Close][False] = SimpleNamespace(count=0) market = self.market[self.tick.Close] mit = None if self.tick.Close in self.mit: mit = self.mit[self.tick.Close] if mit: for long_short in [True, False]: if not long_short in mit: continue if market is None or not long_short in market: market[long_short] = SimpleNamespace(count=0) market[long_short].count = market[long_short].count + mit[ long_short].count SignalFactor().sign_trade_order_mit_ret.emit( self.tick.Close, long_short, 0) del self.mit[self.tick.Close] for long_short in [True, False]: if not long_short in market: continue if market[long_short].count <= 0: continue if not self.trade or self.trade[-1].long_short == long_short: trade = SimpleNamespace() trade.price = self.tick.Close trade.long_short = long_short trade.count = market[long_short].count self.trade.append(trade) del self.market[self.tick.Close][long_short] SignalFactor().sign_trade_order_market_ret.emit( self.tick.Close, long_short, 0) SignalFactor().sign_trade_order_mit_ret.emit( self.tick.Close, long_short, 0) SignalFactor().sign_trade_deal.emit(self.tick, long_short, trade.count, 0) else: tmp_trade = [] for t in self.trade: if market[long_short].count <= 0: tmp_trade.append(t) continue if t.count > market[long_short].count: if long_short: gain = (t.price - self.tick.Close) * market[long_short].count else: gain = (self.tick.Close - t.price) * market[long_short].count self.account.profit = self.account.profit + gain SignalFactor().sign_trade_deal.emit( self.tick, long_short, market[long_short].count, gain) self.account.fee = self.account.fee + market[ long_short].count t.count = t.count - market[long_short].count market[long_short].count = 0 tmp_trade.append(t) else: if long_short: gain = (t.price - self.tick.Close) * t.count else: gain = (self.tick.Close - t.price) * t.count self.account.profit = self.account.profit + gain self.account.fee = self.account.fee + t.count SignalFactor().sign_trade_deal.emit( self.tick, long_short, t.count, gain) market[long_short].count = market[ long_short].count - t.count self.trade = tmp_trade SignalFactor().sign_trade_order_market_ret.emit( self.tick.Close, long_short, market[long_short].count) if market[long_short].count <= 0: del self.market[self.tick.Close][long_short] if len(self.trade) <= 0 and SettingFactor( ).getFreePosFreeOrderEnable() == 'True': self.trade_order_market_buy_clear() self.trade_order_market_sell_clear() self.trade_order_mit_buy_clear() self.trade_order_mit_sell_clear()
def trade_order_limit_market(self, price, count, long_short): is_trade = False if count > 0: if long_short == True and price >= self.tick.Close: is_trade = True elif long_short == False and price <= self.tick.Close: is_trade = True if is_trade: if not self.trade or self.trade[-1].long_short == long_short: trade = SimpleNamespace() trade.price = self.tick.Close trade.long_short = long_short trade.count = count self.trade.append(trade) SignalFactor().sign_trade_deal.emit(self.tick, long_short, trade.count, 0) else: tmp_trade = [] market_count = count for t in self.trade: if market_count <= 0: tmp_trade.append(t) continue if t.count > market_count: if long_short: gain = (t.price - self.tick.Close) * market_count else: gain = (self.tick.Close - t.price) * market_count self.account.profit = self.account.profit + gain SignalFactor().sign_trade_deal.emit( self.tick, long_short, market_count, gain) self.account.fee = self.account.fee + market_count t.count = t.count - market_count market_count = 0 tmp_trade.append(t) else: if long_short: gain = (t.price - self.tick.Close) * t.count else: gain = (self.tick.Close - t.price) * t.count self.account.profit = self.account.profit + gain self.account.fee = self.account.fee + t.count SignalFactor().sign_trade_deal.emit( self.tick, long_short, t.count, gain) market_count = market_count - t.count self.trade = tmp_trade else: if count > 0: if not price in self.market: self.market[price] = {} if not long_short in self.market[price]: self.market[price][long_short] = SimpleNamespace(count=0) self.market[price][long_short].count = self.market[price][ long_short].count + count SignalFactor().sign_trade_order_market_ret.emit( price, long_short, self.market[price][long_short].count) else: if price in self.market and long_short in self.market[price]: if self.market[price][long_short].count > 0: self.market[price][long_short].count = self.market[ price][long_short].count + count SignalFactor().sign_trade_order_market_ret.emit( price, long_short, self.market[price][long_short].count) if self.market[price][long_short].count == 0: del self.market[price][long_short]
def clickedOK(self): prodid = self.prodid.text() SettingFactor().setYahooProdId(prodid) SignalFactor().sign_yahoo_config_done.emit(True)