Ejemplo n.º 1
0
	def update_flow(self, index):
		db = stockdb.stockdb()
		flow = self.__read_flow(index)
		size = len(flow)
		manager = stockmanager.stockmanager()
		days = manager.get_stock_index(index)
		for i, item in enumerate(days):
			if i < size:
				continue
			day = item[0].split('-')
			year = string.atoi(day[0])
			month = string.atoi(day[1])
			day = string.atoi(day[2])
			new = manager.get_stock_detailed(index, year, month, day)
			if new == []:
				print 'BUG(miss data): ' + str(year) + str(month) + str(day)
				parser = stockparser.stock_parser()
				detail = parser.get_detailed_exchange(index, year, month, day)
				if len(detail) > 0:
					db.write_data_day(index, detail, year, month, day)
					new = manager.get_stock_detailed(index, year, month, day)
					print 'Fixed OK!'
			record = []
			record.append(item[0])
			if new != []:
				sum, all, big, sl, sh, el, eh = self.cal_flow(new, item[1], item[2])
				record.append(str(sum))
				record.append(str(all))
				record.append(str(big))
				record.append(str(sl))
				record.append(str(sh))
				record.append(str(el))
				record.append(str(eh))
			flow.append(record)
		db.write_data_flow(index, flow)
Ejemplo n.º 2
0
def get_sort_cl(index):
    db = stockdb.stockdb()
    name = str(index) + ".bin"
    data = db.read_data_crf(name)
    if data == "":
        return []
    list = data.split("\n")
    ret = []
    for line in list:
        cos = line.split(",")
        ret.append(cos)
    return ret
Ejemplo n.º 3
0
	def __read_flow(self, index):
		db = stockdb.stockdb()
		data = db.read_data_flow(index)
		if data == '':
			return []
		list = data.split('\n')
		ret = []
		for line in list:
			day_flow = line.split(',')
			ret.append(day_flow)
		ret.sort(cmp = lambda x,y: cmp(x[0],y[0]))
		return ret
Ejemplo n.º 4
0
def get_sort(up_sort):
    db = stockdb.stockdb()
    data = db.read_data_crf("vol_sort")
    list = data.split("\n")
    ret = []
    for line in list:
        day_exchange = line.split(",")
        day_exchange[1] = string.atoi(day_exchange[1])
        ret.append(day_exchange)
    if up_sort == 1:
        ret.sort(cmp=lambda x, y: cmp(x[1], y[1]))
    else:
        ret.sort(cmp=lambda x, y: cmp(x[1], y[1]), reverse=True)
    return ret
Ejemplo n.º 5
0
#!/usr/bin/python
#!coding=utf-8
import stocksort
import stockdb
db = stockdb.stockdb()
list = stocksort.get_vol()
db.write_data_crf('vol_sort', list)
Ejemplo n.º 6
0
class stockmanager():
    parser = stockparser.stock_parser()
    db = stockdb.stockdb()
    macd = macd.macd()
    kdj = kdj.kdj()
    boll = boll.boll()
    ma = ma.ma()
    volume_ma = volume_ma.volume_ma()
    price_range = price_range.price_range()
    volume_range = volume_range.volume_range()
    closeprice_range = closeprice_range.closeprice_range()
    kline = kline.kline()

    def cal_macd(self, list):
        return self.macd.cal_macd(list)

    def cal_kdj(self, list):
        return self.kdj.cal_kdj(list)

    def cal_boll(self, list):
        return self.boll.cal_boll(list)

    def cal_ma(self, list):
        return self.ma.cal_ma(list)

    def cal_volume_ma(self, list):
        return self.volume_ma.cal_ma(list)

    def cal_price_range(self, list):
        return self.price_range.cal_range(list)

    def cal_volume_range(self, list):
        return self.volume_range.cal_range(list)

    def cal_closeprice_range(self, list):
        return self.closeprice_range.cal_range(list)

    def cal_kline(self, list):
        return self.kline.cal_kline(list)

    def get_stock_list(self):
        return self.parser.get_stock_list()

    def __get_stock_index_jidu(self, name, year, jidu):
        data = self.db.read_data_jidu(name, year, jidu)
        if len(data) <= 0:
            return []
        list = data.split('\n')
        ret = []
        for line in list:
            day_exchange = line.split(',')
            start = string.atof(day_exchange[1])
            end = string.atof(day_exchange[3])
            low = string.atof(day_exchange[4])
            high = string.atof(day_exchange[2])
            day_exchange[1] = start
            day_exchange[2] = end
            day_exchange[3] = low
            day_exchange[4] = high
            day_exchange[5] = string.atoi(day_exchange[5])
            day_exchange[6] = string.atoi(day_exchange[6])
            ret.append(day_exchange)
        return ret

    def get_stock_index(self, name):
        today = stockutils.get_date().split('-')
        start = stockconfig.FIG_START_DAY.split('-')
        start_year = string.atoi(start[0])
        start_jidu = (string.atoi(start[1]) + 2) / 3
        end_year = string.atoi(today[0])
        end_jidu = (string.atoi(today[1]) + 2) / 3
        index = []
        while True:
            data = self.__get_stock_index_jidu(name, start_year, start_jidu)
            index.extend(data)
            if (start_year == end_year) and (start_jidu == end_jidu):
                break
            start_year, start_jidu = stockutils.next_jidu(
                start_year, start_jidu)
        return index
