A library for working with alpaca.markets APIs, including the Broker API.

Overview

alpaca-rs, an unofficial Rust SDK for the Alpaca API (WIP)

Features

  • Easy to use - Minimal setup and no boilerplate.
  • Cross-platform - can run on most platforms that Rust can run on, including WebAssembly.
  • Interoperable - does not depend on any async runtime, so you can use whatever executor you want, like Tokio, actix-rt, or async-std's own executor.
  • Supports all Alpaca APIs - Broker, Trading and Market Data APIs.

Guide

Installing

Crates.io (not released yet)

Use this command:

cargo add alpaca-rs

Or add this to Cargo.toml:

[dependencies]
alpaca-rs = "<latest crates.io version>"

Latest commit (git)

Use this command:

cargo add alpaca-rs --git https://github.com/PassivityTrading/alpaca-rs

Or add this to Cargo.toml:

[dependencies]
# ... other dependencies ...
alpaca-rs.git = "https://github.com/PassivityTrading/alpaca-rs"

Beware that if you use the git version, it may break, it may not even compile, etc. We do not recommend you use this, but if you want the latest changes or there is no suitable crates.io version, this would work.

Usage

Broker API

Create a client:

use alpaca_rs::prelude::*;

let auth: BrokerAuth = BrokerAuth { key: std::env::var("ALPACA_BROKER_KEY").unwrap().into() };
let client = BrokerClient::new_sandbox(auth);

Make an account:

use alpaca_rs::prelude::*;

fn get_contact() -> Contact { todo!() }
fn get_identity() -> Identity { todo!() }

async fn run() -> Result<(), AlpacaError> {
    let client = BrokerClient::new_sandbox(BrokerAuth { key: std::env::var("ALPACA_BROKER_KEY").unwrap().into() });
    let account = client.create_account(get_contact(), get_identity()).execute().await?;
    println!("Created account: {account:#?}");
    Ok(())
}
You might also like...
API wrapper for the tankerkönig api

tankerkoenig-rs API wrapper for the tankerkoenig-api written in rust. Gives you ready deserialized structs and a easy to use and strictly typed api. I

A repository full of manually generated hand curated JSON files, which contain the API Types that the Discord API returns.

Discord API Types A repository full of manually generated hand curated JSON files, which contain the API Types that the Discord API returns. Also did

Notion Offical API client library for rust

Notion API client library for rust.

An asynchronous Rust client library for the Hashicorp Vault API

vaultrs An asynchronous Rust client library for the Hashicorp Vault API The following features are currently supported: Auth AppRole JWT/OIDC Token Us

Wrapper library for utilizing DigitalOcean API v2 in Rust

doapi-rs Wrapper library for utilizing DigitalOcean API v2 in Rust Disclaimer This library is in alpha - it may do anything up to, and including, eati

Serenity is a Rust library for the Discord API
Serenity is a Rust library for the Discord API

serenity Serenity is a Rust library for the Discord API. View the examples on how to make and structure a bot. Serenity supports bot login via the use

🦀 Zulip API Library Rust Client

Zulip API Client Library Rust Crate This repo contains the code for an unofficial, third-party Zulip API client library crate written in the Rust prog

Rust lib for Scaleway API

Notes This Scaleway API Crate is created and maintained by Qovery and used in production in the Qovery Engine. This project relies on OpenAPI Generato

mdzk is a plain text Zettelkasten system that is based on the mdBook API.

mdzk A lovingly designed system and static publishing tool for your plain text Zettelkasten mdzk is a plain text Zettelkasten system that is based on

