Giter VIP home page Giter VIP logo

ghostfolio-sync's Introduction

Ghostfolio-Sync

Docker Hub package

Sync your Ghostfolio with IBKR ( more to come? Help is always welcome! )

Setup

IBKR

Important: When you configure your Flex Query give it: Cash report and Cash transactions and Trades and nothing else

Follow this guide to configure your Flex Queries in your Interactive Brokers account: https://help.wealthica.com/help/how-to-connect-ib-interactive-brokers-and-configure-the-flex-report

Important: If you dont want ghostfolio-sync to sync everything everytime and make it quicker, just set a shorter window for the query. Keep in mind that what was not synced by ghostfolio-sync in that period of time will be lost (ie when the window moves and content was not uploaded to ghostfolio). This can be avoided at the cost of a longer window of time and longer sync

Ghostfolio

  • Take note of your user KEY (generated upon user creation and used to login to Ghostfolio)
  • Run the following on the terminal (replace ghostfol.io with localhost or your host url if you are self-hosting):
curl -X POST -H "Content-Type: application/json" \
	-d '{ "accessToken": "YOUR-USER-KEY-GOES-HERE }' \    
	https://ghostfol.io/api/v1/auth/anonymous
  • Take note of the token {"authToken":"12cd45.... That is your GHOST_TOKEN

Run in Docker

docker run -e GHOST_TOKEN=YOUR_GHOST_TOKEN -e IBKR_TOKEN=YOUR-IBKR-TOKEN -e IBKR_QUERY=YOUR-IBKR-QUERY agusalex/ghostfolio-sync

In Podman

podman run -e GHOST_TOKEN=YOUR_GHOST_TOKEN -e IBKR_TOKEN=$IBKR_TOKEN -e IBKR_QUERY=$IBKR_QUERY -e GHOST_HOST=http://$GHOST_URL -e GHOST_CURRENCY=EUR -e GHOST_IBKR_PLATFORM=$IBKR_PLATFORM -v ./mapping.yaml:/usr/app/src/mapping.yaml:Z agusalex/ghostfolio-sync

Symbol mapping

You can specify the symbol mappings in mapping.yaml and you do not need to rebuild the container with the above mount command.

More Options

Envs Description
IBKR_TOKEN Your Token
IBKR_QUERY Your Query ID
GHOST_TOKEN The token for your ghostfolio account
GHOST_KEY The key for your ghostfolio account, if this is used you don't need GHOST_TOKEN and vice-versa
GHOST_HOST (optional) Ghostfolio Host, only add if using custom ghostfolio
GHOST_CURRENCY (optional) Ghostfolio Account Currency, only applied if the account doesn't exist
GHOST_IBKR_PLATFORM (optional) For self-hosted, specify the Platform ID
CRON (optional) To run on a Cron Schedule
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 make a request to /account to find the relevant platform ID and store it in the IBKR_PLATFORM env variable

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

export IBKR_PLATFORM=<PUT PLATFORM ID HERE>

Contributing

  • Feel free to submit any issue or PR's you think necessary
  • If you like the work and want to buy me a coffee you are more than welcome :)

Buy Me A Coffee

ghostfolio-sync's People

Contributors

agusalex avatar cellulosa avatar elgohr avatar longstone avatar paulsp94 avatar pvieira84 avatar trefex avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

ghostfolio-sync's Issues

Issue when running container

Hi,

I tried your container, i rebuilt it for ARM, and I receive following error.

Not sure how to proceed?

Many thanks,
T

