robinhood-typescript
Advanced tools
Comparing version 1.7.0 to 1.8.0
@@ -9,2 +9,3 @@ import { AccountsLoaded } from './models/account'; | ||
import { MarketsLoaded } from './models/markets'; | ||
import { QuotesLoaded } from './models/quotes'; | ||
declare class RobinhoodAPI { | ||
@@ -24,3 +25,4 @@ private _authToken; | ||
markets(): Promise<MarketsLoaded>; | ||
quotes(symbol: string): Promise<QuotesLoaded>; | ||
} | ||
export default RobinhoodAPI; |
@@ -150,3 +150,16 @@ "use strict"; | ||
} | ||
// This loads data on quotes. | ||
async quotes(symbol) { | ||
const config = { | ||
headers: { Authorization: `Bearer ${this._authToken}` }, | ||
}; | ||
try { | ||
const response = await axios_1.default.get(`${defaults_1.apiUrl}${defaults_1.endpoints.quotes}${symbol}/`, config); | ||
return response.data; | ||
} | ||
catch (error) { | ||
return error; | ||
} | ||
} | ||
} | ||
exports.default = RobinhoodAPI; |
{ | ||
"name": "robinhood-typescript", | ||
"version": "1.7.0", | ||
"version": "1.8.0", | ||
"description": "NodeJS Framework to make trades with the private Robinhood API. Using this API is not encouraged, since it's not officially available and it has been reverse engineered. See @Sanko's Unofficial Documentation for more information.", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -434,1 +434,41 @@ import RobinhoodAPI from '../index'; | ||
}); | ||
describe('Quotes', () => { | ||
test('successfully retrieved quote', async () => { | ||
const api = new RobinhoodAPI('token'); | ||
const data = { | ||
ask_price: '7.260000', | ||
ask_size: 499, | ||
bid_price: '6.660000', | ||
bid_size: 300, | ||
last_trade_price: '7.230000', | ||
last_extended_hours_trade_price: '7.250000', | ||
previous_close: '6.900000', | ||
adjusted_previous_close: '6.900000', | ||
previous_close_date: '2020-06-26', | ||
symbol: 'NIO', | ||
trading_halted: false, | ||
has_traded: true, | ||
last_trade_price_source: 'consolidated', | ||
updated_at: '2020-06-30T00:00:00Z', | ||
instrument: 'https://api.robinhood.com/instruments/9f1399e5-5023-425a-9eb5-cd3f91560189/', | ||
}; | ||
mockedAxios.get.mockResolvedValue({ data }); | ||
const quotesInfo = await api.quotes('NIO'); | ||
expect(quotesInfo).toEqual(data); | ||
}); | ||
test('failure to retrieve quotes info', async () => { | ||
const api = new RobinhoodAPI('token'); | ||
const errorMessage = 'unable to retrieve quotes'; | ||
mockedAxios.get.mockRejectedValue({ errorMessage }); | ||
const quotesInfo = await api.quotes('NIO'); | ||
expect(quotesInfo).toEqual({ errorMessage }); | ||
}); | ||
}); |
@@ -10,2 +10,3 @@ import { apiUrl, endpoints } from './models/defaults'; | ||
import { MarketsLoaded } from './models/markets'; | ||
import { QuotesLoaded } from './models/quotes'; | ||
@@ -186,4 +187,19 @@ // Dependencies | ||
} | ||
// This loads data on quotes. | ||
async quotes(symbol: string): Promise<QuotesLoaded> { | ||
const config = { | ||
headers: { Authorization: `Bearer ${this._authToken}` }, | ||
}; | ||
try { | ||
const response: AxiosResponse<QuotesLoaded> = await axios.get(`${apiUrl}${endpoints.quotes}${symbol}/`, config); | ||
return response.data; | ||
} catch (error) { | ||
return error; | ||
} | ||
} | ||
} | ||
export default RobinhoodAPI; |
export interface FundamentalsLoaded { | ||
results: Results[]; | ||
} | ||
interface Results { | ||
open: string; | ||
high: string; | ||
low: string; | ||
volume: string; | ||
average_volume_2_weeks: string; | ||
average_volume: string; | ||
high_52_weeks: string; | ||
dividend_yield: null | string; | ||
float: string; | ||
low_52_weeks: string; | ||
market_cap: string; | ||
pb_ratio: string; | ||
pe_ratio: null | string; | ||
shares_outstanding: string; | ||
description: string; | ||
instrument: string; | ||
ceo: string; | ||
headquarters_city: string; | ||
headquarters_state: string; | ||
sector: string; | ||
industry: string; | ||
num_employees: number; | ||
year_founded: number; | ||
} | ||
results: Results[]; | ||
} | ||
interface Results { | ||
open: string; | ||
high: string; | ||
low: string; | ||
volume: string; | ||
average_volume_2_weeks: string; | ||
average_volume: string; | ||
high_52_weeks: string; | ||
dividend_yield: null | string; | ||
float: string; | ||
low_52_weeks: string; | ||
market_cap: string; | ||
pb_ratio: string; | ||
pe_ratio: null | string; | ||
shares_outstanding: string; | ||
description: string; | ||
instrument: string; | ||
ceo: string; | ||
headquarters_city: string; | ||
headquarters_state: string; | ||
sector: string; | ||
industry: string; | ||
num_employees: number; | ||
year_founded: number; | ||
} |
Sorry, the diff of this file is too big to display
570061
47
14618