Comments
  • Market data

    Market data

    Endpoints

    Stocks

    • [x] 6494b6a Historical auctions
    • [x] 6494b6a...c1c8580 Historical/latest bars
    • [x] 5b66273 Condition/exchange codes
    • [x] Historical/latest quotes
    • [x] Snapshots
    • [x] Historical/latest trades
    enhancement 
    opened by nothendev 0
  • Sandbox market data is broken

    Sandbox market data is broken

    This is the error log with MarketDataClient::new_sandbox:

    2023-12-13T18:05:58.467792Z  INFO mean_reversion: Waiting for 20 bars...
    2023-12-13T18:05:58.467864Z TRACE alpaca_rs::api::trading: Request { method: Get, url: Url { scheme: "https", cannot_be_a_base: false, username: "", password: None, host: Some(Domain("data.sandbox.alpaca.markets")), port: None, path: "/v2/stocks/bars", query: Some("symbols=AAPL&timeframe=1T&start=2023-12-13&limit=20&adjustment=all&feed=iex"), fragment: None }, headers: {"apca-api-secret-key": "Le8yjRdfklocrv5Tuk6kiMJpKGpRIX94eFcl6zIS", "apca-api-key-id": "PKD62K9DUY7TAMLLMAT6"}, version: None, body: Body { reader: "<hidden>", length: Some(0), bytes_read: 0 }, local_addr: None, peer_addr: None, ext: Extensions, trailers_sender: Some(Sender { .. }), trailers_receiver: Some(Receiver { .. }), has_trailers: false }    
    Error: Http(status was not successful: Response { status: Forbidden, headers: {"access-control-max-age": "1728000", "content-length": "146", "connection": "keep-alive", "x-request-id": "20beb13af654911471519d1f731865fc", "access-control-allow-credentials": "true", "strict-transport-security": "max-age=15724800; includeSubDomains", "access-control-allow-methods": "GET, OPTIONS", "access-control-allow-headers": "Apca-Api-Key-Id, Apca-Api-Secret-Key, Authorization", "access-control-allow-origin": "*", "date": "Wed, 13 Dec 2023 18:05:59 GMT", "content-type": "text/html"}, version: None, has_trailers: false, trailers_sender: Some(Sender { .. }), trailers_receiver: Some(Receiver { .. }), upgrade_sender: Some(Sender { .. }), upgrade_receiver: Some(Receiver { .. }), has_upgrade: false, body: Body { reader: "<hidden>", length: Some(0), bytes_read: 0 }, ext: Extensions, local_addr: None, peer_addr: None }, <html>
    <head><title>403 Forbidden</title></head>
    <body>
    <center><h1>403 Forbidden</h1></center>
    <hr><center>nginx</center>
    </body>
    </html>
    )
    
    • [ ] Root cause? Is the library not doing something right? Unlikely, as using new_live works like a charm.
    opened by nothendev 0
  • MVP status

    MVP status

    This issue tracks the tasks that are needed to be completed for an MVP of the SDK.

    • [ ] Market Data
      • [x] #1 (Historical)
      • [ ] WebSockets API
    • [ ] Broker API
      • [x] Finish funding (bank relationships)
      • [ ] Finish the account-wise trading API
    opened by nothendev 0
Owner
null
Efficent platform for inference and serving local LLMs including an OpenAI compatible API server.

candle-vllm Efficient platform for inference and serving local LLMs including an OpenAI compatible API server. Features OpenAI compatible API server p

Eric Buehler 21 Nov 15, 2023
A multipurpose (including music) Discord bot written in Rust

filloabot-rs A multipurpose (including music) Discord bot. This is a full rewrite using Rust of the original FilloaBot. Some features that were consid

FilloaBot 2 Oct 21, 2022
Simplify temporary email management and interaction, including message retrieval and attachment downloads, using Rust.

Tempmail The Tempmail simplifies temporary email management and interaction, including message retrieval and attachment downloads, using the Rust prog

Dilshad 6 Sep 21, 2023
A rust library for interacting with multiple Discord.com-compatible APIs and Gateways at the same time.

Chorus A rust library for interacting with (multiple) Spacebar-compatible APIs and Gateways (at the same time). Explore the docs » Report Bug · Reques

polyphony 4 Apr 30, 2023
Rust bindings for the WebView2 COM APIs

webview2-rs Rust bindings for the WebView2 COM APIs Crates in this repo The root of this repo defines a virtual workspace in Cargo.toml which includes

Bill Avery 24 Dec 15, 2022
Provides two APIs for easily cancelling futures, with the option to fallback to a timeout cancellation

tokio-context Provides two different methods for cancelling futures with a provided handle for cancelling all related futures, with a fallback timeout

Peter Farr 18 Dec 27, 2022
This is a Telegram bot I'm working on in my free time to learn Rust.

Maldness Bot This is a Telegram bot I'm working on in my free time to learn Rust. Building docker build -t . should be enough.

Sergey Kislyakov 10 May 13, 2022
The working code for my Safe Pay app - check out my tutorial!

Safe Pay Tutorial This repository contains the source code for my blog post Using PDAs and SPL Token in Anchor. The code contains the following: Solan

Daniel Pyrathon 39 Aug 28, 2022
A dead-simple tool for working with data in Kafka

ktool - a tool for Kafka ktool is a dead-simple tool for working with data in Kafka: Copy partitions / topics to disk Replay messages Inspect message

Dom 5 Nov 4, 2022
Modrinth API is a simple library for using, you guessed it, the Modrinth API in Rust projects

Modrinth API is a simple library for using, you guessed it, the Modrinth API in Rust projects. It uses reqwest as its HTTP(S) client and deserialises responses to typed structs using serde.

null 21 Jan 1, 2023