Untitled

 avatar
unknown
plain_text
a year ago
6.4 kB
113
Indexable
import ccxt
import discord
from discord.ext import commands
import asyncio
from datetime import datetime, timedelta
from robin_stocks.robinhood.helper import *
from robin_stocks.robinhood.urls import *
from robin_stocks.robinhood.authentication import login  # Import the login function from Robinhood
import pytz  # Import pytz for timezone manipulation

intents = discord.Intents.default()  # Enable the default intents
# Enable necessary intents
intents.messages = True
intents.guilds = True
intents.message_content = True  # Enable message content intent
intents.typing = False  # Disable typing events to reduce load
intents.presences = False  # Disable presence events to reduce load
# Initialize Discord bot
bot = commands.Bot(command_prefix='!', intents=intents)

# Add your Discord channel ID
YOUR_CHANNEL_ID = id goes here 

# Initialize exchange (Gemini)
exchange = ccxt.gemini()

# Function to check market conditions and send alerts
async def check_market_conditions():
    # Specify cryptocurrency to monitor
    crypto_symbol = 'BTC/USDT'
    
    # Fetch recent market data for crypto
    crypto_ticker = exchange.fetch_ticker(crypto_symbol)
    
    # Example: Check if the current price is below a certain threshold to trigger a buy alert for crypto
    if crypto_ticker['last'] < 50000:
        crypto_buy_alert_message = f"🟢 Good time to buy {crypto_symbol}! Current price: {crypto_ticker['last']} USDT"
        await bot.get_channel(YOUR_CHANNEL_ID).send(crypto_buy_alert_message)
    
    # Example: Check if the current price is above a certain threshold to trigger a sell alert for crypto
    if crypto_ticker['last'] > 60000:
        crypto_sell_alert_message = f"🔴 Good time to sell {crypto_symbol}! Current price: {crypto_ticker['last']} USDT"
        await bot.get_channel(YOUR_CHANNEL_ID).send(crypto_sell_alert_message)
    
    # Check for options with confidence threshold of 0.05
    option_data = find_options_by_specific_profitability(crypto_symbol, typeProfit="chance_of_profit_short", profitFloor=0.05)
    if option_data:
        for option in option_data:
            message = f"⚠️ Option Alert: Symbol: {option['symbol']}, Expiry: {option['expiration_date']}, Strike Price: {option['strike_price']}, Type: {option['type']}, Chance of Profit: {option['chance_of_profit_short']}"
            if float(option['chance_of_profit_short']) > 0.73:
                message += " 🚀"  # Add rocket emoji for options with above 73% profit prediction
            await bot.get_channel(YOUR_CHANNEL_ID).send(message)
            
            # Check if the value of the call exceeds its entry price
            if option['type'] == 'call':
                entry_price = float(option['average_open_price'])
                current_price = float(option['adjusted_mark_price'])
                if current_price > entry_price:
                    call_alert_message = f"🚀 Alert: Value of call option exceeds entry price! Symbol: {option['symbol']}, Expiry: {option['expiration_date']}, Strike Price: {option['strike_price']}, Entry Price: {entry_price}, Current Price: {current_price}"
                    await bot.get_channel(YOUR_CHANNEL_ID).send(call_alert_message)
    
    # Check for options expiring within one or two days for crypto
    for days in range(1, 3):
        expiration_date = (datetime.now() + timedelta(days=days)).strftime('%Y-%m-%d')
        option_data = find_tradable_options(crypto_symbol, expirationDate=expiration_date)
        if option_data:
            for option in option_data:
                message = f"⚠️ Option Alert: Symbol: {option['symbol']}, Expiry: {option['expiration_date']}, Strike Price: {option['strike_price']}, Type: {option['type']}"
                await bot.get_channel(YOUR_CHANNEL_ID).send(message)
    
    # Fetch recent market data for stocks
    stock_symbol = 'BTC/USDT'  # Example stock symbol
    stock_ticker = exchange.fetch_ticker(stock_symbol)
    
    # Example: Check if the current price is below a certain threshold to trigger a buy alert for stocks
    if stock_ticker['last'] < 150:
        stock_buy_alert_message = f"🟢 Good time to buy {stock_symbol}! Current price: {stock_ticker['last']}"
        await bot.get_channel(YOUR_CHANNEL_ID).send(stock_buy_alert_message)
    
    # Example: Check if the current price is above a certain threshold to trigger a sell alert for stocks
    if stock_ticker['last'] > 200:
        stock_sell_alert_message = f"🔴 Good time to sell {stock_symbol}! Current price: {stock_ticker['last']}"
        await bot.get_channel(YOUR_CHANNEL_ID).send(stock_sell_alert_message)

# Function to send daily market analysis and sentiment message
async def send_daily_market_analysis():
    # Send market analysis and sentiment message every morning at 8 AM Eastern Time
    eastern = pytz.timezone('US/Eastern')
    current_time = datetime.now(eastern)
    morning_time = current_time.replace(hour=8, minute=0, second=0, microsecond=0)
    if current_time < morning_time:
        delta = morning_time - current_time
        await asyncio.sleep(delta.seconds)

        await bot.get_channel(YOUR_CHANNEL_ID).send("🌞 Good morning! Here's today's market analysis and sentiment:")

        await check_market_conditions()

# Command to start monitoring market conditions
@bot.command()
async def start_alerts():
    while True:
        await check_market_conditions()
        await asyncio.sleep(3600)  # Check every hour (adjust as needed)

# Command to start sending daily market analysis
@bot.command()
async def start_daily_analysis(ctx):
    while True:
        await send_daily_market_analysis()
        await asyncio.sleep(86400)  # Check every day (adjust as needed)

# Robinhood credentials
USERNAME = 'email here'
PASSWORD = 'password here'

# Login to Robinhood
login(username=USERNAME, password=PASSWORD)

# Run the bot
bot.run('token goes here ')
Editor is loading...