robinhood-typescript
Advanced tools
Comparing version 1.4.0 to 1.5.0
@@ -5,2 +5,3 @@ import { AccountsLoaded } from './models/account'; | ||
import { PositionsLoaded } from './models/positions'; | ||
import { DividendsLoaded } from './models/dividends'; | ||
declare class RobinhoodAPI { | ||
@@ -16,3 +17,4 @@ private _authToken; | ||
positions(): Promise<PositionsLoaded>; | ||
dividends(): Promise<DividendsLoaded>; | ||
} | ||
export default RobinhoodAPI; |
@@ -92,3 +92,16 @@ "use strict"; | ||
} | ||
// This should pull info on a user's Dividends. | ||
async dividends() { | ||
const config = { | ||
headers: { Authorization: `Bearer ${this._authToken}` }, | ||
}; | ||
try { | ||
const response = await axios_1.default.get(`${defaults_1.apiUrl}${defaults_1.endpoints.dividends}`, config); | ||
return response.data; | ||
} | ||
catch (error) { | ||
return error; | ||
} | ||
} | ||
} | ||
exports.default = RobinhoodAPI; |
{ | ||
"name": "robinhood-typescript", | ||
"version": "1.4.0", | ||
"version": "1.5.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", |
@@ -241,1 +241,44 @@ import RobinhoodAPI from '../index'; | ||
}); | ||
describe('Dividends', () => { | ||
test('successfully retrieved dividend info', async () => { | ||
const api = new RobinhoodAPI('token'); | ||
const data = { | ||
results: [ | ||
{ | ||
id: 'a3235dd8-ddaf-5b73-98c4-369dfd390202', | ||
url: 'https://api.robinhood.com/dividends/a3235dd8-ddaf-5b73-98c4-369dfd390202/', | ||
account: 'https://api.robinhood.com/accounts/598754190/', | ||
instrument: 'https://api.robinhood.com/instruments/6df56bd0-0bf2-44ab-8875-f94fd8526942/', | ||
amount: '0.30', | ||
rate: '0.1500000000', | ||
position: '2.00000000', | ||
withholding: '0.00', | ||
record_date: '2020-01-30', | ||
payable_date: '2020-03-02', | ||
paid_at: '2020-03-03T05:28:42Z', | ||
state: 'paid', | ||
nra_withholding: '0', | ||
drip_enabled: false, | ||
}, | ||
], | ||
}; | ||
mockedAxios.get.mockResolvedValue({ data }); | ||
const dividendsInfo = await api.dividends(); | ||
expect(dividendsInfo).toEqual(data); | ||
}); | ||
test('failure to retrieve dividends', async () => { | ||
const api = new RobinhoodAPI('token'); | ||
const errorMessage = 'unable to retrieve dividends'; | ||
mockedAxios.get.mockRejectedValue({ errorMessage }); | ||
const dividendsInfo = await api.dividends(); | ||
expect(dividendsInfo).toEqual({ errorMessage }); | ||
}); | ||
}); |
@@ -6,2 +6,3 @@ import { apiUrl, endpoints } from './models/defaults'; | ||
import { PositionsLoaded } from './models/positions'; | ||
import { DividendsLoaded } from './models/dividends'; | ||
@@ -109,4 +110,19 @@ // Dependencies | ||
} | ||
// This should pull info on a user's Dividends. | ||
async dividends(): Promise<DividendsLoaded> { | ||
const config = { | ||
headers: { Authorization: `Bearer ${this._authToken}` }, | ||
}; | ||
try { | ||
const response: AxiosResponse<DividendsLoaded> = await axios.get(`${apiUrl}${endpoints.dividends}`, config); | ||
return response.data; | ||
} catch (error) { | ||
return error; | ||
} | ||
} | ||
} | ||
export default RobinhoodAPI; |
Sorry, the diff of this file is too big to display
554676
35
14129