@master-chief/alpaca
Advanced tools
Comparing version 1.3.0 to 1.4.1
@@ -1,6 +0,2 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var client_1 = require("./lib/client"); | ||
Object.defineProperty(exports, "Client", { enumerable: true, get: function () { return client_1.Client; } }); | ||
var stream_1 = require("./lib/stream"); | ||
Object.defineProperty(exports, "Stream", { enumerable: true, get: function () { return stream_1.Stream; } }); | ||
export { Client } from './lib/client.js'; | ||
export { Stream } from './lib/stream.js'; |
@@ -1,16 +0,9 @@ | ||
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Client = void 0; | ||
const node_fetch_1 = __importDefault(require("node-fetch")); | ||
const http_method_enum_1 = __importDefault(require("http-method-enum")); | ||
const qs_1 = __importDefault(require("qs")); | ||
const urls_1 = __importDefault(require("./urls")); | ||
const limiter_1 = require("limiter"); | ||
class Client { | ||
import fetch from 'node-fetch'; | ||
import qs from 'qs'; | ||
import limiter from 'limiter'; | ||
import urls from './urls.js'; | ||
export class Client { | ||
constructor(options) { | ||
this.options = options; | ||
this.limiter = new limiter_1.RateLimiter(199, 'minute'); | ||
this.limiter = new limiter.RateLimiter(199, 'minute'); | ||
} | ||
@@ -27,6 +20,6 @@ async isAuthenticated() { | ||
getAccount() { | ||
return this.request(http_method_enum_1.default.GET, urls_1.default.rest.account, 'account'); | ||
return this.request('GET', urls.rest.account, 'account'); | ||
} | ||
getOrder(params) { | ||
return this.request(http_method_enum_1.default.GET, urls_1.default.rest.account, `orders/${params.order_id || params.client_order_id}?${qs_1.default.stringify({ | ||
return this.request('GET', urls.rest.account, `orders/${params.order_id || params.client_order_id}?${qs.stringify({ | ||
nested: params.nested, | ||
@@ -36,72 +29,72 @@ })}`); | ||
getOrders(params) { | ||
return this.request(http_method_enum_1.default.GET, urls_1.default.rest.account, `orders?${qs_1.default.stringify(params)}`); | ||
return this.request('GET', urls.rest.account, `orders?${qs.stringify(params)}`); | ||
} | ||
placeOrder(params) { | ||
return this.request(http_method_enum_1.default.POST, urls_1.default.rest.account, `orders`, params); | ||
return this.request('POST', urls.rest.account, `orders`, params); | ||
} | ||
replaceOrder(params) { | ||
return this.request(http_method_enum_1.default.PATCH, urls_1.default.rest.account, `orders/${params.order_id}`, params); | ||
return this.request('PATCH', urls.rest.account, `orders/${params.order_id}`, params); | ||
} | ||
cancelOrder(params) { | ||
return this.request(http_method_enum_1.default.DELETE, urls_1.default.rest.account, `orders/${params.order_id}`); | ||
return this.request('DELETE', urls.rest.account, `orders/${params.order_id}`); | ||
} | ||
cancelOrders() { | ||
return this.request(http_method_enum_1.default.DELETE, urls_1.default.rest.account, `orders`); | ||
return this.request('DELETE', urls.rest.account, `orders`); | ||
} | ||
getPosition(params) { | ||
return this.request(http_method_enum_1.default.GET, urls_1.default.rest.account, `positions/${params.symbol}`); | ||
return this.request('GET', urls.rest.account, `positions/${params.symbol}`); | ||
} | ||
getPositions() { | ||
return this.request(http_method_enum_1.default.GET, urls_1.default.rest.account, `positions`); | ||
return this.request('GET', urls.rest.account, `positions`); | ||
} | ||
closePosition(params) { | ||
return this.request(http_method_enum_1.default.DELETE, urls_1.default.rest.account, `positions/${params.symbol}`); | ||
return this.request('DELETE', urls.rest.account, `positions/${params.symbol}`); | ||
} | ||
closePositions() { | ||
return this.request(http_method_enum_1.default.DELETE, urls_1.default.rest.account, `positions`); | ||
return this.request('DELETE', urls.rest.account, `positions`); | ||
} | ||
getAsset(params) { | ||
return this.request(http_method_enum_1.default.GET, urls_1.default.rest.account, `assets/${params.asset_id_or_symbol}`); | ||
return this.request('GET', urls.rest.account, `assets/${params.asset_id_or_symbol}`); | ||
} | ||
getAssets(params) { | ||
return this.request(http_method_enum_1.default.GET, urls_1.default.rest.account, `assets?${qs_1.default.stringify(params)}`); | ||
return this.request('GET', urls.rest.account, `assets?${qs.stringify(params)}`); | ||
} | ||
getWatchlist(params) { | ||
return this.request(http_method_enum_1.default.GET, urls_1.default.rest.account, `watchlists/${params.uuid}`); | ||
return this.request('GET', urls.rest.account, `watchlists/${params.uuid}`); | ||
} | ||
getWatchlists() { | ||
return this.request(http_method_enum_1.default.GET, urls_1.default.rest.account, `watchlists`); | ||
return this.request('GET', urls.rest.account, `watchlists`); | ||
} | ||
createWatchlist(params) { | ||
return this.request(http_method_enum_1.default.POST, urls_1.default.rest.account, `watchlists`, params); | ||
return this.request('POST', urls.rest.account, `watchlists`, params); | ||
} | ||
updateWatchlist(params) { | ||
return this.request(http_method_enum_1.default.PUT, urls_1.default.rest.account, `watchlists/${params.uuid}`, params); | ||
return this.request('PUT', urls.rest.account, `watchlists/${params.uuid}`, params); | ||
} | ||
addToWatchlist(params) { | ||
return this.request(http_method_enum_1.default.POST, urls_1.default.rest.account, `watchlists/${params.uuid}`, params); | ||
return this.request('POST', urls.rest.account, `watchlists/${params.uuid}`, params); | ||
} | ||
removeFromWatchlist(params) { | ||
return this.request(http_method_enum_1.default.DELETE, urls_1.default.rest.account, `watchlists/${params.uuid}/${params.symbol}`); | ||
return this.request('DELETE', urls.rest.account, `watchlists/${params.uuid}/${params.symbol}`); | ||
} | ||
deleteWatchlist(params) { | ||
return this.request(http_method_enum_1.default.DELETE, urls_1.default.rest.account, `watchlists/${params.uuid}`); | ||
return this.request('DELETE', urls.rest.account, `watchlists/${params.uuid}`); | ||
} | ||
getCalendar(params) { | ||
return this.request(http_method_enum_1.default.GET, urls_1.default.rest.account, `calendar?${qs_1.default.stringify(params)}`); | ||
return this.request('GET', urls.rest.account, `calendar?${qs.stringify(params)}`); | ||
} | ||
getClock() { | ||
return this.request(http_method_enum_1.default.GET, urls_1.default.rest.account, `clock`); | ||
return this.request('GET', urls.rest.account, `clock`); | ||
} | ||
getAccountConfigurations() { | ||
return this.request(http_method_enum_1.default.GET, urls_1.default.rest.account, `account/configurations`); | ||
return this.request('GET', urls.rest.account, `account/configurations`); | ||
} | ||
updateAccountConfigurations(params) { | ||
return this.request(http_method_enum_1.default.PATCH, urls_1.default.rest.account, `account/configurations`, params); | ||
return this.request('PATCH', urls.rest.account, `account/configurations`, params); | ||
} | ||
getAccountActivities(params) { | ||
return this.request(http_method_enum_1.default.GET, urls_1.default.rest.account, `account/activities/${params.activity_type}?${qs_1.default.stringify(params)}`); | ||
return this.request('GET', urls.rest.account, `account/activities/${params.activity_type}?${qs.stringify(params)}`); | ||
} | ||
getPortfolioHistory(params) { | ||
return this.request(http_method_enum_1.default.GET, urls_1.default.rest.account, `account/portfolio/history?${qs_1.default.stringify(params)}`); | ||
return this.request('GET', urls.rest.account, `account/portfolio/history?${qs.stringify(params)}`); | ||
} | ||
@@ -113,14 +106,14 @@ getBars(params) { | ||
transformed['symbols'] = params.symbols.join(','); | ||
return this.request(http_method_enum_1.default.GET, urls_1.default.rest.market_data, `bars/${params.timeframe}?${qs_1.default.stringify(params)}`); | ||
return this.request('GET', urls.rest.market_data, `bars/${params.timeframe}?${qs.stringify(params)}`); | ||
} | ||
getLastTrade(params) { | ||
return this.request(http_method_enum_1.default.GET, urls_1.default.rest.market_data, `last/stocks/${params.symbol}`); | ||
return this.request('GET', urls.rest.market_data, `last/stocks/${params.symbol}`); | ||
} | ||
getLastQuote(params) { | ||
return this.request(http_method_enum_1.default.GET, urls_1.default.rest.market_data, `last_quote/stocks/${params.symbol}`); | ||
return this.request('GET', urls.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_1.default.rest.account) { | ||
url = urls_1.default.rest.account.replace('api.', 'paper-api.'); | ||
if (this.options.paper && url == urls.rest.account) { | ||
url = urls.rest.account.replace('api.', 'paper-api.'); | ||
} | ||
@@ -140,3 +133,3 @@ // convert any dates to ISO 8601 for Alpaca | ||
} | ||
await node_fetch_1.default(`${url}/${endpoint}`, { | ||
await fetch(`${url}/${endpoint}`, { | ||
method: method, | ||
@@ -147,3 +140,3 @@ headers: { | ||
}, | ||
body: JSON.stringify(data), | ||
body: data ? JSON.stringify(data) : undefined, | ||
}) | ||
@@ -158,2 +151,1 @@ .then( | ||
} | ||
exports.Client = Client; |
@@ -1,11 +0,5 @@ | ||
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Stream = void 0; | ||
const ws_1 = __importDefault(require("ws")); | ||
const events_1 = require("events"); | ||
const urls_1 = __importDefault(require("./urls")); | ||
class Stream extends events_1.EventEmitter { | ||
import WebSocket from 'ws'; | ||
import urls from './urls.js'; | ||
import { EventEmitter } from 'events'; | ||
export class Stream extends EventEmitter { | ||
constructor(params) { | ||
@@ -20,6 +14,6 @@ // construct EventEmitter | ||
case 'account': | ||
this.host = urls_1.default.websocket.account; | ||
this.host = urls.websocket.account; | ||
break; | ||
case 'market_data': | ||
this.host = urls_1.default.websocket.market_data; | ||
this.host = urls.websocket.market_data; | ||
break; | ||
@@ -29,3 +23,3 @@ default: | ||
} | ||
this.connection = new ws_1.default(this.host) | ||
this.connection = new WebSocket(this.host) | ||
.once('open', () => { | ||
@@ -120,2 +114,1 @@ // if we are not authenticated yet send a request now | ||
} | ||
exports.Stream = Stream; |
@@ -1,4 +0,2 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.default = { | ||
export default { | ||
rest: { | ||
@@ -5,0 +3,0 @@ account: 'https://api.alpaca.markets/v2', |
@@ -1,3 +0,3 @@ | ||
export { Client } from './lib/client' | ||
export { Stream } from './lib/stream' | ||
export { Client } from './lib/client.js' | ||
export { Stream } from './lib/stream.js' | ||
@@ -19,3 +19,3 @@ export { | ||
LastTrade, | ||
} from './lib/entities' | ||
} from './lib/entities.js' | ||
@@ -45,2 +45,2 @@ export { | ||
GetLastQuote, | ||
} from './lib/params' | ||
} from './lib/params.js' |
import fetch from 'node-fetch' | ||
import method from 'http-method-enum' | ||
import qs from 'qs' | ||
import limiter from 'limiter' | ||
import urls from './urls.js' | ||
import urls from './urls' | ||
import { RateLimiter } from 'limiter' | ||
import { | ||
@@ -25,3 +22,3 @@ Account, | ||
Credentials, | ||
} from './entities' | ||
} from './entities.js' | ||
@@ -51,6 +48,6 @@ import { | ||
GetLastQuote, | ||
} from './params' | ||
} from './params.js' | ||
export class Client { | ||
private limiter: RateLimiter = new RateLimiter(199, 'minute') | ||
private limiter = new limiter.RateLimiter(199, 'minute') | ||
@@ -75,3 +72,3 @@ constructor( | ||
getAccount(): Promise<Account> { | ||
return this.request(method.GET, urls.rest.account, 'account') | ||
return this.request('GET', urls.rest.account, 'account') | ||
} | ||
@@ -81,3 +78,3 @@ | ||
return this.request( | ||
method.GET, | ||
'GET', | ||
urls.rest.account, | ||
@@ -92,3 +89,3 @@ `orders/${params.order_id || params.client_order_id}?${qs.stringify({ | ||
return this.request( | ||
method.GET, | ||
'GET', | ||
urls.rest.account, | ||
@@ -100,3 +97,3 @@ `orders?${qs.stringify(params)}` | ||
placeOrder(params: PlaceOrder): Promise<Order> { | ||
return this.request(method.POST, urls.rest.account, `orders`, params) | ||
return this.request('POST', urls.rest.account, `orders`, params) | ||
} | ||
@@ -106,3 +103,3 @@ | ||
return this.request( | ||
method.PATCH, | ||
'PATCH', | ||
urls.rest.account, | ||
@@ -116,3 +113,3 @@ `orders/${params.order_id}`, | ||
return this.request( | ||
method.DELETE, | ||
'DELETE', | ||
urls.rest.account, | ||
@@ -124,15 +121,11 @@ `orders/${params.order_id}` | ||
cancelOrders(): Promise<Order[]> { | ||
return this.request(method.DELETE, urls.rest.account, `orders`) | ||
return this.request('DELETE', urls.rest.account, `orders`) | ||
} | ||
getPosition(params: GetPosition): Promise<Position> { | ||
return this.request( | ||
method.GET, | ||
urls.rest.account, | ||
`positions/${params.symbol}` | ||
) | ||
return this.request('GET', urls.rest.account, `positions/${params.symbol}`) | ||
} | ||
getPositions(): Promise<Position[]> { | ||
return this.request(method.GET, urls.rest.account, `positions`) | ||
return this.request('GET', urls.rest.account, `positions`) | ||
} | ||
@@ -142,3 +135,3 @@ | ||
return this.request( | ||
method.DELETE, | ||
'DELETE', | ||
urls.rest.account, | ||
@@ -150,3 +143,3 @@ `positions/${params.symbol}` | ||
closePositions(): Promise<Order[]> { | ||
return this.request(method.DELETE, urls.rest.account, `positions`) | ||
return this.request('DELETE', urls.rest.account, `positions`) | ||
} | ||
@@ -156,3 +149,3 @@ | ||
return this.request( | ||
method.GET, | ||
'GET', | ||
urls.rest.account, | ||
@@ -165,3 +158,3 @@ `assets/${params.asset_id_or_symbol}` | ||
return this.request( | ||
method.GET, | ||
'GET', | ||
urls.rest.account, | ||
@@ -173,15 +166,11 @@ `assets?${qs.stringify(params)}` | ||
getWatchlist(params: GetWatchList): Promise<Watchlist> { | ||
return this.request( | ||
method.GET, | ||
urls.rest.account, | ||
`watchlists/${params.uuid}` | ||
) | ||
return this.request('GET', urls.rest.account, `watchlists/${params.uuid}`) | ||
} | ||
getWatchlists(): Promise<Watchlist[]> { | ||
return this.request(method.GET, urls.rest.account, `watchlists`) | ||
return this.request('GET', urls.rest.account, `watchlists`) | ||
} | ||
createWatchlist(params: CreateWatchList): Promise<Watchlist[]> { | ||
return this.request(method.POST, urls.rest.account, `watchlists`, params) | ||
return this.request('POST', urls.rest.account, `watchlists`, params) | ||
} | ||
@@ -191,3 +180,3 @@ | ||
return this.request( | ||
method.PUT, | ||
'PUT', | ||
urls.rest.account, | ||
@@ -201,3 +190,3 @@ `watchlists/${params.uuid}`, | ||
return this.request( | ||
method.POST, | ||
'POST', | ||
urls.rest.account, | ||
@@ -211,3 +200,3 @@ `watchlists/${params.uuid}`, | ||
return this.request( | ||
method.DELETE, | ||
'DELETE', | ||
urls.rest.account, | ||
@@ -220,3 +209,3 @@ `watchlists/${params.uuid}/${params.symbol}` | ||
return this.request( | ||
method.DELETE, | ||
'DELETE', | ||
urls.rest.account, | ||
@@ -229,3 +218,3 @@ `watchlists/${params.uuid}` | ||
return this.request( | ||
method.GET, | ||
'GET', | ||
urls.rest.account, | ||
@@ -237,7 +226,7 @@ `calendar?${qs.stringify(params)}` | ||
getClock(): Promise<Clock> { | ||
return this.request(method.GET, urls.rest.account, `clock`) | ||
return this.request('GET', urls.rest.account, `clock`) | ||
} | ||
getAccountConfigurations(): Promise<AccountConfigurations> { | ||
return this.request(method.GET, urls.rest.account, `account/configurations`) | ||
return this.request('GET', urls.rest.account, `account/configurations`) | ||
} | ||
@@ -249,3 +238,3 @@ | ||
return this.request( | ||
method.PATCH, | ||
'PATCH', | ||
urls.rest.account, | ||
@@ -261,3 +250,3 @@ `account/configurations`, | ||
return this.request( | ||
method.GET, | ||
'GET', | ||
urls.rest.account, | ||
@@ -270,3 +259,3 @@ `account/activities/${params.activity_type}?${qs.stringify(params)}` | ||
return this.request( | ||
method.GET, | ||
'GET', | ||
urls.rest.account, | ||
@@ -285,3 +274,3 @@ `account/portfolio/history?${qs.stringify(params)}` | ||
return this.request( | ||
method.GET, | ||
'GET', | ||
urls.rest.market_data, | ||
@@ -294,3 +283,3 @@ `bars/${params.timeframe}?${qs.stringify(params)}` | ||
return this.request( | ||
method.GET, | ||
'GET', | ||
urls.rest.market_data, | ||
@@ -303,3 +292,3 @@ `last/stocks/${params.symbol}` | ||
return this.request( | ||
method.GET, | ||
'GET', | ||
urls.rest.market_data, | ||
@@ -311,3 +300,3 @@ `last_quote/stocks/${params.symbol}` | ||
private request( | ||
method: method, | ||
method: string, | ||
url: string, | ||
@@ -345,3 +334,3 @@ endpoint: string, | ||
}, | ||
body: JSON.stringify(data), | ||
body: data ? JSON.stringify(data) : undefined, | ||
}) | ||
@@ -348,0 +337,0 @@ .then( |
import WebSocket from 'ws' | ||
import urls from './urls.js' | ||
import { EventEmitter } from 'events' | ||
import { Credentials } from './entities' | ||
import urls from './urls' | ||
import { Credentials } from './entities.js' | ||
@@ -7,0 +7,0 @@ export declare interface Stream { |
{ | ||
"name": "@master-chief/alpaca", | ||
"version": "1.3.0", | ||
"description": "A TypeScript Node.js library for the https://alpaca.markets REST API and WebSocket streams.", | ||
"version": "1.4.1", | ||
"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": [ | ||
@@ -30,3 +31,2 @@ "alpaca", | ||
"dependencies": { | ||
"http-method-enum": "^1.0.0", | ||
"limiter": "^1.1.5", | ||
@@ -40,5 +40,4 @@ "node-fetch": "^2.6.0", | ||
"@types/qs": "^6.9.3", | ||
"@types/ws": "^7.2.4", | ||
"ava": "^3.8.2" | ||
"@types/ws": "^7.2.4" | ||
} | ||
} |
@@ -5,3 +5,4 @@ { | ||
"target": "ESNEXT", | ||
"module": "commonjs", | ||
"module": "ES6", | ||
"moduleResolution": "node", | ||
"declaration": true, | ||
@@ -8,0 +9,0 @@ "strict": false, |
@@ -1,4 +0,4 @@ | ||
export { Client } from './lib/client'; | ||
export { Stream } from './lib/stream'; | ||
export { Account, Order, Position, Asset, Watchlist, Calendar, Clock, AccountConfigurations, NonTradeActivity, TradeActivity, PortfolioHistory, Bar, LastQuote, LastTrade, } from './lib/entities'; | ||
export { GetOrder, GetOrders, PlaceOrder, ReplaceOrder, CancelOrder, GetPosition, ClosePosition, GetAsset, GetAssets, GetWatchList, CreateWatchList, UpdateWatchList, AddToWatchList, RemoveFromWatchList, DeleteWatchList, GetCalendar, UpdateAccountConfigurations, GetAccountActivities, GetPortfolioHistory, GetBars, GetLastTrade, GetLastQuote, } from './lib/params'; | ||
export { Client } from './lib/client.js'; | ||
export { Stream } from './lib/stream.js'; | ||
export { Account, Order, Position, Asset, Watchlist, Calendar, Clock, AccountConfigurations, NonTradeActivity, TradeActivity, PortfolioHistory, Bar, LastQuote, LastTrade, } from './lib/entities.js'; | ||
export { GetOrder, GetOrders, PlaceOrder, ReplaceOrder, CancelOrder, GetPosition, ClosePosition, GetAsset, GetAssets, GetWatchList, CreateWatchList, UpdateWatchList, AddToWatchList, RemoveFromWatchList, DeleteWatchList, GetCalendar, UpdateAccountConfigurations, GetAccountActivities, GetPortfolioHistory, GetBars, GetLastTrade, GetLastQuote, } from './lib/params.js'; |
@@ -1,3 +0,3 @@ | ||
import { Account, Order, Position, Asset, Watchlist, Calendar, Clock, AccountConfigurations, NonTradeActivity, TradeActivity, PortfolioHistory, Bar, LastQuote, LastTrade, Credentials } from './entities'; | ||
import { GetOrder, GetOrders, PlaceOrder, ReplaceOrder, CancelOrder, GetPosition, ClosePosition, GetAsset, GetAssets, GetWatchList, CreateWatchList, UpdateWatchList, AddToWatchList, RemoveFromWatchList, DeleteWatchList, GetCalendar, UpdateAccountConfigurations, GetAccountActivities, GetPortfolioHistory, GetBars, GetLastTrade, GetLastQuote } from './params'; | ||
import { Account, Order, Position, Asset, Watchlist, Calendar, Clock, AccountConfigurations, NonTradeActivity, TradeActivity, PortfolioHistory, Bar, LastQuote, LastTrade, Credentials } from './entities.js'; | ||
import { GetOrder, GetOrders, PlaceOrder, ReplaceOrder, CancelOrder, GetPosition, ClosePosition, GetAsset, GetAssets, GetWatchList, CreateWatchList, UpdateWatchList, AddToWatchList, RemoveFromWatchList, DeleteWatchList, GetCalendar, UpdateAccountConfigurations, GetAccountActivities, GetPortfolioHistory, GetBars, GetLastTrade, GetLastQuote } from './params.js'; | ||
export declare class Client { | ||
@@ -4,0 +4,0 @@ protected options: { |
/// <reference types="node" /> | ||
import { EventEmitter } from 'events'; | ||
import { Credentials } from './entities'; | ||
import { Credentials } from './entities.js'; | ||
export declare interface Stream { | ||
@@ -5,0 +5,0 @@ on<U extends keyof StreamEvents>(event: U, listener: StreamEvents[U]): this; |
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
4
3
Yes
50511
1584
- Removedhttp-method-enum@^1.0.0
- Removedhttp-method-enum@1.0.0(transitive)