Giter Site home page Giter Site logo

rsibot's Introduction

rsi_optimizations.py:

This Python script is designed to optimize Relative Strength Index (RSI) trading strategies for a set of stocks listed on the Alpaca trade platform. The script retrieves daily bars for a set of specified symbols over a defined period and calculates the RSI for each symbol. It then iterates through a range of possible values for overbought and oversold thresholds and window sizes, calculating the total return for each combination. The script returns the optimal RSI values for each symbol, which can be used to execute trades based on RSI.

The script uses the Alpaca API to retrieve data and execute trades. The API keys are imported from a separate file named 'keys2.py'. The script also includes a function to send email notifications using SMTP server.

The script runs an optimization function every 24 hours, which calculates the optimal RSI thresholds for each symbol. The optimization function is run on a separate thread to ensure it does not interfere with the main trading function.

This script is intended to work in tandem with a second script that executes trades based on the optimal RSI values returned by this script. The second script is not included in this code and must be implemented separately.

To use this script, you will need to modify the parameters at the beginning of the script to suit your desired symbols, timeframes, and optimization parameters. You will also need to provide your own API keys and SMTP server information in the 'keys2.py' file.

order_exec.py:

This is the second Python script for a trading bot that works in tandem with rsi_optimizations. It includes functions to execute trades based on the RSI (Relative Strength Index) indicator and to get the current price of a list of symbols.

The script uses the Alpaca Trading API and keys are imported from keys2.py. The symbols list and optimal_values dictionary are also imported from another Python script.

The execute_trades() function takes in the list of symbols and current prices for each symbol, and uses the optimal RSI values to execute trades based on whether the current RSI is above the overbought threshold or below the oversold threshold. If the RSI is above the overbought threshold, it sells a specified quantity of shares for that symbol; if the RSI is below the oversold threshold, it buys as many shares as possible based on available funds. The function also prints messages for each trade, including whether the trade was successful or not.

The get_current_prices() function takes in a list of symbols and returns a dictionary of the current prices for each symbol. It uses the Alpaca Trading API to get the most recent bar for each symbol and extract the current price.

The script also includes a continuous loop that checks the current time and executes the execute_trades() function only during market hours. The loop waits for 10 minutes before checking prices again when the market is closed. The account buying power is also displayed at the end of the loop.

Together with the first Python script, this trading bot can execute trades based on the RSI indicator and optimize RSI thresholds for a list of symbols.

proposed architecture
https://lucid.app/lucidchart/d96484a1-0512-4078-a13d-1e9bd7d0ec71/edit?invitationId=inv_62e35864-64e3-4c21-8d3b-2cea6fcc304c&page=0_0#

rsibot's People

Contributors

mikaeelkhalid avatar zfarrell13 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.