Using the Alpaca API with Ruby

Hoss@Hossapp /

Using the Alpaca API with Ruby

In this tutorial, we’ll demonstrate how to use the Alpaca API with Ruby. We’ll cover installation, making a few calls, and getting started with Hoss.

Installing and Importing Libraries

Before you start using the API, it is necessary to install a few ruby gems through the gem package manager - so run ‘gem install alpaca-trade-api’ in your terminal. To sign up for Hoss - which provides you with insights into API performance - go ahead and do so here. In order to install Hoss, run ‘gem install hoss’ in your terminal.

For our purposes, we will be using Bundler. To ensure that the Hoss Agent and the Stripe package are available, drop the following lines into your gemfile. Then, run ‘bundle install’

source ''
gem 'alpaca-trade-api'
gem 'hoss-agent'

Make sure to insert these lines at the top of your code (not in the gemfile).

require 'alpaca-trade-api'
require 'hoss-agent'

Integrate the Hoss SDK

Here, we integrated the Hoss SDK. It's as simple as writing these two lines!

You can find your Hoss keys in your settings here. There are three keys for development, production, and staging respectively. We are using our development key here.

hoss_key ='development-##################################'

Getting Started With Alpaca

Head over to your Alpaca account and obtain your API public and private keys. You’ll have to create a developer account here, if you haven’t already done so. Obviously, we won’t be trading real money in this tutorial, so we will be working in the paper trading mode.

Alpaca::Trade::Api.configure do |config|
  config.endpoint = ''
  config.key_id = 'xxxxxxxx'
  config.key_secret = 'xxxxx'

Getting Account Information

Now, we will view account information.

Alpaca::Trade::Api.configure do |config|
  config.endpoint = ''
  config.key_id = 'xxxxxxxx'
  config.key_secret = 'xxxxx'

client =
puts client.orders.last.inspect

The response is as follows.

  "activity_type": "ACTIVITY_TYPE",
  "cum_qty": "CUM_QTY",
  "id": "ID",
  "leaves_qty": "LEAVES_QTY",
  "price": "PRICE",
  "qty": "QTY",
  "side": "OPERATION",
  "symbol": "SYMBOL",
  "transaction_time": "TIME",
  "order_id": "ORDER_ID",
  "type": "FILL"

View your Request History in Hoss

On the toolbar on the left side of the panel, you can select which API you want to view and then select “Requests”. On this page, you can also view important metrics about API performance, such as latency. We can see the API requests - clicking on the individual requests allows us to examine the headers, payloads, and other relevant information about the request and response.

Set Up Alarms

Hoss empowers you to gain insight into API status, failed calls, and latency. We provide Slack and Pagerduty integrations to enable you to send notifications directly to the folks responsible for working with these API integrations.

Masking Fields

The Alpaca API may provide PII in the responses. To help ensure that you are compliant with data privacy regulations, Hoss provides the ability to mask fields. Learn more about it here.

Next Steps

That’s it! You can check out the full Alpaca API documentation here to get started.

Subscribe to Hoss ModeA weekly newsletter with curated articles, community discussions, news and trends.

Using the Quovo API with Node.js

Read more
In this tutorial, we’ll talk about how to get started with the Quovo API. We’ll cover installing important libraries and authentication, before diving into some sample requests.

Using the Alpaca API with Python

Read more
In this tutorial, we’ll show you how to get started with the Alpaca API when using Python. when We’ll go over installing libraries, integrating the Hoss SDK, and executing trades.
Back to blog

Copyright © Hoss Technologies, Inc. 2021 - All rights reserved. Terms of Service & Privacy Policy