Beispiel #1
0
 def async_save():
     Candle.insert(**d).on_conflict_ignore().execute()
     print(
         jh.color(
             'candle: {}-{}-{}: {}'.format(
                 jh.timestamp_to_time(d['timestamp']), exchange, symbol,
                 candle), 'blue'))
Beispiel #2
0
 def async_save() -> None:
     Candle.insert(**d).on_conflict_ignore().execute()
     print(
         jh.color(
             f"candle: {jh.timestamp_to_time(d['timestamp'])}-{exchange}-{symbol}: {candle}",
             'blue'
         )
     )
Beispiel #3
0
def fetch_candles_from_db(exchange: str, symbol: str, start_date: int,
                          finish_date: int) -> tuple:
    return tuple(
        Candle.select(Candle.timestamp, Candle.open, Candle.close, Candle.high,
                      Candle.low, Candle.volume).where(
                          Candle.timestamp.between(start_date, finish_date),
                          Candle.exchange == exchange,
                          Candle.symbol == symbol).order_by(
                              Candle.timestamp.asc()).tuples())
Beispiel #4
0
def store_candle_into_db(exchange: str, symbol: str, candle: np.ndarray, on_conflict='ignore') -> None:
    from jesse.models.Candle import Candle

    d = {
        'id': jh.generate_unique_id(),
        'symbol': symbol,
        'exchange': exchange,
        'timestamp': candle[0],
        'open': candle[1],
        'high': candle[3],
        'low': candle[4],
        'close': candle[2],
        'volume': candle[5]
    }

    if on_conflict == 'ignore':
        Candle.insert(**d).on_conflict_ignore().execute()
    elif on_conflict == 'replace':
        Candle.insert(**d).on_conflict(
            conflict_target=['timestamp', 'symbol', 'exchange'],
            preserve=(Candle.open, Candle.high, Candle.low, Candle.close, Candle.volume),
        ).execute()
    elif on_conflict == 'error':
        Candle.insert(**d).execute()
    else:
        raise Exception(f'Unknown on_conflict value: {on_conflict}')