A modular financial assistant: run your investments in the background.
Enigma Capital observes two use-cases. It functions as both a Financial Assistant and a Developer Skills Enhancer.
This repository allows you to run your finances in the background, freeing you to do anything else. Current features include:
- Monitoring and saving your positions and balances across crypto and traditional exchanges;
- Conducting analysis on collected data;
- Building and tracking performance records;
- Quantifying investment theses, creating dashboards, and delivering them to your chosen Telegram channel.
Supported Exchanges
- Binance;
- Bybit;
- DYDX;
- Ethereum;
- Interactive Brokers;
- TradeStation;
- FTX;
- Kraken;
- RootStock;
The Account Data Fetcher follows a modular architecture:
Adding new components is straightforward—simply extend the existing base classes. The codebase uses verbose, Google-style docstrings for clarity and is filled with To-dos to guide contributors who are uncertain where to begin.
- Install virtualenv:
sudo pip install virtualenv
- Clone the repo or a fork of it
- Navigate to the base repo directory and run:
virtualenv env
- Activate your virtual environment:
source env/bin/activate
- Install the requirements:
pip install -r requirements.txt
- Install Rust for the cryptography library:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
- Generate a Private Key:
Create a private key usingencryptor.py
in/utilities
(with a password!). The project looks for private keys in both./account_data_fetcher/secrets/
and./monitor/
directories. Run the below in both directories to set-up your./pk.txt
:
- From
./monitor
:
python3 ../utilities/encryptor.py
- and from
./account_data_fetcher/secrets/
:
python3 ../../utilities/encryptor.py
- Set API Keys:
Useencryptor.py
with the functionwrite_api_key_enc_to_file
, then add additional keys usingadd_keys_to_encrypted_file
. Use the following pattern, and source "Other_fields" informations from here
key_information = {
"Key": "",
"Secret": "",
"Other_fields": {}
}
- Create an Encrypted
.gsheet.txt
File:
If using gsheet as write parameters, obtain JSON from Google (cf tutorial) - Thesis Monitoring Setup:
Repeat steps 6 and 7 in the/thesis_monitoring
directory. - Run the Scripts:
You may need to make the script executable first:
chmod+x scriptname.sh
Run the scripts. To move them to the background after entering your password, press CTRL+z
, then run bg
. disown
if needed.
For those needing higher frequency than daily data, use the IBC gateway. Raspberry Pi users, take note: this is currently not possible for you. If you're inexperienced, I wouldn't recommend using the below.
IBC requirements:
-
iI
java -version
returns nothing, install Java:
sudo apt install default-jdk
On Unix:
- Unzip the File:
Unpack the ZIP file with the following command
sudo unzip ~/Downloads/IBCLinux-3.6.0.zip -d /opt/ibc
- Set File Permissions:
Ensure all script files are executable
cd /opt/ibc
sudo chmod o+x *.sh */*.sh
- Check Version:
Verify the major version number for TWS in the shell scripts located in the IBC folder. Files to check:
- Windows:
StartTWS.bat
,StartGateway.bat
- Unix:
twsstart.sh
,gatewaystart.sh
- macOS:
twsstartmacos.sh
,gatewaystartmacos.sh
- Find Major Version Number:
Run TWS or the Gateway manually through the IBKR-provided icon. Navigate to Help > About Trader Workstation or Help > About IB Gateway. Look for a line like:
Build 10.19.1f, Oct 28, 2022 3:03:08 PM
- Windows/Linux: Major version is 1019 (ignore the period)
- MacOS: Major version is 10.19
-
Edit Scripts:
Open the script files and make sure the TWS_MAJOR_VRSN variable is set correctly. -
Set Environment Variable:
For zsh shells, add ENIGMA as an environment variable:
echo 'export ENIGMA=~/Documents/dev/enigma_capital ' >> ~/.zshenv`
- Take a look at account_data_fetcher, how could you refactor the entire monitor component? (source)
- Handle subscription on per topic basis (source)
- For the bravest, automate the below by listening to withdraw/deposits for each exchanges and updating the database as needed. (source)
- Process request is the only entry-point at the factory level. This could be made more generic to accomodate for other entry-points and inputs as the application scales. (source)
- For now, we only enforce two methods implementation, namely fetch_balance and fetch_positions. As such, process_request is quite statically defined as well. How could we untangle both so that we can define more abstract methods and have the process_request understands what to fetch dynamically. (source)
- Fetch positions (source)
- Fix arbitrary ConnectionResetError bug requests.exceptions.ConnectionError: ('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer')) (source)
- Batch calls via multicall contracts + use helios lightweight client (need to fix eth_call loops, broken atm) (source)
- Only localhost is supported for components communication. Allow support for other hosts! (source)
- Be able to subscribe to different topics, so that the data_aggregator can scale easily to more usecases (source)
- Handle failure. What if an exchange stop publishing and we just loop forever? Need some form of heartbit logic. (source)
- Make the function more modular, the data_aggregator should be agnostic to what data is being aggregated as that should be abstracted away. (source)
- Properly parse the object below so that the inner dataclass can be read as a dataclass, and not accessed as a dict (source)