/bkdocs-go

Alpaca Brokerage API. Generated from OpenAPI.

Primary LanguageShell

Go API client for openapi

Open brokerage accounts, enable commission-free trading, and manage the ongoing user experience with Alpaca Broker API

Overview

This API client was generated by the OpenAPI Generator project. By using the OpenAPI-spec from a remote server, you can easily generate an API client.

  • API version: 1.0.0
  • Package version: 1.0.0
  • Build package: org.openapitools.codegen.languages.GoClientCodegen

Installation

Install the following dependencies:

go get github.com/stretchr/testify/assert
go get golang.org/x/oauth2
go get golang.org/x/net/context

Put the package under your project folder and add the following in import:

import sw "./openapi"

To use a proxy, set the environment variable HTTP_PROXY:

os.Setenv("HTTP_PROXY", "http://proxy_name:proxy_port")

Configuration of Server URL

Default configuration comes with Servers field that contains server objects as defined in the OpenAPI specification.

Select Server Configuration

For using other server than the one defined on index 0 set context value sw.ContextServerIndex of type int.

ctx := context.WithValue(context.Background(), sw.ContextServerIndex, 1)

Templated Server URL

Templated server URL is formatted using default variables from configuration or from context value sw.ContextServerVariables of type map[string]string.

ctx := context.WithValue(context.Background(), sw.ContextServerVariables, map[string]string{
	"basePath": "v2",
})

Note, enum values are always validated and all unused variables are silently ignored.

URLs Configuration per Operation

Each operation can use different server URL defined using OperationServers map in the Configuration. An operation is uniquely identifield by "{classname}Service.{nickname}" string. Similar rules for overriding default operation server index and variables applies by using sw.ContextOperationServerIndices and sw.ContextOperationServerVariables context maps.

ctx := context.WithValue(context.Background(), sw.ContextOperationServerIndices, map[string]int{
	"{classname}Service.{nickname}": 2,
})
ctx = context.WithValue(context.Background(), sw.ContextOperationServerVariables, map[string]map[string]string{
	"{classname}Service.{nickname}": {
		"port": "8443",
	},
})

Documentation for API Endpoints

All URIs are relative to https://broker-api.sandbox.alpaca.markets/v1

