def print_order_book(self, prefix=''): if prefix != '': print('\n{}:'.format(prefix)) print('Bids: {}\nBids_price: {}\nBids_amount: {}\nBids_time: {}' \ '\nAsks: {}\nAsks_price: {}\nAsks_amount: {}\nAsks_time: {}'.format( self.bids, self.bids_price, self.bids_amount, MyDate.get_date_time_from_epoch_seconds(self.bids_ts), self.asks, self.asks_price, self.asks_amount, MyDate.get_date_time_from_epoch_seconds(self.asks_ts) ))
def __print_time_stamps__(tick_end_time_stamp: float, last_refresh_time_stamp: float): flag = tick_end_time_stamp >= last_refresh_time_stamp if not flag: return date_time_end = MyDate.get_date_time_from_epoch_seconds( tick_end_time_stamp) date_time_last_refresh = MyDate.get_date_time_from_epoch_seconds( last_refresh_time_stamp) print( 'was_any_wave_finished_since_time_stamp = {}: tick_end = {} / {} = last_refresh' .format(flag, date_time_end, date_time_last_refresh))
def __add_expected_trading_end_to_dict__(self, return_dict: dict): if self.function_cont.f_var_cross_f_upper_f_lower > 0: date_forecast = MyDate.get_date_time_from_epoch_seconds(self.function_cont.f_var_cross_f_upper_f_lower) if self.sys_config.period == PRD.INTRADAY: return_dict['Expected exchange_config end'] = str(date_forecast.time())[:5] else: return_dict['Expected exchange_config end'] = str(date_forecast.date())
def __init__(self, api: TradingBoxApi): self.box_type = '' self._api = api self._data_dict = api.data_dict self._pattern_type = self._data_dict[DC.PATTERN_TYPE] self._ticker_id = self._data_dict[DC.TICKER_ID] self._off_set_value = api.off_set_value # basis for distance_top and _bottom self._buy_price = api.buy_price self._sma_value = 0 # simple moving average value for this strategy self._trade_strategy = api.trade_strategy self._ticker_last_price_list = [ api.off_set_value, api.buy_price ] # off_set is used to guarantee: max >= offset self._ticker_last_price = api.buy_price self._height = self.round(api.height) self._time_stamp_end = self.__get_time_stamp_end__() self._date_time_end = MyDate.get_date_time_from_epoch_seconds( self._time_stamp_end) self._distance_bottom = api.distance_bottom self._distance_top = 0 self._stop_loss_orig = 0 self._stop_loss = 0 self._sell_limit_orig = 0 self._sell_limit = 0 self._init_parameters_() self.__calculate_stops_and_limits__() self._price_was_close_to_stop = False self._small_profit_taking_active = api.small_profit_taking_active self._small_profit_taking_parameters = api.small_profit_taking_parameters self._was_adjusted_to_small_profit_taking = False
def fill_asset_gaps(self, ts_last: int, ts_to: int, ts_interval: int): access_layer_stocks = AccessLayer4Stock(self.db_stock) last_asset_query = 'SELECT * FROM asset WHERE Validity_Timestamp={}'.format( ts_to) df_last_asset = AccessLayer4Asset( self.db_stock).select_data_by_query(last_asset_query) ts_actual = ts_last + ts_interval while ts_actual < ts_to: dt_saving = str(MyDate.get_date_time_from_epoch_seconds(ts_actual)) for index, asset_row in df_last_asset.iterrows(): equity_type = asset_row[DC.EQUITY_TYPE] asset = asset_row[DC.EQUITY_NAME] amount = asset_row[DC.QUANTITY] value_total = asset_row[DC.VALUE_TOTAL] balance = Balance('exchange', asset, amount, amount) if equity_type == EQUITY_TYPE.CASH: balance.current_value = value_total else: if equity_type == EQUITY_TYPE.CRYPTO: asset = asset + 'USD' current_price = access_layer_stocks.get_actual_price_for_symbol( asset, ts_actual) balance.current_value = value_total if current_price == 0 else round( amount * current_price, 2) data_dict = AssetDataDictionary( ).get_data_dict_for_target_table_for_balance( balance, ts_actual, dt_saving) self.db_stock.insert_asset_entry(data_dict) ts_actual += ts_interval
def get_next_wave_tick(self) -> WaveTick: self.test_case_wave_tick_list_index += 1 wave_tick = self.test_case.wave_tick_list[ self.test_case_wave_tick_list_index] time_stamp = wave_tick.time_stamp date_time = MyDate.get_date_time_from_epoch_seconds(time_stamp) value = wave_tick.close print('{}: {}-new value pair to check: [{} ({}), {}]'.format( self.trade_process, self.trade_test_api.symbol, date_time, time_stamp, value)) return wave_tick
def __on_hover__(self, x, y): tolerance = PlotterInterface.get_tolerance_range_for_extended_dict(self.sys_config) tick = self.pdh.pattern_data.tick_by_date_num_ext_dic.get_value_by_dict_key(x, tolerance) if tick is None: return '' else: if self.sys_config.period == PRD.INTRADAY: date_obj = MyDate.get_date_time_from_epoch_seconds(tick.f_var) date_time_str = '{} {}'.format(date_obj.date(), str(date_obj.time())[:5]) else: date_time_str = tick.date return self.__get_status_message__(date_time_str, tick, y)
def get_dict_for_input(self, symbol: str, period: str, aggregation: int): if math.isnan(self.high): return {} date_time = MyDate.get_date_time_from_epoch_seconds(self.time_stamp) return { CN.PERIOD: period, CN.AGGREGATION: aggregation, CN.SYMBOL: symbol, CN.TIMESTAMP: self.time_stamp, CN.DATE: date_time.date(), CN.TIME: date_time.time(), CN.OPEN: self.open, CN.HIGH: self.high, CN.LOW: self.low, CN.CLOSE: self.close, CN.VOL: self.volume, CN.BIG_MOVE: self._big_move, CN.DIRECTION: self._direction }
def get_tick_list_as_data_frame_for_replay(self): tick_table = [] for tick in self.tick_list: date = MyDate.get_date_from_epoch_seconds(tick.time_stamp) time = MyDate.get_time_from_epoch_seconds(tick.time_stamp) date_time = str( MyDate.get_date_time_from_epoch_seconds(tick.time_stamp)) row = [ tick.position, tick.open, tick.high, tick.low, tick.close, tick.volume, date, time, date_time, tick.time_stamp ] tick_table.append(row) v_array = np.array(tick_table).reshape([len(self.tick_list), 10]) return pd.DataFrame(v_array, columns=[ CN.POSITION, CN.OPEN, CN.HIGH, CN.LOW, CN.CLOSE, CN.VOL, CN.DATE, CN.TIME, CN.DATETIME, CN.TIMESTAMP ])
def get_value_dict(self) -> dict: value_dict = {} value_dict['Order_Id'] = self.order_id value_dict['Symbol'] = self.symbol value_dict['Order_trigger'] = self.order_trigger value_dict['Trade_strategy'] = self.trade_strategy value_dict['Exchange'] = self.exchange value_dict['Side'] = self.side value_dict['Type'] = self.type value_dict['Original_amount'] = self.original_amount value_dict['Executed_amount'] = self.executed_amount value_dict['Remaining_amount'] = self.remaining_amount value_dict['Price'] = self.price value_dict['Is_cancelled'] = self.is_cancelled value_dict['Fee_amount'] = self.fee_amount value_dict['Value_total'] = self.value_total value_dict['DateTime'] = MyDate.get_date_time_from_epoch_seconds( self.time_stamp) value_dict['Timestamp'] = self.time_stamp return value_dict
def __get_data_for_heatmap_figure__(self, index: str, for_mood_graph=False): x_data = self._wave_handler.tick_key_list_for_retrospection if self._wave_handler.period_for_retrospection == PRD.INTRADAY: x_data = [ str(MyDate.get_date_time_from_epoch_seconds(key)) for key in x_data ] y_data = WAVEST.get_waves_types_for_processing( [self._wave_handler.period_for_retrospection]) y_data = y_data[::-1] # we want them in this order z_data = [ self._wave_handler.get_waves_number_list_for_wave_type_and_index( wt, index) for wt in y_data ] # print('__get_data_for_heatmap_figure__: {}: \n{}\n{}\n{}'.format(index, x_data, y_data, z_data)) if for_mood_graph: return self.__get_heatmap_data_for_mood_graph__( x_data, y_data, z_data) return [x_data, y_data, z_data]
def date_time_str(self) -> str: return str(MyDate.get_date_time_from_epoch_seconds(self.time_stamp))
def __print_count_value_category_details__(ts_start: int, hit_list_counter: int, category: str): if ts_start == 0 or hit_list_counter == 0: # we print only available numbers return ts_start_time = MyDate.get_date_time_from_epoch_seconds(ts_start)
def get_xy_from_timestamp_to_date_time_str(xy): if type(xy) == list: return [(str(MyDate.get_date_time_from_epoch_seconds(t_val[0])), t_val[1]) for t_val in xy] return str(MyDate.get_date_time_from_epoch_seconds(xy[0])), xy[1]