Backend for Ribbit, Broker API Reference App

Overview

Ribbit Reference Implementation (Backend)

The reference implementation for the backend of a broker-dealer trading application with the Alpaca Broker API. The backend is implemented using Go.

To read more about what Ribbit is, it’s use cases, how it works with Broker API, and more check out our Ribbit documentation.

You can also access the Ribbit Reference Implementation (Android) and Ribbit Reference Implementation (iOS) for a reference implementation of Ribbit’s user interface for both iOS and Android.

Caveat

This code is provided as open source for the purpose of demonstration of the Broker API usage. It is not designed for the production use and Alpaca does not offer official support of the code available in this repository.

Development Setup

Ribbit uses golang gin as webserver, and go-pg library for connecting with a PostgreSQL database.

High-level Architecture

ribbit

Third Party Dependencies

The application uses the following third party apps in order to enable functionality reuse:

  1. Twilio Verify(Used for email/mobile verification)
    • Twilio Verify API (https://www.twilio.com/docs/verify/api)
    • The Application requires the Twilio Account SID under the TWILIO_ACCOUNT variable in env.sample
    • The Application requires the Twilio Account Auth Token under the TWILIO_TOKEN variable in env.sample
  2. Plaid (Used for quickly transferring funds from your bank to Alpaca)
    • Plaid feature is only currently supported for US customers. Integration with UK and EU customers is coming soon
    • Plaid is used for ACH transfers to Alpaca. Check Alpaca's funding documentation for more info. Alpaca's ACH API might be helpful as well
    • Environment variables (in env.sample):
      • PLAID_CLIENT_ID: Plaid API account ID
      • PLAID_SECRET: Plaid authentication token
      • PLAID_ENV: [sandbox|development|production]
      • PLAID_PRODUCTS: currently, the app only needs auth to authenticate ACH transfers
  3. Magic Labs (Used for seemless sign up and login using a single link)
    • Environment variables (in env.sample):
      • MAGIC_API_KEY: API key provided by Magic labs
      • MAGIC_API_SECRET: Secret token provided by Magic labs
  4. SendGrid (Used for the traditional sign up flow)
    • Environment variables (in env.sample):
      • SENDGRID_API_KEY: API key provided by SendGrid

Get started


Generating private keys

A simple and efficient way of generating private keys is through mkcert. To install it, go over to their repo.

After successfully installing it in your machine, run mkcert -install

# allow read write execute for current user
chmod 700 ./generate-ssl.sh

Initializing and starting the application


Run it with docker compose

docker compose up

Run it locally

Note: Change POSTGRES_HOST to localhost when running on local machine and not docker. The same goes for POSTGRES_SUPERUSER_PASSWORD, set it to empty.

# postgresql config
cp .env.sample .env
source .env

# get dependencies and run
go get -v ./...
go run ./entry/ generate_secret
# copy the cli output of the command above and replace {JWT_SECRET} with it
export JWT_SECRET={JWT_SECRET}

# create a new database based on config values in .env
go run ./entry create_db

# create our database schema
go run ./entry create_schema

# create our superadmin user, which is used to administer our API server
go run ./entry create_superadmin

# schema migration and subcommands are available in the migrate subcommand
# go run ./entry migrate [command]

# run the application
go run ./entry/main.go

Tests and coverage

Run all tests

go test -coverprofile c.out ./...
go tool cover -html=c.out

# or simply
./test.sh

Run only integration tests

go test -v -run Integration ./...

./test.sh -i

Run only unit tests

go test -v -short ./...

# without coverage
./test.sh -s
# with coverage
./test.sh -s -c

Schema migration and cli management commands

# create a new database based on config values in .env
go run ./entry create_db

# create our database schema
go run ./entry create_schema

# create our superadmin user, which is used to administer our API server
go run ./entry create_superadmin

# schema migration and subcommands are available in the migrate subcommand
# go run ./entry migrate [command]
You might also like...
This is a simple chat app which shows how to use Go with Hotwire.
This is a simple chat app which shows how to use Go with Hotwire.

chat-hotwire-go This is a simple chat app which shows how to use Go with Hotwire. Messages from another user are received via Turbo Streams over a web

PTT APP 的後端

PTT APP 後端 這個專案主要的開發語言是 Golang 以及中文。 原有的 PTT 程式碼是透過C語言進行開發的, 然而C語言開發的程式碼雖然效能高,但是可維護性稍低,以致於後續接手維護不易。

Corona App for Ubuntu Touch

Corona App Digitaler Impfausweis Luca - check in Corona Warn App

Coding assessment to create Todo app given by Percipia

Coding assessment to create Todo app given by Percipia

It is a basic todo app which has CRUD operation using Buffalo and golang

It is a basic todo app which has CRUD operation using Buffalo and golang

Dolphinsay app written in Go.

DolphinSay About Welcome in DolphinSay! DolphinSay is inspired by Cowsay program. DolphinSay allow you to display a message said by a cute random Dolp

Minimal example app of hexagonal architecture in go

Hexagonal Architecture Minimal example of hexagonal architecture (ports & adapters) in go. Resources T

Example app using labstack/echo and ozzo-validator.

Example app using labstack/echo and ozzo-validator.

Package buildinfo provides basic building blocks and instructions to easily add build and release information to your app.
Package buildinfo provides basic building blocks and instructions to easily add build and release information to your app.

Package buildinfo provides basic building blocks and instructions to easily add build and release information to your app. This is done by replacing variables in main during build with ldflags.

Comments
  • Bump github.com/gin-gonic/gin from 1.6.3 to 1.7.0

    Bump github.com/gin-gonic/gin from 1.6.3 to 1.7.0

    Bumps github.com/gin-gonic/gin from 1.6.3 to 1.7.0.

    Release notes

    Sourced from github.com/gin-gonic/gin's releases.

    Release v1.7.0

    BUGFIXES

    • fix compile error from #2572 (#2600)
    • fix: print headers without Authorization header on broken pipe (#2528)
    • fix(tree): reassign fullpath when register new node (#2366)

    ENHANCEMENTS

    • Support params and exact routes without creating conflicts (#2663)
    • chore: improve render string performance (#2365)
    • Sync route tree to httprouter latest code (#2368)
    • chore: rename getQueryCache/getFormCache to initQueryCache/initFormCa (#2375)
    • chore(performance): improve countParams (#2378)
    • Remove some functions that have the same effect as the bytes package (#2387)
    • update:SetMode function (#2321)
    • remove a unused type SecureJSONPrefix (#2391)
    • Add a redirect sample for POST method (#2389)
    • Add CustomRecovery builtin middleware (#2322)
    • binding: avoid 2038 problem on 32-bit architectures (#2450)
    • Prevent panic in Context.GetQuery() when there is no Request (#2412)
    • Add GetUint and GetUint64 method on gin.context (#2487)
    • update content-disposition header to MIME-style (#2512)
    • reduce allocs and improve the render WriteString (#2508)
    • implement ".Unwrap() error" on Error type (#2525) (#2526)
    • Allow bind with a map[string]string (#2484)
    • chore: update tree (#2371)
    • Support binding for slice/array obj [Rewrite] (#2302)
    • basic auth: fix timing oracle (#2609)
    • Add mixed param and non-param paths (port of httprouter#329) (#2663)
    • feat(engine): add trustedproxies and remoteIP (#2632)
    Changelog

    Sourced from github.com/gin-gonic/gin's changelog.

    Gin v1.7.0

    BUGFIXES

    • fix compile error from #2572 (#2600)
    • fix: print headers without Authorization header on broken pipe (#2528)
    • fix(tree): reassign fullpath when register new node (#2366)

    ENHANCEMENTS

    • Support params and exact routes without creating conflicts (#2663)
    • chore: improve render string performance (#2365)
    • Sync route tree to httprouter latest code (#2368)
    • chore: rename getQueryCache/getFormCache to initQueryCache/initFormCa (#2375)
    • chore(performance): improve countParams (#2378)
    • Remove some functions that have the same effect as the bytes package (#2387)
    • update:SetMode function (#2321)
    • remove a unused type SecureJSONPrefix (#2391)
    • Add a redirect sample for POST method (#2389)
    • Add CustomRecovery builtin middleware (#2322)
    • binding: avoid 2038 problem on 32-bit architectures (#2450)
    • Prevent panic in Context.GetQuery() when there is no Request (#2412)
    • Add GetUint and GetUint64 method on gin.context (#2487)
    • update content-disposition header to MIME-style (#2512)
    • reduce allocs and improve the render WriteString (#2508)
    • implement ".Unwrap() error" on Error type (#2525) (#2526)
    • Allow bind with a map[string]string (#2484)
    • chore: update tree (#2371)
    • Support binding for slice/array obj [Rewrite] (#2302)
    • basic auth: fix timing oracle (#2609)
    • Add mixed param and non-param paths (port of httprouter#329) (#2663)
    • feat(engine): add trustedproxies and remoteIP (#2632)
    Commits

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies 
    opened by dependabot[bot] 1
  • Error starting ribbit-backend_ribbit_1, following readme instructions

    Error starting ribbit-backend_ribbit_1, following readme instructions

    Hi, I tried to follow along with the readme, but running into 2 problems:

    1. A warning on the plaid environment selection - .env is set to export PLAID_ENV=sandbox, but this doesn't seem to be working. The same error occurs with and without double quotes, as well as for the other options.
    2. An email address seems to be needed, but it isn't clear which config file this should be added to.

    Thanks for your help!

    ` WARNING: Invalid environment specified: , please use one of: plaid.Sandbox, plaid.Development or plaid.Production

    create_db called

    Database user test_user already exists

    Database named test_db already exists

    WARNING: Invalid environment specified: , please use one of: plaid.Sandbox, plaid.Development or plaid.Production

    createschema called

    Created model Asset as table assets

    Created model BankAccount as table bankaccounts

    Created model CoinStatement as table coinstatements

    Created model Reward as table rewards

    Created model Role as table roles

    Created model User as table users

    Created model UserReward as table userrewards

    Created model Verification as table verifications

    WARNING: Invalid environment specified: , please use one of: plaid.Sandbox, plaid.Development or plaid.Production

    required flag(s) "email" not set sdjsbhfjbhsfb

    Error: required flag(s) "email" not set

    Usage:

    alpaca create_superadmin [flags]

    Flags:

    -e, --email string SuperAdmin user's email

    -h, --help help for create_superadmin

    -p, --password string SuperAdmin user's password

    Global Flags:

      --config string   config file (default is $HOME/.alpaca.yaml)
    

    exit status 1 `

    opened by mike-greenmmd 0
Owner
Alpaca
Alpaca builds an API for free stock trading
Alpaca
A challenge in Go. A simple backend responding to API calls reading/writing data from to PostgreSQL db.

Go Challenge The challenge has been executed in two different steps. Steps 1 Hour tag: 1 hour: As the challenge required, the tag is a snapshot of wha

Sergio Maria Matone 0 Dec 4, 2021
A dead simple Go wrapper around the hidden moonarch.app API.

moonarch A dead simple Go wrapper around the hidden moonarch.app API. How-To First, get the repository: go get github.com/lazdotdigital/moonarch. moon

Laz 0 Nov 27, 2021
🚀 Backend for Online Courses Builder | SaaS Product

Backend app for Online Course Constructor Platform Build & Run (Locally) Prerequisites go 1.15 docker golangci-lint (optional, used to run code checks

Maksim Zhashkevych 124 Jan 3, 2023
A go backend you can use as a template

Golang project template form Golang Sri Lanka

Golang Sri Lanka 7 May 18, 2022
JumpCloud backend interview assignment

jc-assignment JumpCloud backend interview assignment Hello and thanks for speaking with me earlier this week. As may be apparent from the code, I'm ne

null 0 Nov 5, 2021
Monegi Backend With Fiber And Gorm

Fiber + Gorm Setting environment variables Creating .env file to compose environment variables. .env DB_HOST= <host of db> DB_NAME= <name of db> DB_US

null 0 Nov 17, 2021
Epub generator backend for mdBook

gomdbook2epub An EPUB generator backend for mdBook. Getting Started Install bina

神楽坂帕琪 0 Dec 17, 2021
Golang-echo-sample - Make an out-of-the-box backend based on golang-echo

Golang-echo-sample - Make an out-of-the-box backend based on golang-echo

Haitwang 0 Dec 31, 2021
Radiant is used for rapid development of enterprise application in Go, including RESTful APIs, web apps and backend services.

Radiant is used for rapid development of enterprise application in Go, including RESTful APIs, web apps and backend services.

W3 Engineers Ltd. 3 Mar 22, 2022
Seen tech VAI22 backend MehediHassan

Seen-tech-VAI22-backend-MehediHassan Getting started To make it easy for you to get started with GitLab, here's a list of recommended next steps. Alre

Mehedi Hasan Ridoy 0 Feb 9, 2022