def get(cls, user_name): with session_scope() as session: user = session.query(cls).filter( cls.user_name == user_name).first() if user is None: return None return user
def get_signal_events_by_count(cls, count, prduct_code=settings.product_code): with session_scope() as session: rows = session.query(cls).filter(cls.product_code == prduct_code).order_by(desc(cls.time)).limit(count).all() if rows is None: return [] rows.reverse() return rows
def get(cls, time): with session_scope() as session: log = session.query(cls).filter( cls.time == time).first() if log is None: return None return log
def get_fraction_candle(cls, product_code=settings.product_code): recent_time = cls.get_all_candles(limit=1)[0].time with session_scope() as session: table = factory_candle_class(product_code=product_code, duration=constants.DURATION_5S) candles = session.query(table).filter( table.time >= recent_time).order_by(desc(table.time)).all() if candles is None: return None time = candles[0].time high = candles[0].high low = candles[0].low close = candles[0].close open = candles[-1].open volume = 0 for i in range(len(candles)): high = max(candles[i].high, high) low = min(candles[i].low, low) volume += candles[i].volume candle = cls(time=time, open=open, close=close, high=high, low=low, volume=volume) return candle
def get(cls, time): with session_scope() as session: candle = session.query(cls).filter( cls.time == time).first() if candle is None: return None return candle
def create(cls, user_name, password): user = cls(user_name=user_name, password=GetHashValue(password)) try: with session_scope() as session: session.add(user) return user except IntegrityError: return False
def get_signal_events_after_time(cls, time): with session_scope() as session: rows = session.query(cls).filter(cls.time >= time).all() if rows is None: return [] return rows
def create(cls, time, name, message): log = cls(time=time,name=name,message=message,show=0) try: with session_scope() as session: session.add(log) return log except IntegrityError: return False
def get_all_users(cls, limit=100): with session_scope() as session: users = session.query(cls).order_by(asc( cls.user_id)).limit(limit).all() if len(users) == 0: return None return users
def get_all_logs(cls, limit=10): with session_scope() as session: logs = session.query(cls).order_by( desc(cls.time)).limit(limit).all() if len(logs) == 0: return None return logs
def get_all_candles(cls, limit=100): with session_scope() as session: candles = session.query(cls).order_by(desc( cls.time)).limit(limit).all() if candles is None: return None candles.reverse() return candles
def get_all_Show_logs(cls): with session_scope() as session: logs = session.query(cls).filter( cls.show == 0).order_by( desc(cls.time)).all() if len(logs) == 0: return None return logs
def create(cls, time, open, close, high, low, volume): candle = cls(time=time, open=open, close=close, high=high, low=low, volume=volume) try: with session_scope() as session: session.add(candle) return candle except IntegrityError: return False
def save(self): with session_scope() as session: session.add(self)
def DeleteAllRecord(cls): with session_scope() as session: logs = session.query(cls).all() for log in logs: session.delete(log)
def save(self): """ DBのローソク足を更新します。 """ with session_scope() as session: session.add(self)
def get_user_one_by_name(cls, user_name): with session_scope() as session: user = session.query(cls).filter( cls.user_name == user_name).one_or_none() return user
def DeleteAllRecord(cls): with session_scope() as session: users = session.query(cls).all() for user in users: session.delete(user)