示例#1
0
def Feeder(stock):
	'''
	Feeder(list(stock)) -> last price and volume

	stock: list if stock codes
	'''
	print 'Starting Systems'
	phantomJS = Conf().get('SYS', 'phantomJS')
	webdriver.DesiredCapabilities.PHANTOMJS['phantomjs.page.customHeaders.User-Agent'] = 'Mozilla/5.0 (X11; Linux i686; rv:25.0) Gecko/20100101 Firefox/25.0'
	d = webdriver.PhantomJS(phantomJS)
	L = 'http://www.tadawul.com.sa'
	print 'Connecting...'
	d.get(L)
	stock_market_link = d.find_element_by_link_text('سوق الاسهم').click()
	all_stocks_link = d.find_element_by_link_text('جميع الأسهم').click()
	todays_all_stocks_link = d.find_element_by_link_text('جميع الأسهم اليوم').click()
	find_all = d.find_elements_by_class_name('calibri-12')
	print 'Fetching...'
	configGet = Config('Get')
	print stock
	for ii, i in zip(configGet.sections(), stock):
		print find_all[int(i)+15].text, ii, i
		if configGet.has_section(ii) == True:
				last_price = find_all[int(i)+15].text
				last_vol =  find_all[int(i)+1].text
				SetLast('Price', last_price, ii)
	d.close()
示例#2
0
def SetLastData(stock_name, last_price):
	config = Config('Set')[1]
	configFile = Config('Set')[0]
	config.set(stock_name,'last_price', last_price)
	#config.set(stock_name,'last_volume', last_volume)
	config.write(configFile)
示例#3
0
    def buy(self):
        stocks = GetList('All')
        my_stocks = GetConfig('code')[0]
        my_shares = GetConfig('shares')[1]
        config = Config('Get')
        buy_log = open('log/buy.log', 'a')


        code_list  = npyscreen.Form(name = "Buy Code Or List",)

        pick  = code_list.add(npyscreen.TitleFixedText, name = "Please choose an option",)
        option = code_list.add(npyscreen.TitleSelectOne, max_height =-2, value = [1,], name="Option",
                values = ["Tadawul Code","Choose From List"], scroll_exit=True)
        code_list.edit()

        if str(option.get_selected_objects()) == "['Choose From List']":

            list_  = npyscreen.Form(name = "Buy - List",)
            stock = list_.add(npyscreen.TitleSelectOne, max_height=30, value = [1,], name="Stocks", values = stocks, scroll_exit=True)
            shares = list_.add(npyscreen.TitleText, name = "Shares:",)
            price = list_.add(npyscreen.TitleText, name = "Price:",)
            date = list_.add(npyscreen.TitleDateCombo, name = "Date:")

            list_.edit()

            code = str(stock.get_selected_objects())
            code_re = re.findall('[0-9]{1,}', code)[0]

            if re.findall('[\w]{1,}', code)[0] in config.sections():
                section = re.findall('[\w]{1,}', code)[0]
                aval = Config('Get').get(section, 'shares')
                current_shares = int(aval) + int(shares.value)

                SetLast('Shares', current_shares, section)
                SetLast('Last_Buying_Price', price.value, section)
                SetLast('Last_Purchase_Date', date.value, section)

            else:    
                SetConfig(stock_name=GetData(code=code_re, sector=TadawulStocks('All'))[0],
                          code=code_re,
                          shares=shares.value,
                          last_buying_price=price.value,
                          last_purchase_date=date.value,
                          last_price=1)

            stock_code = code_re

            
        elif str(option.get_selected_objects()) == "['Tadawul Code']":

            code = npyscreen.Form(name = "Buy - List",)
            stock = code.add(npyscreen.TitleText, name = "Code:",)
            shares = code.add(npyscreen.TitleText, name = "Shares:",)
            price = code.add(npyscreen.TitleText, name = "Price:",)
            date = code.add(npyscreen.TitleDateCombo, name = "Date:",)

            code.edit()

            if re.findall('[\w]{1,}', GetData(code=stock.value, sector=TadawulStocks('All'))[0])[0] in config.sections():
                section = re.findall('[\w]{1,}', GetData(code=stock.value, sector=TadawulStocks('All'))[0])[0]
                aval = Config('Get').get(section, 'shares')
                current_shares = int(aval) + int(shares.value)

                SetLast('Shares', current_shares, section)
                SetLast('Last_Buying_Price', price.value, section)
                SetLast('Last_Purchase_Date', date.value, section)
            else:
            
                SetConfig(stock_name=GetData(code=stock.value, sector=TadawulStocks('All'))[0],
                          code=stock.value,
                          shares=shares.value,
                          last_buying_price=price.value,
                          last_purchase_date=date.value,
                          last_price=1)

            stock_code = stock.value

        total = float(shares.value) * float(price.value)
        string = "%s - You Bought %s shares of %s for %s SAR per share. %s SAR in total." %(date.value, shares.value, GetData(code=stock_code, sector=TadawulStocks('All'))[0], price.value, str(total))
        buy_log.write(string+'\n')
        buy_log.close()