Categorygithub.com/tbliu/bkdocs-go
repositorypackage
0.0.0-20211121071622-c0f7fab0e5d1
Repository: https://github.com/tbliu/bkdocs-go.git
Documentation: pkg.go.dev

# README

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

ClassMethodHTTP requestDescription
AccountsApiAccountsAccountIdDocumentsUploadPostPost /accounts/{account_id}/documents/uploadUpload a document to an already existing account
AccountsApiAccountsActivitiesActivityTypeGetGet /accounts/activities/{activity_type}Retrieve specific account activities
AccountsApiAccountsActivitiesGetGet /accounts/activitiesRetrieve account activities
AccountsApiAccountsGetGet /accountsRetrieve all accounts
AccountsApiAccountsPostPost /accountsCreate an account
AccountsApiDeleteAccountDelete /accounts/{account_id}Request to close an account
AccountsApiDeleteAchRelationshipDelete /accounts/{account_id}/ach_relationships/{ach_relationship_id}Delete an existing ACH relationship
AccountsApiDeleteRecipientBankDelete /accounts/{account_id}/recipient_banks/{bank_id}Delete a Bank Relationship for an account
AccountsApiDeleteTransferDelete /accounts/{account_id}/transfers/{transfer_id}Request to close a transfer
AccountsApiEventsAccountsStatusGetGet /events/accounts/statusSubscribe to account status events (SSE).
AccountsApiGetAccountGet /accounts/{account_id}Retrieve an account.
AccountsApiGetAchRelationshipsGet /accounts/{account_id}/ach_relationshipsRetrieve ACH Relationships for an account
AccountsApiGetRecipientBanksGet /accounts/{account_id}/recipient_banksRetrieve bank relationships for an account
AccountsApiGetTradingAccountGet /trading/accounts/{account_id}/accountRetrieve trading details for an account.
AccountsApiGetTransfersGet /accounts/{account_id}/transfersReturn a list of transfers for an account.
AccountsApiPatchAccountPatch /accounts/{account_id}Update an account
AccountsApiPostAchRelationshipsPost /accounts/{account_id}/ach_relationshipsCreate an ACH Relationship
AccountsApiPostRecipientBanksPost /accounts/{account_id}/recipient_banksCreate a Bank Relationship for an account
AccountsApiPostTransfersPost /accounts/{account_id}/transfersRequest a new transfer
AssetsApiAssetsAssetIdGetGet /assets/{asset_id}Retrieve an asset by UUID
AssetsApiAssetsSymbolGetGet /assets/{symbol}Retrieve an asset by symbol
AssetsApiGetAssetsGet /assetsRetrieve all assets
CalendarApiCalendarGetGet /calendarQuery market calendar
ClockApiClockGetGet /clockQuery market clock
DocumentsApiAccountsAccountIdDocumentsDocumentIdDownloadGetGet /accounts/{account_id}/documents/{document_id}/downloadDownload a document file that belongs to an account.
DocumentsApiAccountsAccountIdDocumentsGetGet /accounts/{account_id}/documentsReturn a list of account documents.
DocumentsApiDocumentsDocumentIdGetGet /documents/{document_id}Download a document file directly
EventsApiEventsAccountsStatusGetGet /events/accounts/statusSubscribe to account status events (SSE).
EventsApiEventsJournalsStatusGetGet /events/journals/statusSubscribe to journal events (SSE).
FundingApiDeleteAchRelationshipDelete /accounts/{account_id}/ach_relationships/{ach_relationship_id}Delete an existing ACH relationship
FundingApiDeleteRecipientBankDelete /accounts/{account_id}/recipient_banks/{bank_id}Delete a Bank Relationship for an account
FundingApiDeleteTransferDelete /accounts/{account_id}/transfers/{transfer_id}Request to close a transfer
FundingApiGetAchRelationshipsGet /accounts/{account_id}/ach_relationshipsRetrieve ACH Relationships for an account
FundingApiGetRecipientBanksGet /accounts/{account_id}/recipient_banksRetrieve bank relationships for an account
FundingApiGetTransfersGet /accounts/{account_id}/transfersReturn a list of transfers for an account.
FundingApiPostAchRelationshipsPost /accounts/{account_id}/ach_relationshipsCreate an ACH Relationship
FundingApiPostRecipientBanksPost /accounts/{account_id}/recipient_banksCreate a Bank Relationship for an account
FundingApiPostTransfersPost /accounts/{account_id}/transfersRequest a new transfer
JournalsApiDeleteJournalDelete /journals/{journal_id}Cancel a pending journal.
JournalsApiEventsJournalsStatusGetGet /events/journals/statusSubscribe to journal events (SSE).
JournalsApiGetJournalsGet /journalsReturn a list of requested journals.
JournalsApiPostJournalsPost /journalsRequest a journal.
JournalsApiPostJournalsBatchPost /journals/batchCreate a batch journal
OAuthApiOauthAuthorizePostPost /oauth/authorizeIssue a code.
OAuthApiOauthClientsClientIdGetGet /oauth/clients/{client_id}Returns an OAuth client.
OAuthApiOauthTokenPostPost /oauth/tokenIssue a token.
TradingApiDeleteOrderDelete /trading/accounts/{account_id}/orders/{order_id}Attempts to cancel an open order.
TradingApiDeleteOrdersDelete /trading/accounts/{account_id}/ordersAttempts to cancel all open orders. A response will be provided for each order that is attempted to be cancelled.
TradingApiGetOrderGet /trading/accounts/{account_id}/orders/{order_id}Retrieves a single order for the given order_id.
TradingApiGetOrdersGet /trading/accounts/{account_id}/ordersRetrieves a list of orders for the account, filtered by the supplied query parameters.
TradingApiGetPositionsGet /trading/accounts/{account_id}/positionsList open positions for an account
TradingApiPatchOrderPatch /trading/accounts/{account_id}/orders/{order_id}Replaces a single order with updated parameters. Each parameter overrides the corresponding attribute of the existing order.
TradingApiPostOrdersPost /trading/accounts/{account_id}/ordersCreate 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