CODY - Crypto Strategy Assistant

Bitcoin Accumulation Algo

CODY - Crypto Strategy Assistant

원본 공유 채팅 열기

사용자

Buy $1000 worth of Bitcoin every day while price is below $50k. Sell 50% at $75k and 50% at $100k

CODY - Crypto Strategy Assistant

To create a trading bot that buys $1000 worth of Bitcoin daily while the price is below $50,000, and sells 50% of the holding at $75,000 and the remaining 50% at $100,000, you can follow these steps:

  1. Initialize a state to keep track of the Bitcoin purchased and the last time a purchase was made.
  2. During each iteration, check the current price of Bitcoin.
  3. If the price is below $50,000 and it's been a day since the last purchase, buy $1000 worth of Bitcoin.
  4. Check if the price reaches $75,000 or $100,000, and sell 50% of the holdings at each of these price points.

Here's the Python code for the Quadency bot framework:

def initialize(self, state, context, args):
    state['lastPurchase'] = None
    state['btcHolding'] = 0.0

def run_iteration(self, state, context, args):
    inputs = {
        "symbol": args.params['pair'],
        "buyThreshold": 50000,
        "sellThreshold1": 75000,
        "sellThreshold2": 100000,
        "dailyInvestment": 1000
    }

    current_time = context.date()
    price = self.exchange.fetch_ticker(inputs['symbol'])['last']

    # Buy BTC if the price is below the threshold and it's been a day since last purchase
    if price < inputs['buyThreshold'] and (state['lastPurchase'] is None or current_time - state['lastPurchase'] >= timedelta(days=1)):
        baseAmount = inputs['dailyInvestment'] / price
        order = self.exchange.create_order(type='market', side='buy', symbol=inputs['symbol'], amount=baseAmount)
        log.info(f"Purchased {baseAmount} BTC")
        state['btcHolding'] += baseAmount
        state['lastPurchase'] = current_time

    # Sell 50% of BTC holdings at each threshold
    if state['btcHolding'] > 0:
        if price >= inputs['sellThreshold1']:
            sellAmount = state['btcHolding'] * 0.5
            order = self.exchange.create_order(type='market', side='sell', symbol=inputs['symbol'], amount=sellAmount)
            log.info(f"Sold 50% of holdings at {inputs['sellThreshold1']}")
            state['btcHolding'] -= sellAmount

        elif price >= inputs['sellThreshold2']:
            sellAmount = state['btcHolding']
            order = self.exchange.create_order(type='market', side='sell', symbol=inputs['symbol'], amount=sellAmount)
            log.info(f"Sold remaining holdings at {inputs['sellThreshold2']}")
            state['btcHolding'] = 0

To use this bot on Quadency:

  1. Create a Quadency account.
  2. Connect your exchange account using API keys.
  3. Go to the Bots section and select 'Cody - AI Trading Assistant'.
  4. Paste the provided Python code into the Cody bot.
  5. You can either backtest (if supported) or start the bot in live mode.

Please note that the framework currently doesn't support backtesting for multi-asset strategies, but you can run this bot live. Always ensure you're aware of the risks involved in automated trading and that you have sufficient funds in your exchange account for the bot to execute trades effectively.