Hi
I'm trying to add CoinGecko data (just need the marketcap). I want all other elements of the CryptoUniverse. Here's what I have so far. I would appreciate any help
from AlgorithmImports import *
import numpy as np
import re
import pandas as pd
class TxTrader(QCAlgorithm):
def initialize(self):
self.set_start_date(year=2024, month=1, day=1)
self.set_account_currency("USDT")
self.set_cash(100000)
self.set_brokerage_model(BrokerageName.BINANCE, AccountType.CASH)
self.cg_symbols = list()
self.GC_df_ready = False
self.universe_settings.Resolution = Resolution.DAILY
self.coingecko_dic = dict()
self._universe = self.add_universe(CryptoUniverse.binance(self.universe_selection_filter))
# self.add_alpha(HistoricalReturnsAlphaModel(12, Resolution.HOUR))
# self.set_portfolio_construction(EqualWeightingPortfolioConstructionModel())
# self.set_execution(ImmediateExecutionModel())
# self.add_risk_management(NullRiskManagementModel())
def universe_selection_filter(self, universe_day):
# Define prefixes that need to be removed
prefixes = [
'USD', 'BUSD', 'BKRW', 'EUR', 'TRY', 'FDUSD', 'PAX', 'TUSD', 'BRL', 'GBP', 'RUB', 'JPY', 'AUD'
]
# Regex pattern to match the prefix
prefix_pattern = re.compile(f"^({'|'.join(prefixes)})")
# Regular expression to match "USDT" suffix but exclude "BULLUSDT" and "BEARUSDT"
usdt_pair = re.compile(r'^(?!.*(BULLUSDT|BEARUSDT)).*USDT$')
self.filtered_universe = list()
# Filter symbols based on prefix and suffix
for crypto in universe_day:
symbol = crypto.symbol.value
if usdt_pair.search(symbol) and not prefix_pattern.search(symbol):
self.filtered_universe.append(crypto)
for crypto in self.filtered_universe:
cg_symbol = crypto.symbol.value.replace("USDT", "")
if cg_symbol not in [s.value for s in self.cg_symbols]:
self.cg_symbols.append(self.add_data(CoinGecko, cg_symbol, Resolution.DAILY).symbol)
# if not self.coingecko_dic:
# self.log(f'coingecko_dic : {self.coingecko_dic}')
# else:
# self.debug('coingecko dictionary empty')
# marketcap = [self.coingecko_dic[cg].marketcap for cg in self.cg_symbols]
top_5 = sorted(self.filtered_universe, key=lambda x: x.VolumeInUsd, reverse=True)[:5]
# Return the symbols of the selected cryptocurrencies
return [x.Symbol for x in top_5]
def on_data(self, slice):
for crypto in self.active_securities.values:
if crypto.symbol in self.cg_symbols:
self.log(f'coin gecko active: {crypto.symbol} , mcap : {crypto.value}')
else:
self.log(f'not found: {crypto.symbol}')
# cg_data = slice.get(CoinGecko)
# if cg_data:
# for cg_symbol in self.cg_symbols:
# if cg_symbol in cg_data:
# self.coingecko_dic[cg_symbol.value] = cg_data[cg_symbol]
# else:
# self.debug(f'cg_data not found for {cg_symbol}')
Mia Alissi
Sources: Bybit Crypto Futures Regression Algorithm, Momentum Effect In Commodities Futures, Asset Growth Effect, Momentum And State Of Market Filters, Accrual Anomaly
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
Tamer
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!