Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

crypto trading bot python

def run_bot_for_ticker(ccxt_ticker, trading_ticker):

    currently_holding = False
    while 1:
        # STEP 1: FETCH THE DATA
        ticker_data = fetch_data(ccxt_ticker)
        if ticker_data is not None:
            # STEP 2: COMPUTE THE TECHNICAL INDICATORS & APPLY THE TRADING STRATEGY
            trade_rec_type = get_trade_recommendation(ticker_data)
            print(f'{datetime.now().strftime("%d/%m/%Y %H:%M:%S")}  TRADING RECOMMENDATION: {trade_rec_type}')

            # STEP 3: EXECUTE THE TRADE
            if (trade_rec_type == 'BUY' and not currently_holding) or 
                (trade_rec_type == 'SELL' and currently_holding):
                print(f'Placing {trade_rec_type} order')
                trade_successful = execute_trade(trade_rec_type,trading_ticker)
                currently_holding = not currently_holding if trade_successful else currently_holding

            # SLEEP BEFORE REPEATING THE STEPS
            time.sleep(CANDLE_DURATION_IN_MIN*60)
        else:
            print(f'Unable to fetch ticker data - {ccxt_ticker}. Retrying!!')
            time.sleep(5)
            

CCXT_TICKER_NAME = 'BTC/USDT'
TRADING_TICKER_NAME = 'btcusdt'
run_bot_for_ticker(CCXT_TICKER_NAME,TRADING_TICKER_NAME)
Comment

PREVIOUS NEXT
Code Example
Python :: discord.py create button 
Python :: pysimplegui get value from textbox 
Python :: seaborn orient 
Python :: dynamically create python dictionary 
Python :: python get module name 
Python :: elbow plot for k means clustering 
Python :: python initialize multidimensional array 
Python :: binary search tree in python 
Python :: table pandas to postgresql 
Python :: swap two lists without using third variable python 
Python :: sample hierarchical clustering 
Python :: unicode error python 
Python :: swapping upper case and lower case string python 
Python :: python debugging 
Python :: qr detector 
Python :: how to check how many key value pairs are in a dict python 
Python :: model checkpoint 
Python :: get the last item in a python list 
Python :: python split string by specific word 
Python :: how to close opened file in python 
Python :: is there a null data type in python 
Python :: python environment 
Python :: discord bot python get message id 
Python :: python math exp 
Python :: binary search in python 
Python :: _ in python 
Python :: sqlalchemy function for default value for column 
Python :: Accessing elements from a Python Dictionary using the get method 
Python :: cache-control no cache django 
Python :: percentage plot of categorical variable in python woth hue 
ADD CONTENT
Topic
Content
Source link
Name
6+2 =