@investingwolf/alpaca-broker-api
Version:
Node.js client for alpaca broker API
318 lines (317 loc) • 14.9 kB
JavaScript
;
/**
* Alpaca Broker API
* Open brokerage accounts, enable commission-free trading, and manage the ongoing user experience with Alpaca Broker API
*
* The version of the OpenAPI document: 1.0.0
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.OAuthApi = exports.OAuthApiApiKeys = void 0;
const request_1 = __importDefault(require("request"));
const models_1 = require("../model/models");
const models_2 = require("../model/models");
const apis_1 = require("./apis");
let defaultBasePath = 'https://broker-api.sandbox.alpaca.markets/v1';
// ===============================================
// This file is autogenerated - Please do not edit
// ===============================================
var OAuthApiApiKeys;
(function (OAuthApiApiKeys) {
})(OAuthApiApiKeys = exports.OAuthApiApiKeys || (exports.OAuthApiApiKeys = {}));
class OAuthApi {
constructor(basePathOrUsername, password, basePath) {
this._basePath = defaultBasePath;
this._defaultHeaders = {};
this._useQuerystring = false;
this.authentications = {
'default': new models_1.VoidAuth(),
'BasicAuth': new models_2.HttpBasicAuth(),
};
this.interceptors = [];
if (password) {
this.username = basePathOrUsername;
this.password = password;
if (basePath) {
this.basePath = basePath;
}
}
else {
if (basePathOrUsername) {
this.basePath = basePathOrUsername;
}
}
}
set useQuerystring(value) {
this._useQuerystring = value;
}
set basePath(basePath) {
this._basePath = basePath;
}
set defaultHeaders(defaultHeaders) {
this._defaultHeaders = defaultHeaders;
}
get defaultHeaders() {
return this._defaultHeaders;
}
get basePath() {
return this._basePath;
}
setDefaultAuthentication(auth) {
this.authentications.default = auth;
}
setApiKey(key, value) {
this.authentications[OAuthApiApiKeys[key]].apiKey = value;
}
set username(username) {
this.authentications.BasicAuth.username = username;
}
set password(password) {
this.authentications.BasicAuth.password = password;
}
addInterceptor(interceptor) {
this.interceptors.push(interceptor);
}
/**
* The operation issues an OAuth code which can be used in the OAuth code flow.
* @summary Issue a code.
* @param inlineObject1
*/
oauthAuthorizePost(inlineObject1, options = { headers: {} }) {
return __awaiter(this, void 0, void 0, function* () {
const localVarPath = this.basePath + '/oauth/authorize';
let localVarQueryParameters = {};
let localVarHeaderParams = Object.assign({}, this._defaultHeaders);
const produces = ['application/json'];
// give precedence to 'application/json'
if (produces.indexOf('application/json') >= 0) {
localVarHeaderParams.Accept = 'application/json';
}
else {
localVarHeaderParams.Accept = produces.join(',');
}
let localVarFormParams = {};
// verify required parameter 'inlineObject1' is not null or undefined
if (inlineObject1 === null || inlineObject1 === undefined) {
throw new Error('Required parameter inlineObject1 was null or undefined when calling oauthAuthorizePost.');
}
Object.assign(localVarHeaderParams, options.headers);
let localVarUseFormData = false;
let localVarRequestOptions = {
method: 'POST',
qs: localVarQueryParameters,
headers: localVarHeaderParams,
uri: localVarPath,
useQuerystring: this._useQuerystring,
json: true,
body: models_1.ObjectSerializer.serialize(inlineObject1, "InlineObject1")
};
let authenticationPromise = Promise.resolve();
if (this.authentications.BasicAuth.username && this.authentications.BasicAuth.password) {
authenticationPromise = authenticationPromise.then(() => this.authentications.BasicAuth.applyToRequest(localVarRequestOptions));
}
authenticationPromise = authenticationPromise.then(() => this.authentications.default.applyToRequest(localVarRequestOptions));
let interceptorPromise = authenticationPromise;
for (const interceptor of this.interceptors) {
interceptorPromise = interceptorPromise.then(() => interceptor(localVarRequestOptions));
}
return interceptorPromise.then(() => {
if (Object.keys(localVarFormParams).length) {
if (localVarUseFormData) {
localVarRequestOptions.formData = localVarFormParams;
}
else {
localVarRequestOptions.form = localVarFormParams;
}
}
return new Promise((resolve, reject) => {
request_1.default(localVarRequestOptions, (error, response, body) => {
if (error) {
reject(error);
}
else {
body = models_1.ObjectSerializer.deserialize(body, "InlineResponse2008");
if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) {
resolve({ response: response, body: body });
}
else {
reject(new apis_1.HttpError(response, body, response.statusCode));
}
}
});
});
});
});
}
/**
* The endpoint returns the details of OAuth client to display in the authorization page.
* @summary Returns an OAuth client.
* @param clientId
* @param responseType
* @param redirectUri
* @param scope
*/
oauthClientsClientIdGet(clientId, responseType, redirectUri, scope, options = { headers: {} }) {
return __awaiter(this, void 0, void 0, function* () {
const localVarPath = this.basePath + '/oauth/clients/{client_id}'
.replace('{' + 'client_id' + '}', encodeURIComponent(String(clientId)));
let localVarQueryParameters = {};
let localVarHeaderParams = Object.assign({}, this._defaultHeaders);
const produces = ['application/json'];
// give precedence to 'application/json'
if (produces.indexOf('application/json') >= 0) {
localVarHeaderParams.Accept = 'application/json';
}
else {
localVarHeaderParams.Accept = produces.join(',');
}
let localVarFormParams = {};
// verify required parameter 'clientId' is not null or undefined
if (clientId === null || clientId === undefined) {
throw new Error('Required parameter clientId was null or undefined when calling oauthClientsClientIdGet.');
}
if (responseType !== undefined) {
localVarQueryParameters['response_type'] = models_1.ObjectSerializer.serialize(responseType, "'code' | 'token'");
}
if (redirectUri !== undefined) {
localVarQueryParameters['redirect_uri'] = models_1.ObjectSerializer.serialize(redirectUri, "string");
}
if (scope !== undefined) {
localVarQueryParameters['scope'] = models_1.ObjectSerializer.serialize(scope, "string");
}
Object.assign(localVarHeaderParams, options.headers);
let localVarUseFormData = false;
let localVarRequestOptions = {
method: 'GET',
qs: localVarQueryParameters,
headers: localVarHeaderParams,
uri: localVarPath,
useQuerystring: this._useQuerystring,
json: true,
};
let authenticationPromise = Promise.resolve();
if (this.authentications.BasicAuth.username && this.authentications.BasicAuth.password) {
authenticationPromise = authenticationPromise.then(() => this.authentications.BasicAuth.applyToRequest(localVarRequestOptions));
}
authenticationPromise = authenticationPromise.then(() => this.authentications.default.applyToRequest(localVarRequestOptions));
let interceptorPromise = authenticationPromise;
for (const interceptor of this.interceptors) {
interceptorPromise = interceptorPromise.then(() => interceptor(localVarRequestOptions));
}
return interceptorPromise.then(() => {
if (Object.keys(localVarFormParams).length) {
if (localVarUseFormData) {
localVarRequestOptions.formData = localVarFormParams;
}
else {
localVarRequestOptions.form = localVarFormParams;
}
}
return new Promise((resolve, reject) => {
request_1.default(localVarRequestOptions, (error, response, body) => {
if (error) {
reject(error);
}
else {
body = models_1.ObjectSerializer.deserialize(body, "InlineResponse2006");
if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) {
resolve({ response: response, body: body });
}
else {
reject(new apis_1.HttpError(response, body, response.statusCode));
}
}
});
});
});
});
}
/**
* This operation issues an access token for an account.
* @summary Issue a token.
* @param inlineObject
*/
oauthTokenPost(inlineObject, options = { headers: {} }) {
return __awaiter(this, void 0, void 0, function* () {
const localVarPath = this.basePath + '/oauth/token';
let localVarQueryParameters = {};
let localVarHeaderParams = Object.assign({}, this._defaultHeaders);
const produces = ['application/json'];
// give precedence to 'application/json'
if (produces.indexOf('application/json') >= 0) {
localVarHeaderParams.Accept = 'application/json';
}
else {
localVarHeaderParams.Accept = produces.join(',');
}
let localVarFormParams = {};
// verify required parameter 'inlineObject' is not null or undefined
if (inlineObject === null || inlineObject === undefined) {
throw new Error('Required parameter inlineObject was null or undefined when calling oauthTokenPost.');
}
Object.assign(localVarHeaderParams, options.headers);
let localVarUseFormData = false;
let localVarRequestOptions = {
method: 'POST',
qs: localVarQueryParameters,
headers: localVarHeaderParams,
uri: localVarPath,
useQuerystring: this._useQuerystring,
json: true,
body: models_1.ObjectSerializer.serialize(inlineObject, "InlineObject")
};
let authenticationPromise = Promise.resolve();
if (this.authentications.BasicAuth.username && this.authentications.BasicAuth.password) {
authenticationPromise = authenticationPromise.then(() => this.authentications.BasicAuth.applyToRequest(localVarRequestOptions));
}
authenticationPromise = authenticationPromise.then(() => this.authentications.default.applyToRequest(localVarRequestOptions));
let interceptorPromise = authenticationPromise;
for (const interceptor of this.interceptors) {
interceptorPromise = interceptorPromise.then(() => interceptor(localVarRequestOptions));
}
return interceptorPromise.then(() => {
if (Object.keys(localVarFormParams).length) {
if (localVarUseFormData) {
localVarRequestOptions.formData = localVarFormParams;
}
else {
localVarRequestOptions.form = localVarFormParams;
}
}
return new Promise((resolve, reject) => {
request_1.default(localVarRequestOptions, (error, response, body) => {
if (error) {
reject(error);
}
else {
body = models_1.ObjectSerializer.deserialize(body, "InlineResponse2007");
if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) {
resolve({ response: response, body: body });
}
else {
reject(new apis_1.HttpError(response, body, response.statusCode));
}
}
});
});
});
});
}
}
exports.OAuthApi = OAuthApi;