Skip to main content

APISIX Setup

Finmars APISIX Setup Guide

Abstract

As result of that instruction you will have proxy to Exante Broker e.g. https://exante-proxy.client.com where client.com your domain

Prerequisites

Before starting make sure you have the following:

  1. Setting up AWS EC2 with Ubuntu, Docker, and a Public IP
    1. A machine running Linux with Ubuntu 22.04.
    2. Docker installed on your machine.
    3. A public IP address.
  2. Generated API keys in Exante Account Page

Steps to Set Up APISIX

  1. Run command to add your user to docker group to execute commands:
    sudo usermod -a -G docker $USER
    
    You need to relogin to VM:
     exit
    
    And connect again. To check if it's in effect, run to see current docker images:
    docker ps
    
  2. Create the apisix.yaml Configuration File with your desired configuration:
    1. Run command to create a file:
      nano apisix.yaml
      
    2. Copy paste content of the yaml script below.
    3. You need to replace
  3. Run the APISIX Docker Container:
    docker run -d --name apache-apisix -p 9080:9080 -p 9443:9443 -e APISIX_STAND_ALONE=true apache/apisix
    
  4. Copy the <strong class="editor-theme-bold editor-theme-code">apisix.yaml</strong> File to the APISIX Container:
    docker cp apisix.yaml apache-apisix:/var/tmp/
    
  5. Move the <strong class="editor-theme-bold editor-theme-code">apisix.yaml</strong> File to the APISIX Configuration Directory:
    docker exec -i apache-apisix sh -c 'cp /var/tmp/apisix.yaml /usr/local/apisix/conf/'
    
  6. Reload the APISIX Configuration:
    docker exec -it apache-apisix apisix reload
    

Setting Up HTTPS

If you want your APISIX instance to listen for HTTPS connections, follow these additional steps:

  1. Obtain an SSL Certificate:
    Get or create an SSL certificate and export it along with its private key to PEM format.
  2. Update <strong class="editor-theme-bold editor-theme-code">ssls.yaml</strong>**:**
    Put the PEM contents into the corresponding sections of <span class="editor-theme-code">ssls.yaml</span>.
  3. Include SSL Configuration in <strong class="editor-theme-bold editor-theme-code">apisix.yaml</strong>**:**
    Add the contents of <span class="editor-theme-code">ssls.yaml</span> to <span class="editor-theme-code">apisix.yaml</span> before the <span class="editor-theme-code">#END</span> instruction.

apisix.yaml file content:

apisix:
  node_listen: 9080           # HTTP inbound port
  ssl:
    enable: true
    listen:
      - port: 9443           # HTTPS inbound port
        enable_http3: false

consumers:
  - username: finmars        # client name
    plugins:
      basic-auth:
        username: ***YOUR_USERNAME***        # inbound credentials, that you will pass to Finmars IT Team
        password: ***YOUR_PASSWORD***


# upstream.yaml

upstreams:
  - id: 1
    nodes:
      api-demo.exante.eu:443: 1
    scheme: https
    pass_host: node
    type: roundrobin
  - id: 2
    nodes:
      api-live.exante.eu:443: 1
    scheme: https
    pass_host: node
    type: roundrobin


# plugin_config.yaml

plugin_configs:
  - id: 1
    plugins:
      basic-auth: {}
      proxy-rewrite:
        headers:
          set:  # credentials used to connect to api-demo.exante.eu # Basic Auth string from API key and Secret Key
            Authorization: "Basic ***YOUR_BASE64_TOKEN***"
        regex_uri:
          - "^/demo/(.*)"
          - "/$1"
  - id: 2
    plugins:
      basic-auth: {}
      proxy-rewrite:
        headers:
          set:  # credentials used to connect to api-live.exante.eu # Basic Auth string from API key and Secret Key
            Authorization: "Basic ***YOUR_BASE64_TOKEN***"
        regex_uri:
          - "^/live/(.*)"
          - "/$1"


# routes.yaml

routes:
  - uris:
     - /demo/md/*/accounts
     - /demo/md/*/symbols/*
     - /demo/md/*/summary/*
     - /demo/md/*/ohlc/*
     - /demo/md/*/transactions
     - /demo/trade/*/orders/*
    upstream_id: 1
    plugin_config_id: 1
  - uris:
     - /live/md/*/accounts
     - /live/md/*/symbols/*
     - /live/md/*/summary/*
     - /live/md/*/ohlc/*
     - /live/md/*/transactions
     - /live/trade/*/orders/*
    upstream_id: 2
    plugin_config_id: 2
#END

How To Test

Make a CURL request to APISIX proxy

curl -u foo:bar 0.0.0.0:9080/demo/md/3.0/accounts

or open <span class="editor-theme-code">0.0.0.0.9080/demo/md/3.0/accounts</span> in browser and pass Basic Auth Credentials

Get help

  • APISIX Documentation [https://apisix.apache.org/docs/apisix/getting-started/README/]
  • Exante Documentation [https://api-live.exante.eu/api-docs/]
  • Finmars IT Help: s.zhitenev@finmars.com