def getCloseAfter(date, stockname, days) -> [int]: stock = Stock.fromJson(loadStock(stockname)) if stock is None: return [] index = 0 for dayvalue in stock.dayvalues: if getTime(dayvalue.date) > date: break index += 1 index -= 1 results = [] for i in days: if index + i < len(stock.dayvalues): results.append(100 * (stock.dayvalues[index + i].close - stock.dayvalues[index].close) / stock.dayvalues[index].close) else: results.append(0) return results
def getTradeInfoAfter(date, stockname, days) -> [RangeTrend]: stock = Stock.fromJson(loadStock(stockname)) if stock is None: return [] index = 0 for dayvalue in stock.dayvalues: if getTime(dayvalue.date) > date: break index += 1 index -= 1 if index >= len(stock.dayvalues): return [] results = [] for i in days: if index + i < len(stock.dayvalues): trend = getRangeTrend(index, i, stock.dayvalues) results.append(trend) return results
def loadFromDB(): stocks = [] client = MongoClient('localhost', 27017) db = client["test"] coll = db['stocks'] results = coll.find({}, {'_id': 0}) for r in results: stocks.append(Stock.fromJson(r)) return stocks
def loadAllStockFromDB() -> Dict[str, Stock]: stocks = dict() items = DatabaseMgr.instance().stocks.find({}, {'_id': 0}) for item in items: if 'id' in item: print(item['id']) stockId = item['id'] stock = Stock.fromJson(item) stock.calcMinsAndMaxs() stocks[stockId] = stock return stocks
from data.stock import Stock from data.storemgr import StockMgr items = DatabaseMgr.instance().stocks.find({'id': '002807'}, {'_id': 0}) stock = None for item in items: if 'id' in item: # print(item['id']) stockId = item['id'] stock = Stock.fromJson(item) break value = stock.findHeighestValue('2017/1/1') value0 = stock.findLowestValue(value.date) value1 = stock.findHeighestValue(value0.date) if value1 is not None: if (value1.high - value0.low) / value0.open < 0.15: pass