@master-chief/alpaca
Advanced tools
Comparing version 2.0.2 to 2.1.3
@@ -1,2 +0,7 @@ | ||
export { AlpacaClient } from './lib/client.js'; | ||
export { AlpacaStream } from './lib/stream.js'; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.AlpacaStream = exports.AlpacaClient = void 0; | ||
var client_js_1 = require("./lib/client.js"); | ||
Object.defineProperty(exports, "AlpacaClient", { enumerable: true, get: function () { return client_js_1.AlpacaClient; } }); | ||
var stream_js_1 = require("./lib/stream.js"); | ||
Object.defineProperty(exports, "AlpacaStream", { enumerable: true, get: function () { return stream_js_1.AlpacaStream; } }); |
@@ -1,100 +0,143 @@ | ||
import qs from 'qs'; | ||
import fetch from 'node-fetch'; | ||
import urls from './urls.js'; | ||
import limiter from 'limiter'; | ||
import { Parser } from './parser.js'; | ||
export class AlpacaClient { | ||
"use strict"; | ||
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.AlpacaClient = void 0; | ||
const qs_1 = __importDefault(require("qs")); | ||
const node_fetch_1 = __importDefault(require("node-fetch")); | ||
const urls_js_1 = __importDefault(require("./urls.js")); | ||
const limiter_1 = __importDefault(require("limiter")); | ||
const parser_js_1 = require("./parser.js"); | ||
class AlpacaClient { | ||
constructor(options) { | ||
this.options = options; | ||
this.limiter = new limiter.RateLimiter(200, 'minute'); | ||
this.parser = new Parser(); | ||
this.limiter = new limiter_1.default.RateLimiter(200, 'minute'); | ||
this.parser = new parser_js_1.Parser(); | ||
} | ||
async isAuthenticated() { | ||
try { | ||
await this.getAccount(); | ||
return true; | ||
} | ||
catch { | ||
return false; | ||
} | ||
isAuthenticated() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
try { | ||
yield this.getAccount(); | ||
return true; | ||
} | ||
catch (_a) { | ||
return false; | ||
} | ||
}); | ||
} | ||
async getAccount() { | ||
return this.parser.parseAccount(await this.request('GET', urls.rest.account, 'account')); | ||
getAccount() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return this.parser.parseAccount(yield this.request('GET', urls_js_1.default.rest.account, 'account')); | ||
}); | ||
} | ||
async getOrder(params) { | ||
return this.parser.parseOrder(await this.request('GET', urls.rest.account, `orders/${params.order_id || params.client_order_id}?${qs.stringify({ | ||
nested: params.nested, | ||
})}`)); | ||
getOrder(params) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return this.parser.parseOrder(yield this.request('GET', urls_js_1.default.rest.account, `orders/${params.order_id || params.client_order_id}?${qs_1.default.stringify({ | ||
nested: params.nested, | ||
})}`)); | ||
}); | ||
} | ||
async getOrders(params) { | ||
return this.parser.parseOrders(await this.request('GET', urls.rest.account, `orders?${qs.stringify(params)}`)); | ||
getOrders(params) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return this.parser.parseOrders(yield this.request('GET', urls_js_1.default.rest.account, `orders?${qs_1.default.stringify(params)}`)); | ||
}); | ||
} | ||
async placeOrder(params) { | ||
return this.parser.parseOrder(await this.request('POST', urls.rest.account, `orders`, params)); | ||
placeOrder(params) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return this.parser.parseOrder(yield this.request('POST', urls_js_1.default.rest.account, `orders`, params)); | ||
}); | ||
} | ||
async replaceOrder(params) { | ||
return this.parser.parseOrder(await this.request('PATCH', urls.rest.account, `orders/${params.order_id}`, params)); | ||
replaceOrder(params) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return this.parser.parseOrder(yield this.request('PATCH', urls_js_1.default.rest.account, `orders/${params.order_id}`, params)); | ||
}); | ||
} | ||
async cancelOrder(params) { | ||
return this.parser.parseOrder(await this.request('DELETE', urls.rest.account, `orders/${params.order_id}`)); | ||
cancelOrder(params) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return this.parser.parseOrder(yield this.request('DELETE', urls_js_1.default.rest.account, `orders/${params.order_id}`)); | ||
}); | ||
} | ||
async cancelOrders() { | ||
return this.parser.parseOrders(await this.request('DELETE', urls.rest.account, `orders`)); | ||
cancelOrders() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return this.parser.parseOrders(yield this.request('DELETE', urls_js_1.default.rest.account, `orders`)); | ||
}); | ||
} | ||
async getPosition(params) { | ||
return this.parser.parsePosition(await this.request('GET', urls.rest.account, `positions/${params.symbol}`)); | ||
getPosition(params) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return this.parser.parsePosition(yield this.request('GET', urls_js_1.default.rest.account, `positions/${params.symbol}`)); | ||
}); | ||
} | ||
async getPositions() { | ||
return this.parser.parsePositions(await this.request('GET', urls.rest.account, `positions`)); | ||
getPositions() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return this.parser.parsePositions(yield this.request('GET', urls_js_1.default.rest.account, `positions`)); | ||
}); | ||
} | ||
async closePosition(params) { | ||
return this.parser.parseOrder(await this.request('DELETE', urls.rest.account, `positions/${params.symbol}`)); | ||
closePosition(params) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return this.parser.parseOrder(yield this.request('DELETE', urls_js_1.default.rest.account, `positions/${params.symbol}`)); | ||
}); | ||
} | ||
async closePositions() { | ||
return this.parser.parseOrders(await this.request('DELETE', urls.rest.account, `positions`)); | ||
closePositions() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return this.parser.parseOrders(yield this.request('DELETE', urls_js_1.default.rest.account, `positions`)); | ||
}); | ||
} | ||
getAsset(params) { | ||
return this.request('GET', urls.rest.account, `assets/${params.asset_id_or_symbol}`); | ||
return this.request('GET', urls_js_1.default.rest.account, `assets/${params.asset_id_or_symbol}`); | ||
} | ||
getAssets(params) { | ||
return this.request('GET', urls.rest.account, `assets?${qs.stringify(params)}`); | ||
return this.request('GET', urls_js_1.default.rest.account, `assets?${qs_1.default.stringify(params)}`); | ||
} | ||
getWatchlist(params) { | ||
return this.request('GET', urls.rest.account, `watchlists/${params.uuid}`); | ||
return this.request('GET', urls_js_1.default.rest.account, `watchlists/${params.uuid}`); | ||
} | ||
getWatchlists() { | ||
return this.request('GET', urls.rest.account, `watchlists`); | ||
return this.request('GET', urls_js_1.default.rest.account, `watchlists`); | ||
} | ||
createWatchlist(params) { | ||
return this.request('POST', urls.rest.account, `watchlists`, params); | ||
return this.request('POST', urls_js_1.default.rest.account, `watchlists`, params); | ||
} | ||
updateWatchlist(params) { | ||
return this.request('PUT', urls.rest.account, `watchlists/${params.uuid}`, params); | ||
return this.request('PUT', urls_js_1.default.rest.account, `watchlists/${params.uuid}`, params); | ||
} | ||
addToWatchlist(params) { | ||
return this.request('POST', urls.rest.account, `watchlists/${params.uuid}`, params); | ||
return this.request('POST', urls_js_1.default.rest.account, `watchlists/${params.uuid}`, params); | ||
} | ||
removeFromWatchlist(params) { | ||
return this.request('DELETE', urls.rest.account, `watchlists/${params.uuid}/${params.symbol}`); | ||
return this.request('DELETE', urls_js_1.default.rest.account, `watchlists/${params.uuid}/${params.symbol}`); | ||
} | ||
deleteWatchlist(params) { | ||
return this.request('DELETE', urls.rest.account, `watchlists/${params.uuid}`); | ||
return this.request('DELETE', urls_js_1.default.rest.account, `watchlists/${params.uuid}`); | ||
} | ||
getCalendar(params) { | ||
return this.request('GET', urls.rest.account, `calendar?${qs.stringify(params)}`); | ||
return this.request('GET', urls_js_1.default.rest.account, `calendar?${qs_1.default.stringify(params)}`); | ||
} | ||
async getClock() { | ||
return this.parser.parseClock(await this.request('GET', urls.rest.account, `clock`)); | ||
getClock() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return this.parser.parseClock(yield this.request('GET', urls_js_1.default.rest.account, `clock`)); | ||
}); | ||
} | ||
getAccountConfigurations() { | ||
return this.request('GET', urls.rest.account, `account/configurations`); | ||
return this.request('GET', urls_js_1.default.rest.account, `account/configurations`); | ||
} | ||
updateAccountConfigurations(params) { | ||
return this.request('PATCH', urls.rest.account, `account/configurations`, params); | ||
return this.request('PATCH', urls_js_1.default.rest.account, `account/configurations`, params); | ||
} | ||
async getAccountActivities(params) { | ||
return this.parser.parseActivities(await this.request('GET', urls.rest.account, `account/activities/${params.activity_type}?${qs.stringify(params)}`)); | ||
getAccountActivities(params) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return this.parser.parseActivities(yield this.request('GET', urls_js_1.default.rest.account, `account/activities/${params.activity_type}?${qs_1.default.stringify(params)}`)); | ||
}); | ||
} | ||
getPortfolioHistory(params) { | ||
return this.request('GET', urls.rest.account, `account/portfolio/history?${qs.stringify(params)}`); | ||
return this.request('GET', urls_js_1.default.rest.account, `account/portfolio/history?${qs_1.default.stringify(params)}`); | ||
} | ||
@@ -106,14 +149,14 @@ getBars(params) { | ||
transformed['symbols'] = params.symbols.join(','); | ||
return this.request('GET', urls.rest.market_data, `bars/${params.timeframe}?${qs.stringify(params)}`); | ||
return this.request('GET', urls_js_1.default.rest.market_data, `bars/${params.timeframe}?${qs_1.default.stringify(params)}`); | ||
} | ||
getLastTrade(params) { | ||
return this.request('GET', urls.rest.market_data, `last/stocks/${params.symbol}`); | ||
return this.request('GET', urls_js_1.default.rest.market_data, `last/stocks/${params.symbol}`); | ||
} | ||
getLastQuote(params) { | ||
return this.request('GET', urls.rest.market_data, `last_quote/stocks/${params.symbol}`); | ||
return this.request('GET', urls_js_1.default.rest.market_data, `last_quote/stocks/${params.symbol}`); | ||
} | ||
request(method, url, endpoint, data) { | ||
// modify the base url if paper is true | ||
if (this.options.paper && url == urls.rest.account) { | ||
url = urls.rest.account.replace('api.', 'paper-api.'); | ||
if (this.options.paper && url == urls_js_1.default.rest.account) { | ||
url = urls_js_1.default.rest.account.replace('api.', 'paper-api.'); | ||
} | ||
@@ -128,7 +171,7 @@ // convert any dates to ISO 8601 for Alpaca | ||
} | ||
return new Promise(async (resolve, reject) => { | ||
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () { | ||
if (this.options.rate_limit) { | ||
await new Promise((resolve) => this.limiter.removeTokens(1, resolve)); | ||
yield new Promise((resolve) => this.limiter.removeTokens(1, resolve)); | ||
} | ||
await fetch(`${url}/${endpoint}`, { | ||
yield node_fetch_1.default(`${url}/${endpoint}`, { | ||
method: method, | ||
@@ -142,7 +185,8 @@ headers: { | ||
// if json parse fails we default to an empty object | ||
.then(async (resp) => (await resp.json().catch(() => false)) || {}) | ||
.then((resp) => __awaiter(this, void 0, void 0, function* () { return (yield resp.json().catch(() => false)) || {}; })) | ||
.then((resp) => 'code' in resp && 'message' in resp ? reject(resp) : resolve(resp)) | ||
.catch(reject); | ||
}); | ||
})); | ||
} | ||
} | ||
exports.AlpacaClient = AlpacaClient; |
@@ -1,1 +0,2 @@ | ||
export {}; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); |
@@ -1,1 +0,2 @@ | ||
export {}; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); |
@@ -1,2 +0,5 @@ | ||
export class Parser { | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Parser = void 0; | ||
class Parser { | ||
parseAccount(rawAccount) { | ||
@@ -7,22 +10,3 @@ if (!rawAccount) { | ||
try { | ||
return { | ||
...rawAccount, | ||
raw: () => rawAccount, | ||
buying_power: this.parseNumber(rawAccount.buying_power), | ||
regt_buying_power: this.parseNumber(rawAccount.regt_buying_power), | ||
daytrading_buying_power: this.parseNumber(rawAccount.daytrading_buying_power), | ||
cash: this.parseNumber(rawAccount.cash), | ||
created_at: new Date(rawAccount.created_at), | ||
portfolio_value: this.parseNumber(rawAccount.portfolio_value), | ||
multiplier: this.parseNumber(rawAccount.multiplier), | ||
equity: this.parseNumber(rawAccount.equity), | ||
last_equity: this.parseNumber(rawAccount.last_equity), | ||
long_market_value: this.parseNumber(rawAccount.long_market_value), | ||
short_market_value: this.parseNumber(rawAccount.short_market_value), | ||
initial_margin: this.parseNumber(rawAccount.initial_margin), | ||
maintenance_margin: this.parseNumber(rawAccount.maintenance_margin), | ||
last_maintenance_margin: this.parseNumber(rawAccount.last_maintenance_margin), | ||
sma: this.parseNumber(rawAccount.sma), | ||
status: rawAccount.status, | ||
}; | ||
return Object.assign(Object.assign({}, rawAccount), { raw: () => rawAccount, buying_power: this.parseNumber(rawAccount.buying_power), regt_buying_power: this.parseNumber(rawAccount.regt_buying_power), daytrading_buying_power: this.parseNumber(rawAccount.daytrading_buying_power), cash: this.parseNumber(rawAccount.cash), created_at: new Date(rawAccount.created_at), portfolio_value: this.parseNumber(rawAccount.portfolio_value), multiplier: this.parseNumber(rawAccount.multiplier), equity: this.parseNumber(rawAccount.equity), last_equity: this.parseNumber(rawAccount.last_equity), long_market_value: this.parseNumber(rawAccount.long_market_value), short_market_value: this.parseNumber(rawAccount.short_market_value), initial_margin: this.parseNumber(rawAccount.initial_margin), maintenance_margin: this.parseNumber(rawAccount.maintenance_margin), last_maintenance_margin: this.parseNumber(rawAccount.last_maintenance_margin), sma: this.parseNumber(rawAccount.sma), status: rawAccount.status }); | ||
} | ||
@@ -55,27 +39,3 @@ catch (err) { | ||
try { | ||
return { | ||
...rawOrder, | ||
raw: () => rawOrder, | ||
created_at: new Date(rawOrder.created_at), | ||
updated_at: new Date(rawOrder.updated_at), | ||
submitted_at: new Date(rawOrder.submitted_at), | ||
filled_at: new Date(rawOrder.filled_at), | ||
expired_at: new Date(rawOrder.expired_at), | ||
canceled_at: new Date(rawOrder.canceled_at), | ||
failed_at: new Date(rawOrder.failed_at), | ||
replaced_at: new Date(rawOrder.replaced_at), | ||
qty: this.parseNumber(rawOrder.qty), | ||
filled_qty: this.parseNumber(rawOrder.filled_qty), | ||
type: rawOrder.type, | ||
side: rawOrder.side, | ||
time_in_force: rawOrder.time_in_force, | ||
limit_price: this.parseNumber(rawOrder.limit_price), | ||
stop_price: this.parseNumber(rawOrder.stop_price), | ||
filled_avg_price: this.parseNumber(rawOrder.filled_avg_price), | ||
status: rawOrder.status, | ||
legs: this.parseOrders(rawOrder.legs), | ||
trail_price: this.parseNumber(rawOrder.trail_price), | ||
trail_percent: this.parseNumber(rawOrder.trail_percent), | ||
hwm: this.parseNumber(rawOrder.hwm), | ||
}; | ||
return Object.assign(Object.assign({}, rawOrder), { raw: () => rawOrder, created_at: new Date(rawOrder.created_at), updated_at: new Date(rawOrder.updated_at), submitted_at: new Date(rawOrder.submitted_at), filled_at: new Date(rawOrder.filled_at), expired_at: new Date(rawOrder.expired_at), canceled_at: new Date(rawOrder.canceled_at), failed_at: new Date(rawOrder.failed_at), replaced_at: new Date(rawOrder.replaced_at), qty: this.parseNumber(rawOrder.qty), filled_qty: this.parseNumber(rawOrder.filled_qty), type: rawOrder.type, side: rawOrder.side, time_in_force: rawOrder.time_in_force, limit_price: this.parseNumber(rawOrder.limit_price), stop_price: this.parseNumber(rawOrder.stop_price), filled_avg_price: this.parseNumber(rawOrder.filled_avg_price), status: rawOrder.status, legs: this.parseOrders(rawOrder.legs), trail_price: this.parseNumber(rawOrder.trail_price), trail_percent: this.parseNumber(rawOrder.trail_percent), hwm: this.parseNumber(rawOrder.hwm) }); | ||
} | ||
@@ -94,18 +54,3 @@ catch (err) { | ||
try { | ||
return { | ||
...rawPosition, | ||
raw: () => rawPosition, | ||
avg_entry_price: this.parseNumber(rawPosition.avg_entry_price), | ||
qty: this.parseNumber(rawPosition.qty), | ||
side: rawPosition.side, | ||
market_value: this.parseNumber(rawPosition.market_value), | ||
cost_basis: this.parseNumber(rawPosition.cost_basis), | ||
unrealized_pl: this.parseNumber(rawPosition.unrealized_pl), | ||
unrealized_plpc: this.parseNumber(rawPosition.unrealized_plpc), | ||
unrealized_intraday_pl: this.parseNumber(rawPosition.unrealized_intraday_pl), | ||
unrealized_intraday_plpc: this.parseNumber(rawPosition.unrealized_intraday_plpc), | ||
current_price: this.parseNumber(rawPosition.current_price), | ||
lastday_price: this.parseNumber(rawPosition.lastday_price), | ||
change_today: this.parseNumber(rawPosition.change_today), | ||
}; | ||
return Object.assign(Object.assign({}, rawPosition), { raw: () => rawPosition, avg_entry_price: this.parseNumber(rawPosition.avg_entry_price), qty: this.parseNumber(rawPosition.qty), side: rawPosition.side, market_value: this.parseNumber(rawPosition.market_value), cost_basis: this.parseNumber(rawPosition.cost_basis), unrealized_pl: this.parseNumber(rawPosition.unrealized_pl), unrealized_plpc: this.parseNumber(rawPosition.unrealized_plpc), unrealized_intraday_pl: this.parseNumber(rawPosition.unrealized_intraday_pl), unrealized_intraday_plpc: this.parseNumber(rawPosition.unrealized_intraday_plpc), current_price: this.parseNumber(rawPosition.current_price), lastday_price: this.parseNumber(rawPosition.lastday_price), change_today: this.parseNumber(rawPosition.change_today) }); | ||
} | ||
@@ -126,12 +71,3 @@ catch (err) { | ||
try { | ||
return { | ||
...rawTradeActivity, | ||
raw: () => rawTradeActivity, | ||
cum_qty: this.parseNumber(rawTradeActivity.cum_qty), | ||
leaves_qty: this.parseNumber(rawTradeActivity.leaves_qty), | ||
price: this.parseNumber(rawTradeActivity.price), | ||
qty: this.parseNumber(rawTradeActivity.qty), | ||
side: rawTradeActivity.side, | ||
type: rawTradeActivity.type, | ||
}; | ||
return Object.assign(Object.assign({}, rawTradeActivity), { raw: () => rawTradeActivity, cum_qty: this.parseNumber(rawTradeActivity.cum_qty), leaves_qty: this.parseNumber(rawTradeActivity.leaves_qty), price: this.parseNumber(rawTradeActivity.price), qty: this.parseNumber(rawTradeActivity.qty), side: rawTradeActivity.side, type: rawTradeActivity.type }); | ||
} | ||
@@ -147,9 +83,3 @@ catch (err) { | ||
try { | ||
return { | ||
...rawNonTradeActivity, | ||
raw: () => rawNonTradeActivity, | ||
net_amount: this.parseNumber(rawNonTradeActivity.net_amount), | ||
qty: this.parseNumber(rawNonTradeActivity.qty), | ||
per_share_amount: this.parseNumber(rawNonTradeActivity.per_share_amount), | ||
}; | ||
return Object.assign(Object.assign({}, rawNonTradeActivity), { raw: () => rawNonTradeActivity, net_amount: this.parseNumber(rawNonTradeActivity.net_amount), qty: this.parseNumber(rawNonTradeActivity.qty), per_share_amount: this.parseNumber(rawNonTradeActivity.per_share_amount) }); | ||
} | ||
@@ -177,1 +107,2 @@ catch (err) { | ||
} | ||
exports.Parser = Parser; |
@@ -1,5 +0,11 @@ | ||
import WebSocket from 'ws'; | ||
import urls from './urls.js'; | ||
import { EventEmitter } from 'events'; | ||
export class AlpacaStream extends EventEmitter { | ||
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.AlpacaStream = void 0; | ||
const ws_1 = __importDefault(require("ws")); | ||
const urls_js_1 = __importDefault(require("./urls.js")); | ||
const events_1 = require("events"); | ||
class AlpacaStream extends events_1.EventEmitter { | ||
constructor(params) { | ||
@@ -14,6 +20,6 @@ // construct EventEmitter | ||
case 'account': | ||
this.host = urls.websocket.account; | ||
this.host = urls_js_1.default.websocket.account; | ||
break; | ||
case 'market_data': | ||
this.host = urls.websocket.market_data; | ||
this.host = urls_js_1.default.websocket.market_data; | ||
break; | ||
@@ -23,3 +29,3 @@ default: | ||
} | ||
this.connection = new WebSocket(this.host) | ||
this.connection = new ws_1.default(this.host) | ||
.once('open', () => { | ||
@@ -114,1 +120,2 @@ // if we are not authenticated yet send a request now | ||
} | ||
exports.AlpacaStream = AlpacaStream; |
@@ -1,6 +0,8 @@ | ||
import { Parser } from '../parser'; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const parser_1 = require("../parser"); | ||
describe('Parser', () => { | ||
describe('parseAccount', () => { | ||
it('should handle missing input', () => { | ||
const parser = new Parser(); | ||
const parser = new parser_1.Parser(); | ||
const result = parser.parseAccount(null); | ||
@@ -10,3 +12,3 @@ expect(result).toBeNull(); | ||
it('should make a raw function to return the raw input', () => { | ||
const parser = new Parser(); | ||
const parser = new parser_1.Parser(); | ||
const rawAccount = {}; | ||
@@ -18,3 +20,3 @@ const account = parser.parseAccount(rawAccount); | ||
it('should parse buying power to a number', () => { | ||
const parser = new Parser(); | ||
const parser = new parser_1.Parser(); | ||
const rawAccount = { | ||
@@ -29,3 +31,3 @@ buying_power: '123.456', | ||
it('should handle missing input', () => { | ||
const parser = new Parser(); | ||
const parser = new parser_1.Parser(); | ||
const result = parser.parseOrder(null); | ||
@@ -35,3 +37,3 @@ expect(result).toBeNull(); | ||
it('should make a raw function to return the raw input', () => { | ||
const parser = new Parser(); | ||
const parser = new parser_1.Parser(); | ||
const rawOrder = {}; | ||
@@ -43,3 +45,3 @@ const account = parser.parseOrder(rawOrder); | ||
it('should parse qty to a number', () => { | ||
const parser = new Parser(); | ||
const parser = new parser_1.Parser(); | ||
const rawOrder = { | ||
@@ -52,3 +54,3 @@ qty: '42', | ||
it('should parse legs if they exist', () => { | ||
const parser = new Parser(); | ||
const parser = new parser_1.Parser(); | ||
const rawOrder = { | ||
@@ -65,3 +67,3 @@ legs: [ | ||
it(`should not parse legs if they don't exist`, () => { | ||
const parser = new Parser(); | ||
const parser = new parser_1.Parser(); | ||
const rawOrder = { | ||
@@ -76,3 +78,3 @@ legs: null, | ||
it('should parse orders if they exist', () => { | ||
const parser = new Parser(); | ||
const parser = new parser_1.Parser(); | ||
const rawOrders = [ | ||
@@ -87,3 +89,3 @@ { | ||
it(`should not parse orders if they don't exist`, () => { | ||
const parser = new Parser(); | ||
const parser = new parser_1.Parser(); | ||
const result = parser.parseOrders(null); | ||
@@ -95,3 +97,3 @@ expect(result).toBeNull(); | ||
it('should handle missing input', () => { | ||
const parser = new Parser(); | ||
const parser = new parser_1.Parser(); | ||
const result = parser.parsePosition(null); | ||
@@ -101,3 +103,3 @@ expect(result).toBeNull(); | ||
it('should make a raw function that returns the raw input', () => { | ||
const parser = new Parser(); | ||
const parser = new parser_1.Parser(); | ||
const rawPosition = {}; | ||
@@ -109,3 +111,3 @@ const position = parser.parsePosition(rawPosition); | ||
it('should parse qty to a number', () => { | ||
const parser = new Parser(); | ||
const parser = new parser_1.Parser(); | ||
const rawPosition = { | ||
@@ -120,3 +122,3 @@ qty: '42', | ||
it('should parse positions if they exist', () => { | ||
const parser = new Parser(); | ||
const parser = new parser_1.Parser(); | ||
const rawPositions = null; | ||
@@ -127,3 +129,3 @@ const result = parser.parsePositions(rawPositions); | ||
it(`should not parse positions if they don't exist`, () => { | ||
const parser = new Parser(); | ||
const parser = new parser_1.Parser(); | ||
const rawPositions = [ | ||
@@ -140,3 +142,3 @@ { | ||
it('should handle missing input', () => { | ||
const parser = new Parser(); | ||
const parser = new parser_1.Parser(); | ||
const result = parser.parseTradeActivity(null); | ||
@@ -146,3 +148,3 @@ expect(result).toBeNull(); | ||
it('should make a raw function that returns the raw input', () => { | ||
const parser = new Parser(); | ||
const parser = new parser_1.Parser(); | ||
const rawTradeActivity = {}; | ||
@@ -154,3 +156,3 @@ const position = parser.parseTradeActivity(rawTradeActivity); | ||
it('should parse qty to a number', () => { | ||
const parser = new Parser(); | ||
const parser = new parser_1.Parser(); | ||
const rawTradeActivity = { | ||
@@ -165,3 +167,3 @@ qty: '42', | ||
it('should handle missing input', () => { | ||
const parser = new Parser(); | ||
const parser = new parser_1.Parser(); | ||
const result = parser.parseNonTradeActivity(null); | ||
@@ -171,3 +173,3 @@ expect(result).toBeNull(); | ||
it('should make a raw function that returns the raw input', () => { | ||
const parser = new Parser(); | ||
const parser = new parser_1.Parser(); | ||
const rawNonTradeActivity = {}; | ||
@@ -179,3 +181,3 @@ const position = parser.parseNonTradeActivity(rawNonTradeActivity); | ||
it('should parse qty to a number', () => { | ||
const parser = new Parser(); | ||
const parser = new parser_1.Parser(); | ||
const rawNonTradeActivity = { | ||
@@ -190,3 +192,3 @@ qty: '42', | ||
it('should handle missing input', () => { | ||
const parser = new Parser(); | ||
const parser = new parser_1.Parser(); | ||
const result = parser.parseActivities(null); | ||
@@ -196,3 +198,3 @@ expect(result).toBeNull(); | ||
it('should parse each activity type', () => { | ||
const parser = new Parser(); | ||
const parser = new parser_1.Parser(); | ||
const rawActivities = [ | ||
@@ -199,0 +201,0 @@ { |
@@ -1,2 +0,4 @@ | ||
export default { | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.default = { | ||
rest: { | ||
@@ -3,0 +5,0 @@ account: 'https://api.alpaca.markets/v2', |
{ | ||
"name": "@master-chief/alpaca", | ||
"version": "2.0.2", | ||
"version": "2.1.3", | ||
"description": "a TypeScript Node.js library for the https://alpaca.markets REST API and WebSocket streams", | ||
"main": "dist/index.js", | ||
"types": "types/index.d.ts", | ||
"type": "module", | ||
"keywords": [ | ||
@@ -9,0 +8,0 @@ "alpaca", |
{ | ||
"compilerOptions": { | ||
"outDir": "dist/", | ||
"target": "ESNEXT", | ||
"module": "ES6", | ||
"target": "ES6", | ||
"module": "CommonJS", | ||
"moduleResolution": "node", | ||
@@ -7,0 +7,0 @@ "declaration": true, |
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
134190
4292
0
No