Class Method HTTP request Description
AccountsApi AccountsAccountIdDocumentsUploadPost Post /accounts/{account_id}/documents/upload Upload a document to an already existing account
AccountsApi AccountsActivitiesActivityTypeGet Get /accounts/activities/{activity_type} Retrieve specific account activities
AccountsApi AccountsActivitiesGet Get /accounts/activities Retrieve account activities
AccountsApi AccountsGet Get /accounts Retrieve all accounts
AccountsApi AccountsPost Post /accounts Create an account
AccountsApi DeleteAccount Delete /accounts/{account_id} Request to close an account
AccountsApi DeleteAchRelationship Delete /accounts/{account_id}/ach_relationships/{ach_relationship_id} Delete an existing ACH relationship
AccountsApi DeleteRecipientBank Delete /accounts/{account_id}/recipient_banks/{bank_id} Delete a Bank Relationship for an account
AccountsApi DeleteTransfer Delete /accounts/{account_id}/transfers/{transfer_id} Request to close a transfer
AccountsApi EventsAccountsStatusGet Get /events/accounts/status Subscribe to account status events (SSE).
AccountsApi GetAccount Get /accounts/{account_id} Retrieve an account.
AccountsApi GetAchRelationships Get /accounts/{account_id}/ach_relationships Retrieve ACH Relationships for an account
AccountsApi GetRecipientBanks Get /accounts/{account_id}/recipient_banks Retrieve bank relationships for an account
AccountsApi GetTradingAccount Get /trading/accounts/{account_id}/account Retrieve trading details for an account.
AccountsApi GetTransfers Get /accounts/{account_id}/transfers Return a list of transfers for an account.
AccountsApi PatchAccount Patch /accounts/{account_id} Update an account
AccountsApi PostAchRelationships Post /accounts/{account_id}/ach_relationships Create an ACH Relationship
AccountsApi PostRecipientBanks Post /accounts/{account_id}/recipient_banks Create a Bank Relationship for an account
AccountsApi PostTransfers Post /accounts/{account_id}/transfers Request a new transfer
AssetsApi AssetsAssetIdGet Get /assets/{asset_id} Retrieve an asset by UUID
AssetsApi AssetsSymbolGet Get /assets/{symbol} Retrieve an asset by symbol
AssetsApi GetAssets Get /assets Retrieve all assets
CalendarApi CalendarGet Get /calendar Query market calendar
ClockApi ClockGet Get /clock Query market clock
DocumentsApi AccountsAccountIdDocumentsDocumentIdDownloadGet Get /accounts/{account_id}/documents/{document_id}/download Download a document file that belongs to an account.
DocumentsApi AccountsAccountIdDocumentsGet Get /accounts/{account_id}/documents Return a list of account documents.
DocumentsApi DocumentsDocumentIdGet Get /documents/{document_id} Download a document file directly
EventsApi EventsAccountsStatusGet Get /events/accounts/status Subscribe to account status events (SSE).
EventsApi EventsJournalsStatusGet Get /events/journals/status Subscribe to journal events (SSE).
FundingApi DeleteAchRelationship Delete /accounts/{account_id}/ach_relationships/{ach_relationship_id} Delete an existing ACH relationship
FundingApi DeleteRecipientBank Delete /accounts/{account_id}/recipient_banks/{bank_id} Delete a Bank Relationship for an account
FundingApi DeleteTransfer Delete /accounts/{account_id}/transfers/{transfer_id} Request to close a transfer
FundingApi GetAchRelationships Get /accounts/{account_id}/ach_relationships Retrieve ACH Relationships for an account
FundingApi GetRecipientBanks Get /accounts/{account_id}/recipient_banks Retrieve bank relationships for an account
FundingApi GetTransfers Get /accounts/{account_id}/transfers Return a list of transfers for an account.
FundingApi PostAchRelationships Post /accounts/{account_id}/ach_relationships Create an ACH Relationship
FundingApi PostRecipientBanks Post /accounts/{account_id}/recipient_banks Create a Bank Relationship for an account
FundingApi PostTransfers Post /accounts/{account_id}/transfers Request a new transfer
JournalsApi DeleteJournal Delete /journals/{journal_id} Cancel a pending journal.
JournalsApi EventsJournalsStatusGet Get /events/journals/status Subscribe to journal events (SSE).
JournalsApi GetJournals Get /journals Return a list of requested journals.
JournalsApi PostJournals Post /journals Request a journal.
JournalsApi PostJournalsBatch Post /journals/batch Create a batch journal
OAuthApi OauthAuthorizePost Post /oauth/authorize Issue a code.
OAuthApi OauthClientsClientIdGet Get /oauth/clients/{client_id} Returns an OAuth client.
OAuthApi OauthTokenPost Post /oauth/token Issue a token.
TradingApi DeleteOrder Delete /trading/accounts/{account_id}/orders/{order_id} Attempts to cancel an open order.
TradingApi DeleteOrders Delete /trading/accounts/{account_id}/orders Attempts to cancel all open orders. A response will be provided for each order that is attempted to be cancelled.
TradingApi GetOrder Get /trading/accounts/{account_id}/orders/{order_id} Retrieves a single order for the given order_id.
TradingApi GetOrders Get /trading/accounts/{account_id}/orders Retrieves a list of orders for the account, filtered by the supplied query parameters.
TradingApi GetPositions Get /trading/accounts/{account_id}/positions List open positions for an account
TradingApi PatchOrder Patch /trading/accounts/{account_id}/orders/{order_id} Replaces a single order with updated parameters. Each parameter overrides the corresponding attribute of the existing order.
TradingApi PostOrders Post /trading/accounts/{account_id}/orders Create an order for an account.

Documentation For Models

Documentation For Authorization

BasicAuth

  • Type: HTTP basic authentication

Example

auth := context.WithValue(context.Background(), sw.ContextBasicAuth, sw.BasicAuth{
    UserName: "username",
    Password: "password",
})
r, err := client.Service.Operation(auth, args)

Documentation for Utility Methods

Due to the fact that model structure members are all pointers, this package contains a number of utility functions to easily obtain pointers to values of basic types. Each of these functions takes a value of the given basic type and returns a pointer to it:

  • PtrBool
  • PtrInt
  • PtrInt32
  • PtrInt64
  • PtrFloat
  • PtrFloat32
  • PtrFloat64
  • PtrString
  • PtrTime

Author