Пример #1
0
    def btcusdt_binance() -> CurrencySpot:
        """
        Return the Binance BTC/USDT instrument for backtesting.

        Returns
        -------
        CurrencySpot

        """
        return CurrencySpot(
            instrument_id=InstrumentId(
                symbol=Symbol("BTC/USDT"),
                venue=Venue("BINANCE"),
            ),
            local_symbol=Symbol("BTCUSDT"),
            base_currency=BTC,
            quote_currency=USDT,
            price_precision=2,
            size_precision=6,
            price_increment=Price(1e-02, precision=2),
            size_increment=Quantity(1e-06, precision=6),
            lot_size=None,
            max_quantity=Quantity(9000, precision=6),
            min_quantity=Quantity(1e-06, precision=6),
            max_notional=None,
            min_notional=Money(10.00000000, USDT),
            max_price=Price(1000000, precision=2),
            min_price=Price(0.01, precision=2),
            margin_init=Decimal(0),
            margin_maint=Decimal(0),
            maker_fee=Decimal("0.001"),
            taker_fee=Decimal("0.001"),
            ts_event=0,
            ts_init=0,
        )
Пример #2
0
    def adabtc_binance() -> CurrencySpot:
        """
        Return the Binance ADA/BTC instrument for backtesting.

        Returns
        -------
        CurrencySpot

        """
        return CurrencySpot(
            instrument_id=InstrumentId(
                symbol=Symbol("ADA/BTC"),
                venue=Venue("BINANCE"),
            ),
            local_symbol=Symbol("ADABTC"),
            base_currency=ADA,
            quote_currency=BTC,
            price_precision=8,
            size_precision=8,
            price_increment=Price(1e-08, precision=8),
            size_increment=Quantity(1e-08, precision=8),
            lot_size=None,
            max_quantity=Quantity.from_int(90000000),
            min_quantity=Quantity.from_int(1),
            max_notional=None,
            min_notional=Money(0.00010000, BTC),
            max_price=Price(1000, precision=8),
            min_price=Price(1e-8, precision=8),
            margin_init=Decimal("0"),
            margin_maint=Decimal("0"),
            maker_fee=Decimal("0.0010"),
            taker_fee=Decimal("0.0010"),
            ts_event=0,
            ts_init=0,
        )
Пример #3
0
    def ethusd_ftx() -> CurrencySpot:
        """
        Return the FTX ETH/USD instrument for backtesting.

        Returns
        -------
        CurrencySpot

        """
        return CurrencySpot(
            instrument_id=InstrumentId(
                symbol=Symbol("ETH/USD"),
                venue=Venue("FTX"),
            ),
            local_symbol=Symbol("ETHUSD"),
            base_currency=ETH,
            quote_currency=USD,
            price_precision=1,
            size_precision=3,
            price_increment=Price(1e-01, precision=1),
            size_increment=Quantity(1e-03, precision=3),
            lot_size=None,
            max_quantity=Quantity(9000, precision=3),
            min_quantity=Quantity(1e-05, precision=3),
            max_notional=None,
            min_notional=Money(10.00, USD),
            max_price=None,
            min_price=Price(0.1, precision=1),
            margin_init=Decimal("0.9"),
            margin_maint=Decimal("0.9"),
            maker_fee=Decimal("0.0002"),
            taker_fee=Decimal("0.0007"),
            ts_event=0,
            ts_init=0,
        )
Пример #4
0
    def ethusdt_binance() -> CurrencySpot:
        """
        Return the Binance ETH/USDT instrument for backtesting.

        Returns
        -------
        CurrencySpot

        """
        return CurrencySpot(
            instrument_id=InstrumentId(
                symbol=Symbol("ETH/USDT"),
                venue=Venue("BINANCE"),
            ),
            base_currency=ETH,
            quote_currency=USDT,
            price_precision=2,
            size_precision=5,
            price_increment=Price(1e-02, precision=2),
            size_increment=Quantity(1e-05, precision=5),
            lot_size=None,
            max_quantity=Quantity(9000, precision=5),
            min_quantity=Quantity(1e-05, precision=5),
            max_notional=None,
            min_notional=Money(10.00, USDT),
            max_price=Price(1000000, precision=2),
            min_price=Price(0.01, precision=2),
            margin_init=Decimal("1.00"),
            margin_maint=Decimal("0.35"),
            maker_fee=Decimal("0.0001"),
            taker_fee=Decimal("0.0001"),
            timestamp_origin_ns=0,
            timestamp_ns=0,
        )
