If i set cash    100000$  set_holdings does not work, if i set 1000000$ everything works well

 

class DydxTestAlgorithm(QCAlgorithm):

    def initialize(self):
        self.set_start_date(2025, 2, 12)
        self.set_end_date(2025, 3, 31)
        self.set_cash(100000)

        self.set_brokerage_model(DydxPerpetualBrokerageModel())
        symbolBTC = "BTC-USD"
        symbolETH = "ETH-USD"

        self._btc_symbol = self.add_data(DydxPerpetualData, symbolBTC, Resolution.DAILY).symbol
        self._eth_symbol = self.add_data(DydxPerpetualData, symbolETH, Resolution.DAILY).symbol

        self.set_benchmark(symbolBTC)
        #self.set_benchmark(symbolETH)

        self._btc_sma = self.sma(self._btc_symbol, 31)
        self._btc_ema = self.ema(self._btc_symbol, 31)
        self._eth_sma = self.sma(self._eth_symbol, 31)
        self._eth_ema = self.sma(self._eth_symbol, 31)

        self.debug(f"BTC Tradable: {self.securities[self._btc_symbol].is_tradable}, Leverage: {self.securities[self._btc_symbol].leverage}, Properties: {self.securities[self._btc_symbol].symbol_properties}")
        self.debug(f"ETH Tradable: {self.securities[self._eth_symbol].is_tradable}, Leverage: {self.securities[self._eth_symbol].leverage}, Properties: {self.securities[self._eth_symbol].symbol_properties}")




    def on_order_event(self, order_event):
        self.debug(f"Order: {order_event.symbol}, Status: {order_event.status}, Qty: {order_event.quantity}, Message: {order_event.message},  Fer :{order_event.order_fee}, Fill price: {order_event.fill_price}, Time: {order_event.utc_time}")

    def on_data(self, data: Slice):   
        if not (self._btc_symbol in data and self._eth_symbol in data):
            self.debug("Data not available for both symbols")
            return

        btc_current_price = data[self._btc_symbol].close

        if not self.portfolio[self._btc_symbol].invested and self._btc_ema.current.value > self._btc_sma.current.value and data[self._btc_symbol].close < self._btc_ema.current.value:
            self.set_holdings(self._btc_symbol, 0.5)
            self.debug('LONG ' + str(self._btc_symbol) + ' price: ' + str(self.securities[self._btc_symbol].price))

        elif not self.portfolio[self._btc_symbol].invested and self._eth_ema.current.value > self._eth_sma.current.value and data[self._eth_symbol].close < self._eth_ema.current.value:
            self.set_holdings(self._eth_symbol, 0.5)
            self.debug('LONG ' + str(self._eth_symbol) + ' price: ' + str(self.securities[self._eth_symbol].price))

        elif not self.portfolio[self._eth_symbol].invested and self._btc_ema.current.value < self._btc_sma.current.value and data[self._btc_symbol].close > self._btc_ema.current.value:
            self.set_holdings(self._btc_symbol, -0.5)
            self.debug('SHORT ' + str(self._btc_symbol) + ' price: ' + str(self.securities[self._btc_symbol].price))

        elif not self.portfolio[self._eth_symbol].invested and self._eth_ema.current.value < self._eth_sma.current.value and data[self._eth_symbol].close > self._eth_ema.current.value:
            self.set_holdings(self._eth_symbol, -0.5)
            self.debug('SHORT ' + str(self._eth_symbol) + ' price: ' + str(self.securities[self._eth_symbol].price))
        
        
        #liquidate if opposite signal
        elif self.portfolio[self._btc_symbol].quantity < 0 and self._btc_ema.current.value > self._btc_sma.current.value and data[self._btc_symbol].close < self._btc_ema.current.value:
            self.liquidate(self._btc_symbol)
            self.debug('LIQUID SHORT ' + str(self._btc_symbol) + ' price: ' + str(self.securities[self._btc_symbol].price))

        elif self.portfolio[self._eth_symbol].quantity < 0 and self._eth_ema.current.value > self._eth_sma.current.value and data[self._eth_symbol].close < self._eth_ema.current.value:
            self.liquidate(self._eth_symbol)
            self.debug('LIQUID SHORT ' + str(self._eth_symbol) + ' price: ' + str(self.securities[self._eth_symbol].price))

        elif self.portfolio[self._btc_symbol].quantity > 0 and self._btc_ema.current.value < self._btc_sma.current.value and data[self._btc_symbol].close > self._btc_ema.current.value:
            self.liquidate(self._btc_symbol)
            self.debug('LIQUID LONG ' + str(self._btc_symbol) + ' price: ' + str(self.securities[self._btc_symbol].price))

        elif self.portfolio[self._eth_symbol].quantity > 0 and self._eth_ema.current.value < self._eth_sma.current.value and data[self._eth_symbol].close > self._eth_ema.current.value:
            self.liquidate(self._eth_symbol)
            self.debug('LIQUID LONG ' + str(self._eth_symbol) + ' price: ' + str(self.securities[self._eth_symbol].price))