def get_change(current, previous, provide_abs=True): """ :param provide_abs: :param current: :param previous: :return: difference in percentage between current & previous """ tot = Decimal(0.5) * Decimal(current + previous) if provide_abs: diff = Decimal(abs(current - previous)) else: diff = Decimal(current - previous) # FIXME NOTE: What if price would be different in multiple times? percent = 0.001 if tot != 0: z = diff / tot if z > 0.001: percent = truncate_float((z * 100), 2) return percent
def round_volume(exchange_id, min_volume, pair_id): if exchange_id == EXCHANGE.BINANCE: return round_volume_by_binance_rules(volume=min_volume, pair_id=pair_id) elif exchange_id == EXCHANGE.HUOBI: return round_volume_by_huobi_rules(volume=min_volume, pair_id=pair_id) return truncate_float(min_volume, 8)
def round_volume_by_huobi_rules(volume, pair_id): pair_name = get_currency_pair_to_huobi(pair_id) base_currency_id, dst_currency_id = split_currency_pairs(pair_id) if pair_name in PRECISION_NUMBER[base_currency_id]: return truncate_float(volume, PRECISION_NUMBER[base_currency_id][pair_name]) return volume
def round_volume_by_exchange_rules(sell_exchange_id, buy_exchange_id, min_volume, pair_id): if EXCHANGE.BINANCE in {sell_exchange_id, buy_exchange_id}: return round_volume_by_binance_rules(volume=min_volume, pair_id=pair_id) elif EXCHANGE.HUOBI in {sell_exchange_id, buy_exchange_id}: return round_volume_by_huobi_rules(volume=min_volume, pair_id=pair_id) return truncate_float(min_volume, 8)
def __str__(self): str_repr = """ Trade at Exchange: {exch} Type: {deal_type} Pair: {pair} for volume {vol} with price {price} order_book_time {ob_time} create_time {ct_time} execute_time {ex_time} Executed at: {dt} order_id {order_id} trade_id {trade_id} executed_volume {ex_volume} arbitrage_id {a_id} """.format(exch=get_exchange_name_by_id(self.exchange_id), deal_type=get_order_type_by_id(self.trade_type), pair=get_pair_name_by_id(self.pair_id), vol=truncate_float(self.volume, 8), price=truncate_float(self.price, 8), ob_time=self.order_book_time, ct_time=self.create_time, ex_time=self.execute_time, dt=ts_to_string_local(self.execute_time), order_id=self.order_id, trade_id=self.trade_id, ex_volume=self.executed_volume, a_id=self.arbitrage_id) return str_repr