def __init__(self, trading_pairs: List[str], wallet_private_key: str, ethereum_rpc_url: str, # not used, but left in place to be consistent with other gateway connectors trading_required: bool = True ): """ :param trading_pairs: a list of trading pairs :param wallet_private_key: a private key for eth wallet :param trading_required: Whether actual trading is needed. """ ExchangeBase.__init__(self) PerpetualTrading.__init__(self) self._trading_pairs = trading_pairs self._wallet_private_key = wallet_private_key self._trading_required = trading_required self._ev_loop = asyncio.get_event_loop() self._shared_client = None self._last_poll_timestamp = 0.0 self._last_balance_poll_timestamp = time.time() self._in_flight_orders = {} self._allowances = {} self._status_polling_task = None self._auto_approve_task = None self._real_time_balance_update = False self._poll_notifier = None self._funding_payment_span = [120, 120] self._fundingPayment = {} self._budget_checker = PerpetualBudgetChecker(self)
def __init__( self, client_config_map: "ClientConfigAdapter", bitmex_api_key: str = None, bitmex_api_secret: str = None, trading_pairs: Optional[List[str]] = None, trading_required: bool = True, domain: str = CONSTANTS.DOMAIN, ): self._bitmex_time_synchronizer = TimeSynchronizer() self._auth: BitmexAuth = BitmexAuth(api_key=bitmex_api_key, api_secret=bitmex_api_secret) self._trading_pairs = trading_pairs self._trading_required = trading_required self._throttler = AsyncThrottler(CONSTANTS.RATE_LIMITS) self._domain = domain self._api_factory = web_utils.build_api_factory(auth=self._auth) self._rest_assistant: Optional[RESTAssistant] = None self._ws_assistant: Optional[WSAssistant] = None ExchangeBase.__init__(self, client_config_map=client_config_map) self._user_stream_tracker = BitmexUserStreamTracker( auth=self._auth, domain=self._domain, throttler=self._throttler, api_factory=self._api_factory, time_synchronizer=self._bitmex_time_synchronizer) self._order_book_tracker = BitmexOrderBookTracker( trading_pairs=trading_pairs, domain=self._domain, throttler=self._throttler, api_factory=self._api_factory) self._ev_loop = asyncio.get_event_loop() self._poll_notifier = asyncio.Event() self._order_not_found_records = defaultdict(int) self._last_timestamp = 0 self._trading_rules = {} self._in_flight_orders = {} self._status_polling_task = None self._user_stream_event_listener_task = None self._trading_rules_polling_task = None self._user_stream_tracker_task = None self._last_poll_timestamp = 0 self._client_order_tracker: ClientOrderTracker = ClientOrderTracker( connector=self) self._trading_pair_to_multipliers = {} self._trading_pair_price_estimate_for_quantize = {} self._token_multiplier = {}
def setUp(self) -> None: super().setUp() self.strategy = None self.markets = {"binance": ExchangeBase(), "kucoin": ExchangeBase()} self.notifications = [] self.log_errors = [] assign_config_default(strategy_cmap) strategy_cmap.get("maker_market").value = "binance" strategy_cmap.get("taker_market").value = "kucoin" strategy_cmap.get("maker_market_trading_pair").value = "ETH-USDT" strategy_cmap.get("taker_market_trading_pair").value = "ETH-USDT" strategy_cmap.get("order_amount").value = Decimal("1") strategy_cmap.get("min_profitability").value = Decimal("2") global_config_map.get("strategy_report_interval").value = 60. strategy_cmap.get("use_oracle_conversion_rate").value = False
def setUp(self) -> None: super().setUp() self.strategy = None self.markets = {"binance": ExchangeBase()} self.assets = set() self.notifications = [] self.log_errors = [] assign_config_default(strategy_cmap) strategy_cmap.get("exchange").value = "binance" strategy_cmap.get("market").value = "balancer" strategy_cmap.get("order_amount").value = Decimal("1") strategy_cmap.get("order_refresh_time").value = 60. strategy_cmap.get("hanging_orders_enabled").value = True strategy_cmap.get("hanging_orders_cancel_pct").value = Decimal("1") # strategy_cmap.get("hanging_orders_aggregation_type").value = "VOLUME_WEIGHTED" strategy_cmap.get("parameters_based_on_spread").value = True strategy_cmap.get("min_spread").value = Decimal("2") strategy_cmap.get("max_spread").value = Decimal("3") strategy_cmap.get("vol_to_spread_multiplier").value = Decimal("1.1") strategy_cmap.get("volatility_sensibility").value = Decimal("2.2") strategy_cmap.get("inventory_risk_aversion").value = Decimal("0.1") strategy_cmap.get("risk_factor").value = Decimal("1.11") strategy_cmap.get("order_book_depth_factor").value = Decimal("2.22") strategy_cmap.get("order_amount_shape_factor").value = Decimal("3.33") self.raise_exception_for_market_initialization = False
def setUp(self) -> None: super().setUp() self.strategy = None self.markets = {"binance": ExchangeBase()} self.assets = set() self.notifications = [] self.log_errors = [] assign_config_default(strategy_cmap) strategy_cmap.get("exchange").value = "binance" strategy_cmap.get("markets").value = "BTC-USDT,ETH-USDT" strategy_cmap.get("token").value = "USDT" strategy_cmap.get("order_amount").value = Decimal("1") strategy_cmap.get("spread").value = Decimal("2") strategy_cmap.get("inventory_skew_enabled").value = False strategy_cmap.get("target_base_pct").value = Decimal("50") strategy_cmap.get("order_refresh_time").value = 60. strategy_cmap.get("order_refresh_tolerance_pct").value = Decimal("1.5") strategy_cmap.get("inventory_range_multiplier").value = Decimal("2") strategy_cmap.get("volatility_interval").value = 30 strategy_cmap.get("avg_volatility_period").value = 5 strategy_cmap.get("volatility_to_spread_multiplier").value = Decimal( "1.1") strategy_cmap.get("max_spread").value = Decimal("4") strategy_cmap.get("max_order_age").value = 300.
def setUp(self) -> None: super().setUp() self.strategy = None self.markets = {"binance": ExchangeBase(client_config_map=ClientConfigAdapter(ClientConfigMap()))} self.notifications = [] self.log_records = [] self.base = "ETH" self.quote = "BTC" self.strategy_config_map = ClientConfigAdapter( AvellanedaMarketMakingConfigMap( exchange="binance", market=combine_to_hb_trading_pair(self.base, self.quote), execution_timeframe_mode=FromDateToDateModel( start_datetime="2021-11-18 15:00:00", end_datetime="2021-11-18 16:00:00", ), order_amount=60, order_refresh_time=60, hanging_orders_mode=TrackHangingOrdersModel( hanging_orders_cancel_pct=1, ), order_levels_mode=MultiOrderLevelModel( order_levels=4, level_distances=1, ), min_spread=2, risk_factor=1.11, order_amount_shape_factor=0.33, ) ) self.raise_exception_for_market_initialization = False self._logger = None
def setUp(self) -> None: super().setUp() self.strategy = None self.markets = {"binance": ExchangeBase()} self.notifications = [] self.log_errors = [] assign_config_default(strategy_cmap) strategy_cmap.get("secondary_exchange").value = "binance" strategy_cmap.get("secondary_market").value = "CELO-USDT" strategy_cmap.get("order_amount").value = Decimal("1") strategy_cmap.get("min_profitability").value = Decimal("2") strategy_cmap.get("celo_slippage_buffer").value = Decimal("3")
def setUp(self) -> None: super().setUp() self.strategy = None self.markets = {"binance": ExchangeBase()} self.notifications = [] self.log_errors = [] assign_config_default(c_map) c_map.get("derivative").value = "binance" c_map.get("market").value = "ETH-USDT" c_map.get("leverage").value = Decimal("5") c_map.get("order_amount").value = Decimal("1") c_map.get("order_refresh_time").value = 60. c_map.get("bid_spread").value = Decimal("1") c_map.get("ask_spread").value = Decimal("2")
def quantize_order_amount(self, trading_pair: str, amount: Decimal, price: Decimal = s_decimal_0) -> Decimal: trading_rule = self._trading_rules[trading_pair] quantized_amount = ExchangeBase.quantize_order_amount(self, trading_pair, amount) current_price = self.get_price(trading_pair, False) calc_price = current_price if price == s_decimal_0 else price notional_size = calc_price * quantized_amount if notional_size < trading_rule.min_notional_size * Decimal("1"): return s_decimal_0 return quantized_amount
def setUp(self) -> None: super().setUp() self.strategy = None self.markets = {"binance": ExchangeBase(), "kucoin": MockPerpConnector()} self.notifications = [] self.log_errors = [] assign_config_default(strategy_cmap) strategy_cmap.get("spot_connector").value = "binance" strategy_cmap.get("spot_market").value = "BTC-USDT" strategy_cmap.get("perpetual_connector").value = "kucoin" strategy_cmap.get("perpetual_market").value = "BTC-USDT" strategy_cmap.get("order_amount").value = Decimal("1") strategy_cmap.get("perpetual_leverage").value = Decimal("2") strategy_cmap.get("min_opening_arbitrage_pct").value = Decimal("10") strategy_cmap.get("min_closing_arbitrage_pct").value = Decimal("1")
def setUp(self) -> None: super().setUp() self.strategy = None self.client_config_map = ClientConfigAdapter(ClientConfigMap()) self.markets = {"binance": ExchangeBase(client_config_map=self.client_config_map)} self.notifications = [] self.log_errors = [] assign_config_default(c_map) c_map.get("exchange").value = "binance" c_map.get("market").value = "ETH-USDT" c_map.get("order_amount").value = Decimal("1") c_map.get("order_refresh_time").value = 60. c_map.get("max_order_age").value = 300. c_map.get("bid_spread").value = Decimal("1") c_map.get("ask_spread").value = Decimal("2") c_map.get("minimum_spread").value = Decimal("0.5") c_map.get("price_ceiling").value = Decimal("100") c_map.get("price_floor").value = Decimal("50") c_map.get("ping_pong_enabled").value = False c_map.get("order_levels").value = 2 c_map.get("order_level_amount").value = Decimal("0.5") c_map.get("order_level_spread").value = Decimal("0.2") c_map.get("inventory_skew_enabled").value = True c_map.get("inventory_target_base_pct").value = Decimal("50") c_map.get("inventory_range_multiplier").value = Decimal("2") c_map.get("filled_order_delay").value = 45. c_map.get("hanging_orders_enabled").value = True c_map.get("hanging_orders_cancel_pct").value = Decimal("6") c_map.get("order_optimization_enabled").value = False c_map.get("ask_order_optimization_depth").value = Decimal("0.01") c_map.get("bid_order_optimization_depth").value = Decimal("0.02") c_map.get("add_transaction_costs").value = False c_map.get("price_source").value = "external_market" c_map.get("price_type").value = "best_bid" c_map.get("price_source_exchange").value = "ascend_ex" c_map.get("price_source_market").value = "ETH-DAI" c_map.get("price_source_custom_api").value = "localhost.test" c_map.get("order_refresh_tolerance_pct").value = Decimal("2") c_map.get("order_override").value = None c_map.get("split_order_levels_enabled").value = True c_map.get("bid_order_level_spreads").value = "1,2" c_map.get("ask_order_level_spreads").value = "1,2" c_map.get("bid_order_level_amounts").value = "1,2" c_map.get("ask_order_level_amounts").value = None
def setUp(self) -> None: super().setUp() self.strategy = None self.markets = {"binance": ExchangeBase()} self.notifications = [] self.log_errors = [] assign_config_default(strategy_cmap) strategy_cmap.get("exchange").value = "binance" strategy_cmap.get("market").value = "balancer" strategy_cmap.get("execution_timeframe").value = "from_date_to_date" strategy_cmap.get("start_time").value = "2021-11-18 15:00:00" strategy_cmap.get("end_time").value = "2021-11-18 16:00:00" strategy_cmap.get("order_amount").value = Decimal("1") strategy_cmap.get("order_refresh_time").value = 60. strategy_cmap.get("hanging_orders_enabled").value = True strategy_cmap.get("hanging_orders_cancel_pct").value = Decimal("1") # strategy_cmap.get("hanging_orders_aggregation_type").value = "VOLUME_WEIGHTED" strategy_cmap.get("min_spread").value = Decimal("2") strategy_cmap.get("risk_factor").value = Decimal("1.11") strategy_cmap.get("order_levels").value = Decimal("4") strategy_cmap.get("level_distances").value = Decimal("1") strategy_cmap.get("order_amount_shape_factor").value = Decimal("3.33") self.raise_exception_for_market_initialization = False
def setUp(self) -> None: super().setUp() self.strategy = None self.client_config_map = ClientConfigAdapter(ClientConfigMap()) self.markets = { "binance": ExchangeBase(client_config_map=self.client_config_map) } self.notifications = [] self.log_errors = [] assign_config_default(c_map) c_map.get("exchange").value = "binance" c_map.get("market").value = "ETH-USDT" c_map.get("n_levels").value = 10 c_map.get("grid_price_ceiling").value = Decimal("5000") c_map.get("grid_price_floor").value = Decimal("2000") c_map.get("start_order_spread").value = Decimal("1") c_map.get("order_refresh_time").value = 60. c_map.get("max_order_age").value = 300. c_map.get("order_refresh_tolerance_pct").value = Decimal("2") c_map.get("order_amount").value = Decimal("1") c_map.get("order_optimization_enabled").value = False c_map.get("ask_order_optimization_depth").value = Decimal("0.01") c_map.get("bid_order_optimization_depth").value = Decimal("0.02")