# rework from the original @
# https://github.com/waytrade/ib-gateway-docker/blob/master/docker-compose.yml
version: "3.5"


services:

  ib_gw_paper:

    # apparently java is a mega cukc:
    # https://stackoverflow.com/a/56895801
    # https://bugs.openjdk.org/browse/JDK-8150460
    ulimits:
      # nproc: 65535
      nproc: 6000
      nofile:
        soft: 2000
        hard: 3000

    # other image tags available:
    # https://github.com/waytrade/ib-gateway-docker#supported-tags
    # image: waytrade/ib-gateway:1012.2i
    image: ghcr.io/gnzsnz/ib-gateway:latest

    restart: 'no'  # restart on boot whenev there's a crash or user clicsk
    network_mode: 'host'

    volumes:
      - type: bind
        source: ./jts.ini
        target: /root/Jts/jts.ini
        # don't let IBC clobber this file for
        # the main reason of not having a stupid
        # timezone set..
        read_only: true

      # force our own IBC config
      - type: bind
        source: ./ibc.ini
        target: /root/ibc/config.ini

      # force our noop script - socat isn't needed in host mode.
      - type: bind
        source: ./fork_ports_delayed.sh
        target: /root/scripts/fork_ports_delayed.sh

      # force our noop script - socat isn't needed in host mode.
      - type: bind
        source: ./run_x11_vnc.sh
        target: /root/scripts/run_x11_vnc.sh
        read_only: true

    # NOTE:to fill these out, define an `.env` file in the same dir as
    # this compose file which looks something like:
    # TWS_USERID='myuser'
    # TWS_PASSWORD='guest'
    environment:
      TWS_USERID: ${TWS_USERID}
      TWS_PASSWORD: ${TWS_PASSWORD}
      TRADING_MODE: 'paper'
      VNC_SERVER_PASSWORD: 'doggy'
      VNC_SERVER_PORT: '3003'

    # ports:
    #   - target: 4002
    #     host_ip: 127.0.0.1
    #     published: 4002
    #     protocol: tcp

      # original mappings for use in non-host-mode
      # which we won't really need going forward since
      # ideally we just pick the port to have ib-gw listen
      # on **when** we spawn the container - i.e. everything
      # will be driven by a ``brokers.toml`` def.
      # - "127.0.0.1:4001:4001"
      # - "127.0.0.1:4002:4002"
      # - "127.0.0.1:5900:5900"

  # ib_gw_live:
  #   image: waytrade/ib-gateway:1012.2i
  #   restart: no
  #   network_mode: 'host'

  #   volumes:
  #     - type: bind
  #       source: ./jts_live.ini
  #       target: /root/jts/jts.ini
  #       # don't let ibc clobber this file for
  #       # the main reason of not having a stupid
  #       # timezone set..
  #       read_only: true

  #     # force our own ibc config
  #     - type: bind
  #       source: ./ibc.ini
  #       target: /root/ibc/config.ini

  #     # force our noop script - socat isn't needed in host mode.
  #     - type: bind
  #       source: ./fork_ports_delayed.sh
  #       target: /root/scripts/fork_ports_delayed.sh

  #     # force our noop script - socat isn't needed in host mode.
  #     - type: bind
  #       source: ./run_x11_vnc.sh
  #       target: /root/scripts/run_x11_vnc.sh
  #       read_only: true

  #   # NOTE: to fill these out, define an `.env` file in the same dir as
  #   # this compose file which looks something like:
  #   environment:
  #     TRADING_MODE: 'live'
  #     VNC_SERVER_PASSWORD: 'doggy'
  #     VNC_SERVER_PORT: '3004'