[sysadmin@rocky-4gb-fsn1-rc-1 ghostfolio-sync]$ podman run -e GHOST_TOKEN=$GHOST_TOKEN -e IBKR_TOKEN=$IBKR_TOKEN -e IBKR_QUERY=$IBKR_QUERY localhost/trefex/ghostfolio-sync
[2024-07-07 22:10:00] Starting ghostfolio-sync Docker...
[2024-07-07 22:10:00] Crontab Not Present running one time now
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/ibflex/parser.py", line 115, in parse_data_element
    attrs = dict(
  File "/usr/local/lib/python3.9/site-packages/ibflex/parser.py", line 116, in <genexpr>
    parse_element_attr(Class, k, v)
  File "/usr/local/lib/python3.9/site-packages/ibflex/parser.py", line 156, in parse_element_attr
    Type = Class.__annotations__[name]
KeyError: 'issuerCountryCode'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/app/src/main.py", line 22, in <module>
    ghost.sync_ibkr()
  File "/usr/app/src/SyncIBKR.py", line 71, in sync_ibkr
    query: FlexQueryResponse = parser.parse(response)
  File "/usr/local/lib/python3.9/site-packages/ibflex/parser.py", line 53, in parse
    parsed = parse_element(root)
  File "/usr/local/lib/python3.9/site-packages/ibflex/parser.py", line 85, in parse_element
    return parse_data_element(elem)
  File "/usr/local/lib/python3.9/site-packages/ibflex/parser.py", line 125, in parse_data_element
    contained_elements = {child.tag: parse_element(child) for child in elem}
  File "/usr/local/lib/python3.9/site-packages/ibflex/parser.py", line 125, in <dictcomp>
    contained_elements = {child.tag: parse_element(child) for child in elem}
  File "/usr/local/lib/python3.9/site-packages/ibflex/parser.py", line 80, in parse_element
    return parse_element_container(elem)
  File "/usr/local/lib/python3.9/site-packages/ibflex/parser.py", line 101, in parse_element_container
    instances = tuple(parse_data_element(child) for child in elem)
  File "/usr/local/lib/python3.9/site-packages/ibflex/parser.py", line 101, in <genexpr>
    instances = tuple(parse_data_element(child) for child in elem)
  File "/usr/local/lib/python3.9/site-packages/ibflex/parser.py", line 125, in parse_data_element
    contained_elements = {child.tag: parse_element(child) for child in elem}
  File "/usr/local/lib/python3.9/site-packages/ibflex/parser.py", line 125, in <dictcomp>
    contained_elements = {child.tag: parse_element(child) for child in elem}
  File "/usr/local/lib/python3.9/site-packages/ibflex/parser.py", line 83, in parse_element
    return parse_element_container(elem)
  File "/usr/local/lib/python3.9/site-packages/ibflex/parser.py", line 101, in parse_element_container
    instances = tuple(parse_data_element(child) for child in elem)
  File "/usr/local/lib/python3.9/site-packages/ibflex/parser.py", line 101, in <genexpr>
    instances = tuple(parse_data_element(child) for child in elem)
  File "/usr/local/lib/python3.9/site-packages/ibflex/parser.py", line 121, in parse_data_element
    raise FlexParserError(msg)
ibflex.parser.FlexParserError: Trade has no attribute 'issuerCountryCode'
[2024-07-07 22:10:07] Starting sync
[2024-07-07 22:10:07] Fetching Query
[2024-07-07 22:10:07] Parsing Query```

No connection adapters were found for

Hi @agusalex

I managed to fix the lib, but now I get the following when trying to connect to self hosted ghostfolio.

Would you know what could be the issue here?

[sysadmin@rocky-4gb-fsn1-rc-1 ghostfolio-sync]$ podman run -e GHOST_TOKEN=$GHOST_TOKEN -e IBKR_TOKEN=$IBKR_TOKEN -e IBKR_QUERY=$IBKR_QUERY -e GHOST_HOST=127.0.0.1:3333 localhost/trefex/ghostfolio-sync[2024-07-08 16:15:25] Starting ghostfolio-sync Docker...
[2024-07-08 16:15:25] Crontab Not Present running one time now
[2024-07-08 16:15:32] Starting sync
[2024-07-08 16:15:32] Fetching Query
[2024-07-08 16:15:32] Parsing Query
[2024-07-08 16:15:32] Finding IBKR account
[2024-07-08 16:15:32] No connection adapters were found for '127.0.0.1:3333/api/v1/account'
[2024-07-08 16:15:32] Creating IBKR account
[2024-07-08 16:15:32] No connection adapters were found for '127.0.0.1:3333/api/v1/account'
[2024-07-08 16:15:32] Failed to retrieve account ID closing now
[2024-07-08 16:15:32] End sync```

Many thanks
T

Can be run in local ghostfolio?

Hi team,

I did all the steps, creating an flex query on Interactive Brokers and enabled the Flex Web Service

I put all the information as your instructions and I'm getting this error:

[2023-09-06 10:24:10] Starting ghostfolio-sync Docker...
[2023-09-06 10:24:10] Crontab Not Present running one time now
Traceback (most recent call last):
  File "/usr/app/src/main.py", line 11, in <module>
    ibkr_tokens = os.environ.get("IBKR_TOKEN").split(",")
AttributeError: 'NoneType' object has no attribute 'split'

Can you help me understand what i'm doing wrong?

Thank you

Failed creating

hi there, I'm trying get this to work with Ghostfolio 2.12.0. It seems like few things have changed? Also from the IBKR side?

here's what I get when I try and run the container:


[2023-10-18 16:55:36] Starting ghostfolio-sync Docker...
[2023-10-18 16:55:36] Crontab Not Present running one time now
Traceback (most recent call last):
  File "/usr/app/src/main.py", line 22, in <module>
    ghost.sync_ibkr()
  File "/usr/app/src/SyncIBKR.py", line 74, in sync_ibkr
    account_id = self.create_or_get_IBKR_accountId()
  File "/usr/app/src/SyncIBKR.py", line 253, in create_or_get_IBKR_accountId
    accounts = self.get_account()
  File "/usr/app/src/SyncIBKR.py", line 250, in get_account
    raise Exception(response)
Exception: <Response [502]>
[2023-10-18 16:55:37] Starting sync
[2023-10-18 16:55:37] Fetching Query
[2023-10-18 16:55:37] Parsing Query
[2023-10-18 16:55:39] Fetching Query
,"MIG":"Migranet","MIININGNFT": (bazillion characters in here so had to cut it) return this.prismaService.marketData.deleteMany(
[2023-10-18 16:55:39] Failed creating 
[2023-10-18 16:55:39] Failed to retrieve account ID closing now
[2023-10-18 16:55:39] End sync
gghostfolio-sync exited with code 0

Failed create

Hello,

I'm new to self hosting. I'm trying to set up ghostfolio-sync. This is the log i get.

[2024-02-07 18:14:49] Starting ghostfolio-sync Docker...
[2024-02-07 18:14:49] Crontab Not Present running one time now
[2024-02-07 18:14:56] Starting sync
[2024-02-07 18:14:56] Fetching Query
[2024-02-07 18:14:56] Parsing Query
[2024-02-07 18:14:56] unsupported operand type(s) for +=: 'decimal.Decimal' and 'NoneType'
[2024-02-07 18:14:56] Failed create: {"message":["property accountType should not exist"],"error":"Bad Request","statusCode":400}

Request

docker run -e GHOST_HOST=localhost -e GHOST_TOKEN=YOUR_GHOST_TOKEN -e IBKR_TOKEN=IBKR-TOKEN -e IBKR_QUERY=IBKR-QUERY agusalex/ghostfolio-sync

Failed download statements

Hey,

Getting an error trying to sync between IBKR and self-hosted ghostfolio.

Traceback (most recent call last):
  File "/usr/app/src/main.py", line 22, in <module>
    ghost.sync_ibkr()
  File "/usr/app/src/SyncIBKR.py", line 69, in sync_ibkr
    response = client.download(self.ibkrtoken, self.ibkrquery)
  File "/usr/local/lib/python3.9/site-packages/ibflex/client.py", line 114, in download
    stmt_access = request_statement(token, query_id)
  File "/usr/local/lib/python3.9/site-packages/ibflex/client.py", line 142, in request_statement
    raise ResponseCodeError(

Request

docker run -e GHOST_TOKEN="token "-e IBKR_TOKEN=token -e IBKR_QUERY=Ghostfolio -e GHOST_HOST=localhost agusalex/ghostfolio-sync

Adapt for docker compose

I'm trying to create this container with docker compose but not succeeding because we it needs the bearer token as an env variable. Would it be possible to supply the ghostfolio user key instead and the script would then fetch the bearer token?

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.