Best practises for defining crypto currencies & instruments for backtests, and future plan? #505
-
Hi, For instance:
@staticmethod
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,
)
ADA = Currency("ADA", precision=6, iso4217=0, name="Cardano", currency_type=CurrencyType.CRYPTO) I feel a bit disturbed with that, this seems somewhat error prone (for instance #503).
At the moment, I plan to use a generic instrument, along a not so generic #!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue Nov 30 20:30:00 2021
@author: yoh
Crypto generic instrument.
"""
from decimal import Decimal
from nautilus_trader.model.identifiers import Symbol, Venue
from nautilus_trader.model.currency import Currency
from nautilus_trader.model.instruments.currency import CurrencySpot
from nautilus_trader.model.identifiers import InstrumentId
from nautilus_trader.model.currencies import USDT
from nautilus_trader.model.objects import Money, Price, Quantity
CRYPTO_TYPE = USDT.currency_type
CRYPTO_MAP = {'ADA':'Cardano',
'BCH':'Bitcoin Cash',
'BNB':'Binance Coin',
'BRZ':'Brazilian Digital Token',
'BSV':'Bitcoin SV',
'BTC':'Bitcoin',
'DASH':'Dash',
'DOGE':'DOGE',
'DOT':'Polkadot',
'EOS':'EOS',
'ETH':'Ether',
'FTT':'FTT',
'LINK':'Chainlink',
'LTC':'Litecoin',
'TRYB':'BiLira',
'VTC':'Vertcoin',
'XLM':'Stellar Lumen',
'XMR':'Monero',
'XRP':'Ripple',
'XTZ':'Tezos',
'USDT':'Tether',
'ZEC':'Zcash'}
def baseusdt_binance(base:str, precision:int=8) -> CurrencySpot:
"""
Return Binance BASE/USDT instrument for backtesting.
Returns
CurrencySpot
"""
base = base.upper()
NAUT_BASE = Currency(base, precision=precision, iso4217=0,
name=CRYPTO_MAP[base], currency_type=CRYPTO_TYPE)
return CurrencySpot(
instrument_id=InstrumentId(symbol=Symbol(f'{base}/USDT'),
venue=Venue('BINANCE')),
local_symbol=Symbol(f'{base}USDT'),
base_currency=NAUT_BASE,
quote_currency=USDT,
price_precision=precision,
size_precision=precision,
price_increment=Price(10**(-precision), precision=precision),
size_increment=Quantity(10**(-precision), precision=precision),
lot_size=None,
max_quantity=Quantity(90000000, precision=precision),
min_quantity=Quantity(10**(-precision), precision=precision),
max_notional=None,
min_notional=Money(1e-8, USDT),
max_price=Price(1000000, precision=8),
min_price=Price(1e-8, precision=8),
margin_init=Decimal(0),
margin_maint=Decimal(0),
maker_fee=Decimal("0.001"),
taker_fee=Decimal("0.001"),
ts_event=0,
ts_init=0,
) Thanks in advance for your comments. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Hi @yohplala So the What should be specified in the docs however, is that the preferred method for obtaining these instruments is actually through the Right now the Then you can just find your desired instrument from the 1700+ which will then be loaded (Spot). |
Beta Was this translation helpful? Give feedback.
Hi @yohplala
So the
TestInstrumentProvider
is more to provide offline stub instruments for both backtests and unit tests.What should be specified in the docs however, is that the preferred method for obtaining these instruments is actually through the
BinanceInstrumentProvider
or other providers specific to their exchanges. This will then request the instrument data over their API, which should alleviate some of your concerns about the correctness of the data.Right now the
BinanceInstrumentProvider
only has an async methodload_all_async
you could run on an event_loop, I will add a convenienceload_all
synchronous method, the old integration used to have one of those.Then you can just …