import ccxt
import pandas as pd
import time
# Binance API keys
api_key = 'YOUR_API_KEY'
api_secret = 'YOUR_API_SECRET'
# Binance connection
exchange = ccxt.binance({
'apiKey': api_key,
'secret': api_secret,
})
# Trading parameters
symbol = 'BTC/USDT'
timeframe = '1m'
trad_size = 40 # Traditional Renko size
volume_threshold = 500 # Minimum volume for drawing line (in BTC)
line_duration_days = 2 # Duration for which the line should be valid
# Function to get Renko chart
def get_renko_chart(data, trad_size):
data['close_shift'] = data['close'].shift(1)
data['price_diff'] = abs(data['close'] - data['close_shift'])
data['bricks'] = data['price_diff'] // trad_size
data.drop(['close_shift', 'price_diff'], axis=1, inplace=True)
return data
# Function to check if the volume is above the threshold
def is_high_volume(data, volume_threshold):
return data['volume'].iloc[-1] >= volume_threshold
# Function to generate buy or sell signals based on Renko chart
def generate_signals(data):
data['buy_signal'] = data['close'] > data['line']
data['sell_signal'] = data['close'] < data['line']
return data
# Main loop
while True:
# Fetch 1-minute data
ohlcv = exchange.fetch_ohlcv(symbol, timeframe)
df = pd.DataFrame(ohlcv, columns=['timestamp', 'open', 'high', 'low', 'close',
'volume'])
df['timestamp'] = pd.to_datetime(df['timestamp'], unit='ms')
df.set_index('timestamp', inplace=True)
# Check for high volume
if is_high_volume(df, volume_threshold):
# Draw line
line_price = df['close'].iloc[-1]
line_start_time = time.time()
# Check if the line should be visible
if time.time() - line_start_time < line_duration_days * 24 * 60 * 60:
df['line'] = line_price
else:
df['line'] = None
# Generate Renko chart
renko_df = get_renko_chart(df, trad_size)
# Generate signals
signals_df = generate_signals(renko_df)
# Print signals (replace with actual trading logic)
if signals_df['buy_signal'].iloc[-1]:
print("Buy Signal!")
elif signals_df['sell_signal'].iloc[-1]:
print("Sell Signal!")
# Sleep for a minute (adjust as needed)
time.sleep(60)