def __init__(self, name: str, starting_assets: list, fee_rate: float, settlement_currency: str, futures_leverage_mode: str, futures_leverage: int): super().__init__(name, starting_assets, fee_rate, 'futures') self.futures_leverage_mode = futures_leverage_mode self.futures_leverage = futures_leverage for item in starting_assets: self.buy_orders[item['asset']] = DynamicNumpyArray((10, 2)) self.sell_orders[item['asset']] = DynamicNumpyArray((10, 2)) # make sure trading routes exist in starting_assets from jesse.routes import router for r in router.routes: base = jh.base_asset(r.symbol) if base not in self.assets: self.assets[base] = 0 self.temp_reduced_amount[base] = 0 if base not in self.buy_orders: self.buy_orders[base] = DynamicNumpyArray((10, 2)) if base not in self.sell_orders: self.sell_orders[base] = DynamicNumpyArray((10, 2)) self.starting_assets = self.assets.copy() self.available_assets = self.assets.copy() # start from 0 balance for self.available_assets which acts as a temp variable for k in self.available_assets: self.available_assets[k] = 0 self.settlement_currency = settlement_currency.upper()
def __init__(self, name: str, starting_assets: list, fee_rate: float, exchange_type: str, settlement_currency: str): self.name = name self.type = exchange_type.lower() for item in starting_assets: self.assets[item['asset']] = item['balance'] self.buy_orders[item['asset']] = DynamicNumpyArray((10, 2)) self.sell_orders[item['asset']] = DynamicNumpyArray((10, 2)) self.temp_reduced_amount[item['asset']] = 0 # margin only: make sure trading routes exist in starting_assets if self.type == 'margin': from jesse.routes import router for r in router.routes: base = jh.base_asset(r.symbol) if base not in self.assets: self.assets[base] = 0 if base not in self.buy_orders: self.buy_orders[base] = DynamicNumpyArray((10, 2)) if base not in self.sell_orders: self.sell_orders[base] = DynamicNumpyArray((10, 2)) if base not in self.temp_reduced_amount: self.temp_reduced_amount[base] = 0 self.starting_assets = self.assets.copy() self.available_assets = self.assets.copy() # in margin mode, start from 0 balance for self.available_assets # which acts as a temp variable if self.type == 'margin': for k in self.available_assets: self.available_assets[k] = 0 self.fee_rate = fee_rate self.settlement_currency = settlement_currency.upper()
def init_storage(self): """ """ for c in config['app']['considering_candles']: key = jh.key(c[0], c[1]) self.storage[key] = DynamicNumpyArray((60, 6), drop_at=120) self.temp_storage[key] = DynamicNumpyArray((100, 4))
def __init__(self, length: int, step=1): self.length = length self.index = 0 # validation if self.length <= self.index: raise ValueError('length must be greater than 0') self._time = time() self._execution_times = DynamicNumpyArray((3, 1), 3) self.step = step self.is_finished = False
def init_storage(self, bucket_size: int = 1000) -> None: for c in config['app']['considering_candles']: exchange, symbol = c[0], c[1] # initiate the '1m' timeframes key = jh.key(exchange, symbol, timeframes.MINUTE_1) self.storage[key] = DynamicNumpyArray((bucket_size, 6)) for timeframe in config['app']['considering_timeframes']: key = jh.key(exchange, symbol, timeframe) # ex: 1440 / 60 + 1 (reserve one for forming candle) total_bigger_timeframe = int((bucket_size / jh.timeframe_to_one_minutes(timeframe)) + 1) self.storage[key] = DynamicNumpyArray((total_bigger_timeframe, 6))
class Progressbar: def __init__(self, length: int, step=1): self.length = length self.index = 0 # validation if self.length <= self.index: raise ValueError('length must be greater than 0') self._time = time() self._execution_times = DynamicNumpyArray((3, 1), 3) self.step = step self.is_finished = False def update(self): if not self.is_finished: self.index += self.step if self.index == self.length: self.is_finished = True now = time() self._execution_times.append(np.array([now - self._time])) self._time = now @property def current(self): if self.is_finished: return 100 return round(self.index / self.length * 100, 1) @property def average_execution_seconds(self): return self._execution_times[:].mean() @property def remaining_index(self): if self.is_finished: return 0 return self.length - self.index @property def estimated_remaining_seconds(self): if self.is_finished: return 0 return self.average_execution_seconds * self.remaining_index / self.step def finish(self): self.is_finished = True
def init_storage(self): for c in config['app']['considering_candles']: key = jh.key(c[0], c[1]) self.temp_storage[key] = { 'last_updated_timestamp': None, 'asks': [], 'bids': [] } self.storage[key] = DynamicNumpyArray((60, 2, 50, 2), drop_at=60)
def init_storage(self) -> None: for c in config['app']['considering_candles']: key = jh.key(c[0], c[1]) self.storage[key] = DynamicNumpyArray((60, 5), drop_at=120)