Ejemplo n.º 7
0
class stockroot():
    parser = stockparser.stock_parser()
    db = stockdb.stockdb()
    thread_num = stockconfig.FIG_THREAD_NUM
    started = False

    def set_thread_num(self, num):
        self.thread_num = num

    def start(self):
        self.started = True

    def stop(self):
        self.started = False

    def __splite_task(self, list):
        task = []
        for i in range(0, self.thread_num):
            task.append([])
        seed = 0
        for stock in list:
            task[seed % self.thread_num].append(stock)
            seed = seed + 1
        return task

    def __get_next_day_by_sh(self, year, jidu, day_string):
        list = self.parser.get_index_list('000001', year, jidu,
                                          0)  #sh000001 index
        if len(list) == 0:
            return ''
        if cmp(list[0][0], day_string) > 0:
            last = ''
            for item in list:
                if cmp(item[0], day_string) <= 0:
                    return last
                last = item[0]
            return last
        return ''

    def __get_year_jidu(self, day_string):
        day = day_string.split('-')
        year = string.atoi(day[0])
        month = string.atoi(day[1])
        jidu = (month + 2) / 3
        return year, jidu

    def __is_same_jidu(self, day1, day2):
        year1, jidu1 = self.__get_year_jidu(day1)
        year2, jidu2 = self.__get_year_jidu(day2)
        if year1 == year2 and jidu1 == jidu2:
            return True
        else:
            return False

    def __get_next_day(self, today):
        year, jidu = self.__get_year_jidu(today)
        next = self.__get_next_day_by_sh(year, jidu, today)
        if next == '':
            year, next_jidu = stockutils.next_jidu(year, jidu)
            next = self.__get_next_day_by_sh(year, next_jidu, today)
        return next

    def __real_update(self, list, day, update_jidu):
        print day + '-' + str(update_jidu)
        threadx = []
        id = 1
        for item in list:
            task = taskthread(item, day, update_jidu, id, self.parser, self.db)
            task.start()
            threadx.append(task)
            id = id + 1
        for item in threadx:
            item.join()
        year, jidu = self.__get_year_jidu(day)
        sh = self.parser.get_index_list('000001', year, jidu, 0)
        self.db.write_data_jidu('sh000001', sh, year, jidu)
        sz = self.parser.get_index_list('399001', year, jidu, 0)
        self.db.write_data_jidu('sz399001', sh, year, jidu)
        print 'update--------------ok'

    def looper(self):
        last_jidu_update_day = '0000-00-00'
        task_list = []
        while self.started == True:
            today = stockutils.get_date()
            last = self.db.get_last_update_day()
            if cmp(today, last):
                next = self.__get_next_day(last)
                if next != '':
                    update_jidu = False
                    current_jidu = self.__is_same_jidu(next, today)
                    same_jidu = self.__is_same_jidu(next, last_jidu_update_day)
                    if current_jidu == True or same_jidu == False:
                        list = self.parser.get_stock_list()
                        task_list = self.__splite_task(list)
                        last_jidu_update_day = next
                        update_jidu = True
                    self.__real_update(task_list, next, update_jidu)
                    self.db.update_last_update_day(next)
                else:
                    time.sleep(1800)
            else:
                time.sleep(1800)

    def get_last_update_day(self):
        return self.db.get_last_update_day()

    def set_last_update_day(self, day):
        self.db.update_last_update_day(day)