Пример #5
0
    async def load_all_async(self) -> None:
        """
        Load the latest Binance instruments into the provider asynchronously.

        """
        # Set async loading flag
        self._loading = True

        # Get current commission rates
        try:
            fee_res: List[Dict[str, str]] = await self._wallet.trade_fee()
            fees: Dict[str, Dict[str, str]] = {s["symbol"]: s for s in fee_res}
        except BinanceClientError:
            self._log.error(
                "Cannot load instruments: API key authentication failed "
                "(this is needed to fetch the applicable account fee tier).", )
            return

        # Get exchange info for all assets
        assets_res: Dict[str, Any] = await self._spot_market.exchange_info()
        server_time_ns: int = millis_to_nanos(assets_res["serverTime"])

        for info in assets_res["symbols"]:
            local_symbol = Symbol(info["symbol"])

            # Create base asset
            base_asset: str = info["baseAsset"]
            base_currency = Currency(
                code=base_asset,
                precision=info["baseAssetPrecision"],
                iso4217=0,  # Currently undetermined for crypto assets
                name=base_asset,
                currency_type=CurrencyType.CRYPTO,
            )

            # Create quote asset
            quote_asset: str = info["quoteAsset"]
            quote_currency = Currency(
                code=quote_asset,
                precision=info["quoteAssetPrecision"],
                iso4217=0,  # Currently undetermined for crypto assets
                name=quote_asset,
                currency_type=CurrencyType.CRYPTO,
            )

            # symbol = Symbol(base_currency.code + "/" + quote_currency.code)
            instrument_id = InstrumentId(symbol=local_symbol,
                                         venue=BINANCE_VENUE)

            # Parse instrument filters
            symbol_filters = {f["filterType"]: f for f in info["filters"]}
            price_filter = symbol_filters.get("PRICE_FILTER")
            lot_size_filter = symbol_filters.get("LOT_SIZE")
            min_notional_filter = symbol_filters.get("MIN_NOTIONAL")
            # market_lot_size_filter = symbol_filters.get("MARKET_LOT_SIZE")

            tick_size = price_filter["tickSize"].rstrip("0")
            step_size = lot_size_filter["stepSize"].rstrip("0")
            price_precision = precision_from_str(tick_size)
            size_precision = precision_from_str(step_size)
            price_increment = Price.from_str(tick_size)
            size_increment = Quantity.from_str(step_size)
            lot_size = Quantity.from_str(step_size)
            max_quantity = Quantity(float(lot_size_filter["maxQty"]),
                                    precision=size_precision)
            min_quantity = Quantity(float(lot_size_filter["minQty"]),
                                    precision=size_precision)
            min_notional = None
            if min_notional_filter is not None:
                min_notional = Money(min_notional_filter["minNotional"],
                                     currency=quote_currency)
            max_price = Price(float(price_filter["maxPrice"]),
                              precision=price_precision)
            min_price = Price(float(price_filter["minPrice"]),
                              precision=price_precision)
            pair_fees = fees.get(local_symbol.value)
            maker_fee: Decimal = Decimal(0)
            taker_fee: Decimal = Decimal(0)
            if pair_fees:
                maker_fee = Decimal(pair_fees["makerCommission"])
                taker_fee = Decimal(pair_fees["takerCommission"])

            # Create instrument
            instrument = CurrencySpot(
                instrument_id=instrument_id,
                local_symbol=local_symbol,
                base_currency=base_currency,
                quote_currency=quote_currency,
                price_precision=price_precision,
                size_precision=size_precision,
                price_increment=price_increment,
                size_increment=size_increment,
                lot_size=lot_size,
                max_quantity=max_quantity,
                min_quantity=min_quantity,
                max_notional=None,
                min_notional=min_notional,
                max_price=max_price,
                min_price=min_price,
                margin_init=Decimal(0),
                margin_maint=Decimal(0),
                maker_fee=maker_fee,
                taker_fee=taker_fee,
                ts_event=server_time_ns,
                ts_init=time.time_ns(),
                info=info,
            )

            self.add_currency(currency=base_currency)
            self.add_currency(currency=quote_currency)
            self.add(instrument=instrument)

        # Set async loading flags
        self._loading = False
        self._loaded = True
Пример #6
0
    def default_fx_ccy(symbol: str, venue: Venue = None) -> CurrencySpot:
        """
        Return a default FX currency pair instrument from the given instrument_id.

        Parameters
        ----------
        symbol : str
            The currency pair symbol.
        venue : Venue
            The currency pair venue.

        Returns
        -------
        CurrencySpot

        Raises
        ------
        ValueError
            If `symbol` length is not in range [6, 7].

        """
        if venue is None:
            venue = Venue("SIM")
        PyCondition.valid_string(symbol, "symbol")
        PyCondition.in_range_int(len(symbol), 6, 7, "len(symbol)")

        instrument_id = InstrumentId(
            symbol=Symbol(symbol),
            venue=venue,
        )

        base_currency = symbol[:3]
        quote_currency = symbol[-3:]

        # Check tick precision of quote currency
        if quote_currency == "JPY":
            price_precision = 3
        else:
            price_precision = 5

        return CurrencySpot(
            instrument_id=instrument_id,
            local_symbol=Symbol(symbol),
            base_currency=Currency.from_str(base_currency),
            quote_currency=Currency.from_str(quote_currency),
            price_precision=price_precision,
            size_precision=0,
            price_increment=Price(1 / 10**price_precision, price_precision),
            size_increment=Quantity.from_int(1),
            lot_size=Quantity.from_str("1000"),
            max_quantity=Quantity.from_str("1e7"),
            min_quantity=Quantity.from_str("1000"),
            max_price=None,
            min_price=None,
            max_notional=Money(50000000.00, USD),
            min_notional=Money(1000.00, USD),
            margin_init=Decimal("0.03"),
            margin_maint=Decimal("0.03"),
            maker_fee=Decimal("0.00002"),
            taker_fee=Decimal("0.00002"),
            ts_event=0,
            ts_init=0,
        )
Пример #7
0
 def parser(block):
     for data in orjson.loads(block):
         obj = CurrencySpot.from_dict(data)
         yield obj