def __init__(self, *args, **kwargs): wx.Frame.__init__(self, size=(1000, 700), *args, **kwargs) self.currentsymbol = "" self.changestr = "" self.changeperc = "" self.companyname = "Press 'Plot Data' to update" self.timabil = 200 self.delta = 20 self.mgr = wx.aui.AuiManager(self) self.leftpanel = wx.Panel(self, -1, size=(100, 150)) self.rightpanel = wx.Panel(self, -1, size=(200, 150)) self.toppanel = wx.Panel(self, -1, size=(200, 100)) self.topleftpanel = wx.Panel(self, -1, size=(200, 100)) self.buypanel = wx.Panel(self, -1, size=(200, 100)) self.newspanel = wx.Panel(self, -1, size=(200, 30)) self.btn1 = wx.Button(self.toppanel, label="Plot Data") self.Bind(wx.EVT_BUTTON, self.GetData, self.btn1) self.periodText = wx.StaticText(self.toppanel, -1, "Viewing period:") self.period = wx.TextCtrl(self.toppanel, -1, "", size=(75, -1)) self.avgText = wx.StaticText(self.toppanel, -1, "Moving average period:") self.avg = wx.TextCtrl(self.toppanel, -1, "", size=(75, -1)) self.inputsizer = wx.FlexGridSizer(cols=3, hgap=6, vgap=6) self.days1 = wx.StaticText(self.toppanel, -1, "days") self.days2 = wx.StaticText(self.toppanel, -1, "days") self.lamefix = wx.StaticText(self.toppanel, -1, "") self.inputsizer.AddMany( [self.periodText, self.period, self.days1, self.avgText, self.avg, self.days2, self.lamefix, self.btn1] ) # Text box which displays main info about selected symbol self.maintext = wx.StaticText(self.topleftpanel, size=(350, 25)) self.maintext.SetFont(wx.Font(18, wx.ROMAN, wx.NORMAL, wx.NORMAL)) self.hbox = wx.BoxSizer(wx.VERTICAL) self.hbox.Add(self.maintext) self.hbox.Add(self.inputsizer) self.toppanel.SetSizer(self.hbox) menubar = wx.MenuBar() menufile = wx.Menu() menuhelp = wx.Menu() quit = wx.MenuItem(menufile, 115, "&Quit\tCtrl+Q", "Quit the Application") self.Bind(wx.EVT_MENU, self.OnClose, quit) menufile.AppendItem(quit) getandplot = wx.MenuItem(menufile, 105, "&Plot\tCtrl+P", "Plot data") self.Bind(wx.EVT_MENU, self.GetData, getandplot) menufile.AppendItem(getandplot) about = wx.MenuItem(menufile, 137, "&About", "About this application") self.Bind(wx.EVT_MENU, self.OnAbout, about) menuhelp.AppendItem(about) menubar.Append(menufile, "&File") menubar.Append(menuhelp, "&Help") self.SetMenuBar(menubar) # Biglist : list of lists of each symbol + corporation name # symbolist : list of all nasdaq symbols self.biglist = splitsymbols.readsymbols("nasdaqlist.txt") symbolist = [] for i in range(1, len(self.biglist) - 1): symbol = self.biglist[i][0] symbolist.append(symbol) self.slist = wx.ListBox(self.leftpanel, 42, wx.DefaultPosition, (100, 100), symbolist) self.Bind(wx.EVT_LISTBOX, self.OnSymbolSelect, id=42) # Image canvas for historical plot of selected symbol self.dpi = 100 self.fig = Figure((5.0, 4.0), dpi=self.dpi) self.fig.subplots_adjust(bottom=0.15) self.fig.suptitle( "Please select a ticker\n on from the list on the left\n Press 'Plot Data' for graph", fontsize=20 ) self.canvas = FigCanvas(self.rightpanel, -1, self.fig) # One rows, two columns self.gs = gridspec.GridSpec(2, 1, height_ratios=[3, 1.5]) # Newsfeed things self.newsbtn1 = wx.Button(self.newspanel, label="Next", pos=(90, 3)) self.newsbtn2 = wx.Button(self.newspanel, label="Previous", pos=(0, 3)) self.Bind(wx.EVT_BUTTON, self.SwitchNewsNext, self.newsbtn1) self.Bind(wx.EVT_BUTTON, self.SwitchNewsPrevious, self.newsbtn2) self.newsnumber = wx.StaticText(self.newspanel, size=(350, 20), pos=(190, 4)) self.newsnumber.SetFont(wx.Font(16, wx.ROMAN, wx.NORMAL, wx.NORMAL)) self.newsnumber.SetLabel("1/20") self.newstitle = wx.StaticText(self.newspanel, size=(350, 20), pos=(360, 4)) self.newstitle.SetFont(wx.Font(16, wx.ROMAN, wx.NORMAL, wx.NORMAL)) self.newstoshow = 0 try: self.newsholder = rss_get_news.pull_titles_and_links(rss_get_news.fetch("goog")) self.newstitle.SetLabel(self.newsholder[0][self.newstoshow]) except: self.NoInternetConnection() self.newsholder = "no internet connection" self.hyper1 = hl.HyperLinkCtrl( self.newspanel, -1, "Click here to read.", pos=(245, 7), URL=self.newsholder[1][self.newstoshow] ) # *** Sizer for rightpanel *** self.sizer_for_rightpanel = wx.BoxSizer(wx.VERTICAL) # sizer_for_rightpanel is a new sizer self.sizer_for_rightpanel.Add( self.canvas, 1, wx.GROW ) # add things that are in the rightpanel to the sizer with wanted attribute (here: wx.GROW) self.rightpanel.SetSizer(self.sizer_for_rightpanel) # set the sizer as default sizer for rightpanel # *** Sizer for rightpanel *** # *** Sizer for leftpanel *** self.sizer_for_leftpanel = wx.BoxSizer(wx.VERTICAL) # sizer_for_leftpanel is a new sizer self.sizer_for_leftpanel.Add( self.slist, 1, wx.GROW ) # add things that are in the leftpanel to the sizer with wanted attribute (here: wx.GROW) self.leftpanel.SetSizer(self.sizer_for_leftpanel) # set the sizer as default sizer for leftpanel # *** Sizer for leftpanel *** self.mgr.AddPane(self.leftpanel, wx.aui.AuiPaneInfo().Left().CloseButton(False).Caption("Corporation tickers")) self.mgr.AddPane( self.rightpanel, wx.aui.AuiPaneInfo().Center().Layer(1).CloseButton(False).Caption("rightpanel").CaptionVisible(False), ) self.mgr.AddPane(self.buypanel, wx.aui.AuiPaneInfo().Top().Layer(1).CloseButton(False).Caption("Buy or Sell")) self.mgr.AddPane(self.toppanel, wx.aui.AuiPaneInfo().Top().Layer(1).CloseButton(False).Caption("Plot controls")) self.mgr.AddPane( self.topleftpanel, wx.aui.AuiPaneInfo().Top().Layer(1).CloseButton(False).Caption("Corporation name") ) self.mgr.AddPane(self.newspanel, wx.aui.AuiPaneInfo().Bottom().Layer(3).CloseButton(False).Caption("News")) # Buy/Sell Panel self.buytxt = wx.StaticText(self.buypanel, 46, "Stocks for \n" + self.companyname) self.buytxt.SetFont(wx.Font(18, wx.ROMAN, wx.NORMAL, wx.NORMAL)) self.buyorsell = wx.TextCtrl(self.buypanel, 46, "SELL or BUY?", size=(300, -1)) self.buyorsell.SetFont(wx.Font(18, wx.ROMAN, wx.NORMAL, wx.NORMAL)) self.buysizer = wx.FlexGridSizer(cols=2, hgap=1, vgap=6) self.buysizer.AddMany([self.buytxt, self.buyorsell]) self.buypanel.SetSizer(self.buysizer) # Buy/Sell Panel self.vbox = wx.BoxSizer(wx.VERTICAL) self.vbox.Add(self.buytxt) self.vbox.Add(self.buyorsell) self.buypanel.SetSizer(self.vbox) self.mgr.Update()
def OnSymbolSelect(self, event): self.currentsymbol = event.GetString() self.currentvalue = event.GetSelection() try: # update newspanel self.newsholder = rss_get_news.pull_titles_and_links(rss_get_news.fetch(self.currentsymbol)) self.newstoshow = 0 self.UpdateNewsPanel() # update newspanel except: self.NoInternetConnection() return # Quick Info now = date.today() dagsetn_nuna = now.strftime("%Y%m%d") then = date.today() - timedelta(5) dagsetn_tha = then.strftime("%Y%m%d") try: self.lastpricelist = ystockquote.get_historical_prices(self.currentsymbol, dagsetn_tha, dagsetn_nuna) except: if self.currentsymbol == "": self.SelectTicker() else: self.NoInternetConnection() return lastprice = float(self.lastpricelist[1][6]) # print(self.lastpricelist) self.currentprice = float(ystockquote.get_price(self.currentsymbol)) change = self.currentprice - lastprice change = round(change, 2) if change < 0: self.changestr = str(change) self.changeperc = str(round((change / lastprice) * 100, 2)) + "%" else: self.changestr = "+" + str(change) self.changeperc = "(" + str(round((change / lastprice) * 100, 2)) + "%" + ")" # Writes ticker and name of company self.companyname = self.biglist[self.currentvalue + 1][1].split("-")[0] self.maintext.SetLabel(self.companyname) # Deletes previous stockpricetext object ( no clear option, has to be rebuilt ) try: self.stockpricetext.Destroy() except: pass self.stockpricetext = wx.StaticText(self.topleftpanel, pos=(0, 40), size=(100, 20), style=wx.TE_READONLY) self.stockpricetext.SetFont(wx.Font(16, wx.ROMAN, wx.NORMAL, wx.NORMAL)) self.stockpricetext.SetLabel(" ") if float(self.changestr) > 0: # self.stockpricetext.SetLabel(' ') self.stockpricetext.SetForegroundColour((0, 200, 0)) # set text color elif float(self.changestr) < 0: # self.stockpricetext.SetLabel(' ') self.stockpricetext.SetForegroundColour((200, 0, 0)) # set text color self.stockpricetext.SetLabel(str(self.currentprice) + " " + self.changestr + " " + self.changeperc)