(Help) Spread Bot BTC/USDC and BTC/USDC
alphaDescription
I need some help with creating/finishing a spread bot to arbitrage between the price difference of BTC/USDT and BTC/USDC on the same exchange. I have started a script but I can't seem to get some of the bugs out of the script. I understand that this is not a favorable way to trade but I would like to run some backtesting myself on the script.
I am a novice at creating scripts, so please go easy on me lol.
HaasScript
GetOrderbookAsk
return btc_usdc_data, btc_usdt_data
DefineCommand def extract_prices(json_data):
# Function to extract current prices from JSON data
def extract_prices(json_data):
btc_price = json_data["BTC_price"]
usd_price = json_data["USD_price"]
current_price = btc_price / usd_price
return current_price
# Function to calculate percentage spread between two prices
def calculate_spread(price1, price2):
spread_percentage = abs((price1 - price2) / ((price1 + price2) / 2)) * 100
return spread_percentage
# Function to retrieve CSV data for historical price data of BTC/USDC and BTC/USDT pairs
def get_csv_data():
btc_usdc_data = []
btc_usdt_data = []
with open('btc_usdc.csv', 'r') as file:
reader = csv.reader(file)
for row in reader:
btc_usdc_data.append(float(row[1]))
with open('btc_usdt.csv', 'r') as file:
reader = csv.reader(file)
for row in reader:
btc_usdt_data.append(float(row[1]))
return btc_usdc_data, btc_usdt_data
# Function to analyze historical data
def analyze_historical_data(data):
# Implement your analysis logic here
pass
# Function for trading logic
def trading_logic(spread_percentage, threshold):
if spread_percentage > threshold:
# Execute buy and sell orders
# Adjust trading strategy based on market conditions
pass
else:
print("Spread is not favorable for trading.")
# Main function
def main():
# Retrieve JSON data
btc_usdc_data, btc_usdt_data = get_json_data()
# Extract current prices
btc_usdc_price = extract_prices(btc_usdc_data)
btc_usdt_price = extract_prices(btc_usdt_data)
# Calculate percentage spread
spread_percentage = calculate_spread(btc_usdc_price, btc_usdt_price)
# Set threshold for trading
threshold = .5 # .5% spread threshold
# Execute trading logic
trading_logic(spread_percentage, threshold)
if DoBuy == "(.5, .5)": DoBuy
0 Comments
Sign in to leave a comment.
No comments yet. Be the first!