Skip to content

Commit

Permalink
Make IBKRCATEGORY an environment variable for self-hosting (#22)
Browse files Browse the repository at this point in the history
* Move IBKR CATEGORY to Env variable to support self-hosted.

* Update doc

* Make Dockerfile more robust for multi arch support

* Make Dockerfile more robust for multi arch support

* Clean Dockerfile

* Revert reqs back to default
  • Loading branch information
Trefex authored Jul 9, 2024
1 parent 00bcbdf commit 3388880
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 7 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ RUN apk add git
WORKDIR /usr/app/src
COPY requirements.txt .
RUN pip3 install -r requirements.txt
ADD https://github.com/Yelp/dumb-init/releases/download/v1.2.1/dumb-init_1.2.1_amd64 /bin/dumb-init
RUN apk add dumb-init
COPY ./entrypoint.sh /root/entrypoint.sh
COPY ./run.sh /root/run.sh
RUN chmod 777 /root/entrypoint.sh /root/run.sh /bin/dumb-init
RUN chmod 777 /root/entrypoint.sh /root/run.sh
COPY main.py .
COPY SyncIBKR.py .
ENTRYPOINT ["dumb-init", "--"]
Expand Down
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,19 @@ curl -X POST -H "Content-Type: application/json" \
|**CRON** | (optional) To run on a [Cron Schedule](https://crontab.guru/) |
|**OPERATION** | (optional) SYNCIBKR (default) or DELETEALL (will erase all operations of all accounts) |

### Configuring / Retrieving Platform ID

If you are using ghostfolio self-hosted option, you need to go into Ghostfolio and add a platform for IBKR.

Then do a request to `/account` to find the relevant platform ID and store it in the GHOST_IBKR_PLATFORM env variable

```bash
curl "http://10.0.0.2:3333/api/v1/account" \
-H "Authorization: Bearer $GHOST_TOKEN"

export GHOST_IBKR_PLATFORM=<PUT PLATFORM ID HERE>
```

## Contributing

* Feel free to submit any issue or PR's you think necessary
Expand Down
9 changes: 5 additions & 4 deletions SyncIBKR.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ def get_diff(old_acts, new_acts):

class SyncIBKR:
IBKRNAME = "Interactive Brokers"
IBKRCATEGORY = "66b22c82-a96c-4e4f-aaf2-64b4ca41dda2"
#IBKRCATEGORY = "66b22c82-a96c-4e4f-aaf2-64b4ca41dda2"

def __init__(self, ghost_host, ibkrtoken, ibkrquery, ghost_key, ghost_token, ghost_currency):
def __init__(self, ghost_host, ibkrtoken, ibkrquery, ghost_key, ghost_token, ghost_currency, ghost_ibkr_platform):
if ghost_token == "" and ghost_key != "":
self.ghost_token = self.create_ghost_token(ghost_host, ghost_key)
else:
Expand All @@ -64,6 +64,7 @@ def __init__(self, ghost_host, ibkrtoken, ibkrquery, ghost_key, ghost_token, gho
self.ghost_currency = ghost_currency
self.ibkrtoken = ibkrtoken
self.ibkrquery = ibkrquery
self.ibkrplatform = ghost_ibkr_platform

def sync_ibkr(self):
print("Fetching Query")
Expand Down Expand Up @@ -156,7 +157,7 @@ def set_cash_to_account(self, account_id, cash):
"currency": self.ghost_currency,
"isExcluded": False,
"name": self.IBKRNAME,
"platformId": self.IBKRCATEGORY
"platformId": self.ibkrplatform
}

url = f"{self.ghost_host}/api/v1/account/{account_id}"
Expand Down Expand Up @@ -243,7 +244,7 @@ def create_ibkr_account(self):
"currency": self.ghost_currency,
"isExcluded": False,
"name": self.IBKRNAME,
"platformId": self.IBKRCATEGORY
"platformId": self.ibkrplatform
}

url = f"{self.ghost_host}/api/v1/account"
Expand Down
3 changes: 2 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@
ghost_hosts = os.environ.get("GHOST_HOST", "https://ghostfol.io").split(",")
ghost_currency = os.environ.get("GHOST_CURRENCY", "USD").split(",")
operations = os.environ.get("OPERATION", SYNCIBKR).split(",")
ghost_ibkr_platform = os.environ.get("GHOST_IBKR_PLATFORM", "66b22c82-a96c-4e4f-aaf2-64b4ca41dda2").split(",")

if __name__ == '__main__':
for i in range(len(operations)):
ghost = SyncIBKR(ghost_hosts[i], ibkr_tokens[i], ibkr_queries[i], ghost_keys[i], ghost_tokens[i], ghost_currency[i])
ghost = SyncIBKR(ghost_hosts[i], ibkr_tokens[i], ibkr_queries[i], ghost_keys[i], ghost_tokens[i], ghost_currency[i], ghost_ibkr_platform[i])
if operations[i] == SYNCIBKR:
print("Starting sync")
ghost.sync_ibkr()
Expand Down

0 comments on commit 3388880

Please sign in to comment.