Пример #1
0
 def __get_stock_list(self):
     collection = Collection(Constants.BASIC_COLLECTION, self.__db)
     stock_infos = collection.find()
     stock_list = []
     for stock_info in stock_infos:
         stock_list.append(stock_info['code'])
     return stock_list
Пример #2
0
 def __get_data(self, stock_code, start, end):
     collection = Collection(stock_code, self.__data_db)
     start_date = datetime.strptime(start, '%Y-%m-%d')
     end_date = datetime.strptime(end, '%Y-%m-%d')
     result = {}
     for record in collection.find().sort('date', pymongo.ASCENDING):
         record_date = datetime.strptime(record['date'], '%Y-%m-%d')
         if record_date >= (start_date - timedelta(
                 days=self.DEFAULT_BAR_PERIOD)) and record_date <= end_date:
             result[record['date']] = record
         if record_date > end_date:
             break
     return OrderedDict(sorted(result.items(), key=lambda t: t[0]))
Пример #3
0
    def __decide_realtime(self, context, stock_code):
        data = context.get_realtime_data(stock_code)
        result = []

        buy_one = data['buyOne']
        sell_one = data['sellOne']
        turnover = data['turnoverRate']

        collection = Collection(stock_code, self.__db)
        last_data = collection.find_one('date')
        if not last_data:
            raise EmptyHistoryDataException('not found stock(%r) history data' % stock_code)

        ma5 = last_data['ma5']
        ma10 = last_data['ma10']

        if self.__should_buy(buy_one, ma10, turnover):
            return self.BUY_IN
        elif self.__should_sell(sell_one, ma10):
            return self.SELL_OUT
        return self.DO_NOTHING
Пример #4
0
    def decide(self, current_info):
        if not current_info:
            return 'sorry, current info is invalid.'

        stock_code = current_info['code']
        buy_one = current_info['buy_one']
        sell_one = current_info['sell_one']
        turnover = current_info['turnover']

        collection = Collection(stock_code, self.__db)
        last_data = collection.find_one('date')
        if not last_data:
            return 'not found history data.'
        ma_5 = last_data['ma5']
        ma_10 = last_data['ma10']
        ma_20 = last_data['ma20']
        if self.__should_buy(buy_one, ma_10) == True:
            return 'you should buy now.'
        if self.__should_sell(sell_one, ma_10) == True:
            return 'you should sell now.'
        return 'you hold, do nothing.'
Пример #5
0
 def __init__(self, stock_code, db):
     self.__stock_code = stock_code
     self.__db = db
     self.__collection = Collection(stock_code, self.__db)
     self.__hist_close_price = []
Пример #6
0
 def __init__(self, stock_code, db):
     self.__stock_code = stock_code
     self.__db = db
     self.__collection = Collection(stock_code, self.__db)
Пример #7
0
 def __init__(self, db):
     self.__db = db
     self.__collection = Collection(Constants.BASIC_COLLECTION, self.__db)