git clone --recurse-submodules -j8 https://github.com/trentstauff/FXBot
FXBot is just what you guessed- a Forex trading bot! It's been developed in Python, enabled by the OANDA V20 API.
This trading bot allows users to backtest and analyze their favourite strategies executed on the most popular currency pairs, while also enabling users to dive straight into trading these forex pairs in real-time, through algorithmic live trading.
As we all know, algorithmic trading is the future of finance. When looking at the top trading firms in the world, all of them are making a shift towards automated trading, and are investing heavily in the space. The ones who don't automate, are at risk of falling behind their competitors!
That's what inspired me to make this bot, and to expose to the public how really anyone this day and age can jump headfirst into the algorithmic trading world.
Before downloading and using this bot, please make sure to understand the following:
Through OANDA, you do NOT need to trade real money, and the same is true with respect to using this bot. OANDA offers practice accounts, which this bot is highly recommended to utilize.
If you do decide to trade real money, this disclaimer is for you.
Trading Forex involves a risk of loss. Please consider carefully if such trading is appropriate for you. Past performance is not indicative of future results. FXBot has been created solely for educational purposes only and its calculations do not constitute investment recommendations or advice, and it is strongly recommended that you use this bot as a learning tool.
If you are to trade using this bot, understand that algorithmic trading involves a high level of risk and is not appropriate for everyone. No guarantee is being made that by using this bot, the algorithmic trading strategies will result in profitable trading or be free of risk of loss. There is a possibility that you could lose some or all of your investment.
When you first run FXBot, you will be prompted to enter the following:
- The currency pair you would like to analyze/trade
- Whether to conduct backtesting or live trading on said currency pair
Backtesting is a method for seeing how well a strategy would have performed on historical data. This powerful technique can gather a lot of important information about the strategy- such as when is the best time for the strategy to operate, which currency pairs it should execute on, and much more. If the strategy performs well during backtesting, then individuals can look into putting the strategy into a production environment and try to beat the market.
FXBot enables users to backtest their strategies, alongside giving flexibility and customization surrounding the parameters passed to the backtester.
When running the backtesting section of the bot, users will be prompted to specify the following:
- The strategy to backtest
- The date range the backtest should occur over
- Whether the strategy should consider trading costs
- The granularity for the backtest session (IE how often should the bot analyze the data and consider positions)?
- Values unique to the strategy (if these values are with respect to time, such as moving averages, the time unit is the same as your specified granularity)
Note: For Backtesting, here are the accepted granularity values you can choose from. You must enter a choice from this list. For live trading, please follow the on screen prompts to enter something along the lines of "1hr" or "30s".
After entering this, the bot will go ahead and conduct the backtesting.
Not only will it test the user's specified parameter choices onto the currency pair, but the bot will also find the most optimal parameter values for that time period that allows for the highest ROI. This optimization gives critical information that can be further analyzed by the user to find the best values for their trading situation.
Finally, the bot will plot the results so that the user can tangibly see the performance of the strategy.
Once you believe you have found a good strategy and have optimized its unique parameters, you can jump into live trading.
Live trading is exactly how it sounds, it utilizes algorithmic, event-driven trading that allows the user to execute the strategy on data as it happens in real-time. This is where you can realize the full potential of your strategy and see how it performs against the market.
When running the live trading section of the bot, users will be prompted to specify the following:
- The strategy to backtest
- The date range the backtest should occur over
- The granularity for the trading session (IE how often should the bot analyze the data and consider positions)?
- The number of units to trade with (IE the size you want your positions to be)
- OPTIONAL: A "stop profit" to halt trading if you reach
- OPTIONAL: A "stop-loss" to halt trading if you go below
- Values unique to the strategy (if these values are with respect to time, such as moving averages, the time unit is the same as your specified granularity)
Once the bot is set up and ready to trade, the trading stream will open. For the duration of the session, the console will continuously output each "tick" of data that is being streamed back to the bot, which contains the time of the tick, the bid price, and the ask price.
Every "granularity", the bot will analyze the current market and determine if it should open, close, modify, or hold a position, which is based on the underlying strategy.
If any of the stop thresholds have been crossed, or if the user terminates the session, the bot will automatically exit all of its current positions, and the console will default back to the start, where the user can start over.
- SMA https://www.google.com/search?q=sma+strategy&oq=SMA+strategy&aqs=chrome.0.0i512j0i67j0i512l2j0i22i30l6.1680j0j7&sourceid=chrome&ie=UTF-8
- Bollinger Bands https://www.investopedia.com/trading/using-bollinger-bands-to-gauge-trends/
- Contrarian https://www.investopedia.com/terms/c/contrarian.asp
- Momentum https://www.investopedia.com/terms/m/momentum_investing.asp
- Machine Learning Classification Analysis
- Machine Learning Regression Analysis
- And much more to come!
You can start off by cloning the repo by running git clone --recurse-submodules -j8 https://github.com/trentstauff/FXBot
First, you need to have at least a practice account with Oanda (https://oanda.com/). Once logged in, you must create an API token and copy your account number.
This green button will say "Generate". Click it, and copy the API Token.
Navigate back to your account, so you can get your account number.
Make an account. Make sure to select 'v20 fxTrade'
Once you have made an account, grab your account number.
Now that you have an OANDA account and these values, you'll need to store them for the bot to use.
These values need to be put into a configuration file, with the name oanda.cfg
, as follows:
(You can make it a .txt file first, type the data, and then rename the file to .cfg)
[oanda]
account_id = XYZ-ABC-...
access_token = ZYXCAB...
account_type = practice (default) or live
Place the oanda.cfg file into the same directory as the main.py file in the cloned repository folder.
After cloning the repo, run pip install -r requirements.txt
to get the required packages.
After installing the requirements, open a command prompt and you can start up the program by typing python main.py
(python3 on Linux, if applicable) while in its directory.