This repository is dependent upon the API from Gain Capital's Forex.com. To make an account visit their website Forex.com. Once an account is made you will need to send them an email and request an API key.
Please see a link to required dependencies below. If you are in Linux, Boost, OpenSSL, libsecret, & libmicrohttpd can be installed with the following commands below.
Fedora:
dnf install boost-devel openssl-devel libsecret-devel libmicrohttpd-devel
Debian:
apt-get install libboost-all-dev libssl-dev libsecret-1-dev libmicrohttpd-devel
Arch:
pacman -Ss boost libmicrohttpd
pacman -S --needed openssl
pacman -Sy libsecret
The arguments to the main function are as follows:
./FX-Order-Management -a [Account Type], -p [Place Trades] -m [Max Retry Failures] -e [Emergency Close] -f [File Logging]
Types:
Account Type: String - Must be "Live" or "Paper"
Place Trades: Boolean
Emergency Close: Boolean
File Logging: Boolean
Max Retry Failures: Int
The default settings in the main.cpp file are the following:
int main(int argc, char* argv[])
{
// USER INPUT DEFAULTS
std::string ACCOUNT = "PAPER";
bool PLACE_TRADES = true, EMERGENCY_CLOSE = false, FILE_LOGGING = true;
int MAX_RETRY_FAILURES = 3;
...
The user should replace the usernames and API key, but the password should not be stored in plain text. The program will prompt the user to assign a new password if one doesn't already exist in the keyring.
{
"Username": "Blank",
"Paper_Username": "Blank",
"API_Key": "Blank",
"Positions": [
"USD/JPY",
"EUR/USD",
"USD/CHF",
"USD/CAD"
],
"Order_Size": 1000,
"Update_Interval": "Minute",
"Update_Span": 5,
"Num_Data_Points": 10000,
"Start_Hour_London_Exchange": 8,
"End_Hour_London_Exchange": 20
}
Types:
Order_Size: Intervals of 1,000;
Update_Interval: Minute or Hour;
Update_Span: MINUTES: 1, 2, 3, 5, 10, 15, 30; HOURS: 1, 2, 4, 8;
Start_Hour_London_Exchange: 0 - 24; All local times are adjusted to coordinate with the London Forex Exchange;
End_Hour_London_Exchange: 0 - 24; All local times are adjusted to coordinate with the London Forex Exchange;
The user can replace the order parameters with any valid combination as described in the Gain Capital API documents. In the case of a typo, the code provides appropriate checks to confirm the user is compliant with the documentation.
User will be prompted the first time they use the application. The password will be stored securely in the keyring and automatically loaded for the next use.
Please don't run in a live trading environment with the placeholder trading model provided. The user should modify with their own trading strategy.
int FXTradingModel::send_trading_signal()
{
// Replace with User's Code
return (rand() % 2) ? 1 : -1;
}
{
"Last Updated": "Thu Feb 1 14:04:06 2024",
"Performance Information":
{
"Current Funds": 45884.16,
"Inital Funds": 45887.76,
"Margin Utilized": 121.73,
"Profit Cumulative": -3.59,
"Profit Percent Cumulative": -0.0
},
"Position Information":
{
"EUR/USD":
{
"Current Price": 1.087210,
"Direction": "buy",
"Entry Price": 1.08727,
"Profit": -5.999999e-05,
"Profit Percent": -0.009999,
"Quantity": 1000.0
},
"USD/CAD":
{
"Current Price": 1.337329,
"Direction": "buy",
"Entry Price": 1.33754,
"Profit": -0.000209,
"Profit Percent": -0.019999,
"Quantity": 1000.0
}
}
}
Changing the value to true will either close the trade immediately upon the update interval, or wait until the trading model signal changes.
{
"EUR/USD":
{
"Close_Position": false,
"Position_Size_Multiple": 1.0
},
"USD/CAD":
{
"Close_Position": false,
"Position_Size_Multiple": 1.0
}
}
Types:
Close_Position: true or false; Closes position at next update interval;
Position_Size_Multiple: Any Double Number; Changes the quantity relative to the Order_Size;
$ mkdir build
$ cmake -S . -B build
$ cmake --build build --target FX-Order-Management
This repository contains a .devcontainer directory. The .devcontainer has all the required dependencies and can be run inside Docker with the Dev Containers VSCode extension.
- C++ Requests Library
- Nlohmann JSON Library
- Gain Capital API C++
- Keychain
- httpmockserver | Testing Only
- Boost
- Libsecret - For Linux
- OpenSSL
- Google Tests | Testing Only
- libmicrohttpd | Testing Only
This software is distributed under the GNU license. Please read LICENSE for information on the software availability and distribution.
Please open an issue of if you have any questions, suggestions, or feedback.
Please submit bug reports, suggestions, and pull requests to the GitHub issue tracker.