Example #1
0
    def group_by_sector(self,username):
    
        t_dao=Transaction_dao()
        c_dao=Company_dao()
        distinct_stocks=t_dao.get_user_stock_list(username)

    
        sector_volume={}
        
        for symbol in distinct_stocks:
            company_info=c_dao.get_company_model(symbol)
            volume=t_dao.get_owned_stock_model(username,symbol,company_info.get_ask()).get_volume()

            try:
                sector=self.get_sector_by_symbol(symbol);
                if(sector.strip()==''):sector="Other"
            except:
                sector="Other"
                
            
            if(sector not in sector_volume):
                sector_volume[sector]=volume;
            else:
                sector_volume[sector]+=volume
        
        return sector_volume;
Example #2
0
    def group_by_sector(self, username):

        t_dao = Transaction_dao()
        c_dao = Company_dao()
        distinct_stocks = t_dao.get_user_stock_list(username)

        sector_volume = {}

        for symbol in distinct_stocks:
            company_info = c_dao.get_company_model(symbol)
            volume = t_dao.get_owned_stock_model(
                username, symbol, company_info.get_ask()).get_volume()

            try:
                sector = self.get_sector_by_symbol(symbol)
                if (sector.strip() == ''): sector = "Other"
            except:
                sector = "Other"

            if (sector not in sector_volume):
                sector_volume[sector] = volume
            else:
                sector_volume[sector] += volume

        return sector_volume
class fifty_vs_two_hund_mving_avg:

    def __init__(self, active_algorithms_list):
        self.moving_list = None
	self.t = Transaction_dao()
	self.c = Company_dao()
	for aam in active_algorithms_list:
            if aam.get_algo_id() == "3":
		if self.moving_list == None:
		    self.moving_list = self.c.get_moving_average()
		if self.moving_list: 
        	    self.algorithm(aam.get_user())
		

    def algorithm(self, username):
	owned_stocks = self.t.get_user_stock_list(username)
	for moving in self.moving_list:
	    symbol = moving.get_symbol()
	    if owned_stocks:
	        if symbol in owned_stocks:
		    if moving.get_fifty_day_ask() > moving.get_two_hundred_day_ask():
		        transaction(username, 1, symbol, "sell", "3")
		if symbol not in owned_stocks:	
		    if moving.get_fifty_day_ask() < moving.get_two_hundred_day_ask():
		        transaction(username, 1, symbol, "buy", "3")
	    else:
		if moving.get_fifty_day_ask() < moving.get_two_hundred_day_ask():
		        transaction(username, 1, symbol, "buy", "3")
class fifty_vs_two_hund_mving_avg:
    def __init__(self, active_algorithms_list):
        self.moving_list = None
        self.t = Transaction_dao()
        self.c = Company_dao()
        for aam in active_algorithms_list:
            if aam.get_algo_id() == "3":
                if self.moving_list == None:
                    self.moving_list = self.c.get_moving_average()
                if self.moving_list:
                    self.algorithm(aam.get_user())

    def algorithm(self, username):
        owned_stocks = self.t.get_user_stock_list(username)
        for moving in self.moving_list:
            symbol = moving.get_symbol()
            if owned_stocks:
                if symbol in owned_stocks:
                    if moving.get_fifty_day_ask(
                    ) > moving.get_two_hundred_day_ask():
                        transaction(username, 1, symbol, "sell", "3")
                if symbol not in owned_stocks:
                    if moving.get_fifty_day_ask(
                    ) < moving.get_two_hundred_day_ask():
                        transaction(username, 1, symbol, "buy", "3")
            else:
                if moving.get_fifty_day_ask() < moving.get_two_hundred_day_ask(
                ):
                    transaction(username, 1, symbol, "buy", "3")
    elif portfolio_filter == '0':
        filter_flag = "USER"
    else:
        filter_flag = portfolio_filter

tdao = Transaction_dao()
u2 = User_stock_value_dao()
u1 = User_portfolio_dao()
cdao = Company_dao()
hdao = History_dao()

data = {}

if filter_flag == "ALL":
    t = hdao.select_all(username)
    l = tdao.get_user_stock_list(username)
elif filter_flag == "ALGOS":
    t = hdao.select_all_algo_trades(username)
    l = tdao.get_all_algo_stock_list(username)
elif filter_flag == "USER":
    t = hdao.select_all_user_trades(username)
    l = tdao.get_only_user_stock_list(username)
else:
    t = hdao.select_algo_trades(username, filter_flag)
    l = tdao.get_algo_stock_list(username, filter_flag)

# HISTORY
if t:
    data['transactions'] = {}

    for i in range(len(t)):
#!/usr/bin/python

import cgi, LINK_HEADERS, sys
import simplejson as json
sys.path.insert(0, str(LINK_HEADERS.DAO_LINK))
from transaction_dao import Transaction_dao
from company_dao import Company_dao

print "Content-Type: text/html\r\n\r\n"

form=cgi.FieldStorage()

if form.getvalue("user_name") != None:
    username=form.getvalue("user_name")

#test
#username='******'
tdao=Transaction_dao()
owned_stock_list=tdao.get_user_stock_list(username)
print json.dumps(owned_stock_list)
    elif portfolio_filter == '0':
        filter_flag = "USER"
    else:
        filter_flag = portfolio_filter
        
tdao = Transaction_dao()
u2 = User_stock_value_dao()
u1 = User_portfolio_dao()
cdao = Company_dao()
hdao = History_dao()

data={}

if filter_flag == "ALL":
    t = hdao.select_all(username)
    l = tdao.get_user_stock_list(username)
elif filter_flag == "ALGOS":
    t = hdao.select_all_algo_trades(username)
    l = tdao.get_all_algo_stock_list(username)
elif filter_flag == "USER":
    t = hdao.select_all_user_trades(username)
    l = tdao.get_only_user_stock_list(username)
else:
    t = hdao.select_algo_trades(username, filter_flag)
    l = tdao.get_algo_stock_list(username, filter_flag)


# HISTORY
if t:
    data['transactions']={}
    
Example #8
0
#!/usr/bin/python

import cgi, LINK_HEADERS, sys
import simplejson as json
sys.path.insert(0, str(LINK_HEADERS.DAO_LINK))
from transaction_dao import Transaction_dao
from company_dao import Company_dao

print "Content-Type: text/html\r\n\r\n"

form = cgi.FieldStorage()

if form.getvalue("user_name") != None:
    username = form.getvalue("user_name")

#test
#username='******'
tdao = Transaction_dao()
owned_stock_list = tdao.get_user_stock_list(username)
print json.dumps(owned_stock_list)