Skip to content

withbelay/alpaca-proxy

Repository files navigation

AlpacaProxy

Coverage Status

The Alpaca Proxy serves as a proxy between Belay and an alpaca account. If you plan to utilize Belay to offer insurance to your investors, and you utilize Alpaca as your brokerage provider, this proxy serves as a intermediatory between your Alpaca brokerage service and Belay. This proxy allows you to control what permissions we have to your Alpaca brokerage service and hide your private keys while still giving Belay a way to communicate to Alpaca.

Usage

This application intends to be hosted on a hosting platform of your choice. For your convenience, we provide a docker package to allow for easy deployment

ENVs required

There are some ENVs that will be required across any method of running AlpacaProxy, these include:

  • BELAY_SECRET: This is a secret generated by the hoster and then shared with Belay to allow us access
  • ALPACA_BASE_URL: The Alpaca base url, for sandbox it will be: https://broker-api.sandbox.alpaca.markets/, for production, it will be: https://broker-api.alpaca.markets/
  • ALPACA_KEY: The Alpaca key retrieved from the Alpaca dashboard
  • ALPACA_SECRET: The Alpaca secret retrieved from the Alpaca dashboard
  • SECRET_KEY_BASE: Required by Elixir Phoenix, set to any secure passphrase, for example, the output of openssl rand -hex 64

Via Docker

When running via Docker, make sure your container is listening on port 4000. The latest docker image will be available in Github packages, see there for the latest version. From there you can pull down the latest version via the following command:

For a specific version, use:
docker pull ghcr.io/withbelay/alpaca-proxy:<<VERSION>>

For the latest in main:
docker pull ghcr.io/withbelay/alpaca-proxy:main

We recommend to always specify a specific version, check the packages section for the current versions available

Running locally

Make sure you have Elixir 1.15 installed

To start the Alpaca Proxy:

  • Run mix deps.get to install and setup dependencies
  • Start Phoenix endpoint with mix phx.server or inside IEx with iex -S mix phx.server

Utilizing

Now you can make Alpaca requests against localhost:4000 with the specified Belay key and secret. The Alpaca Proxy utilizes the same Auth behavior as Alpaca, but uses belay as the Basic Auth key and whatever BELAY_SECRET was set to as the Basic Auth secret

Questions

If there are any further questions, reach out to [email protected]