This repository has been archived by the owner on Nov 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 184
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add typescript support via typings file (#83)
* feat: add typescript support via typings file * fix: test and add newline in gitignore * fix: export all types and enums. remove set_mfa_code * fix: update to remove mfa reference in login
- Loading branch information
1 parent
01dd0e1
commit 344dbfb
Showing
7 changed files
with
326 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Tells the .editorconfg plugin to stop searching once it finds this file | ||
root = true | ||
|
||
[*] | ||
indent_size = 2 | ||
indent_style = space | ||
charset = utf-8 | ||
end_of_line = lf | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true | ||
|
||
[*.md] | ||
trim_trailing_whitespace = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,3 +29,5 @@ node_modules | |
.idea | ||
|
||
.nyc_output | ||
|
||
package-lock.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,254 @@ | ||
import request = require('request') | ||
|
||
declare function robinhood(options: robinhood.Options.WebApiOpts, callback: robinhood.InitCallback): robinhood.RobinhoodWebApi; | ||
|
||
declare namespace robinhood { | ||
|
||
export namespace Options { | ||
interface WebApiOpts { | ||
username?: string | ||
password?: string | ||
token?: string | ||
} | ||
|
||
interface OrdersOptions { | ||
updated_at: string | ||
instrument: string | ||
} | ||
|
||
interface EarningsOptionsWithSymbol { | ||
range?: number | ||
symbol: string | ||
} | ||
|
||
interface EarningsOptionsWithInstrument { | ||
range?: number | ||
instrument: string | ||
} | ||
|
||
interface BuySellOptions { | ||
type: OrderType | ||
quantity: number | ||
bid_price: number | ||
instrument: { | ||
url?: string | ||
symbol?: string | ||
} | ||
trigger: TriggerType | ||
time: TimeInForceType | ||
} | ||
} | ||
|
||
export type TagType = TagTypes | ||
export type OrderType = OrderTypes | ||
export type IntervalType = IntervalTypes | ||
export type SpanType = SpanTypes | ||
export type TriggerType = TriggerTypes | ||
export type TimeInForceType = TimeInForceTypes | ||
export type InitCallback = () => void | ||
|
||
export enum TagTypes { | ||
TopTen = '10-most-popular', | ||
TopOneHundred = '100-most-popular' | ||
} | ||
|
||
export enum TriggerTypes { | ||
Immediate = 'immediate', | ||
Day = 'day' | ||
} | ||
|
||
export enum TimeInForceTypes { | ||
GoodForDay = 'gfd', | ||
GoodTillCancelled = 'gtc', | ||
OrderCancelsOther = 'oco' | ||
} | ||
|
||
export enum OrderTypes { | ||
Limit = 'limit', | ||
Market = 'market' | ||
} | ||
|
||
export enum IntervalTypes { | ||
FiveMinute = '5minute', | ||
TenMinute = '10minute' | ||
} | ||
|
||
export enum SpanTypes { | ||
Week = 'week', | ||
Day = 'day' | ||
} | ||
|
||
|
||
export interface RobinhoodWebApi { | ||
/** | ||
* Revokes the current token for this session. | ||
* @param callback | ||
*/ | ||
expire_token (callback: request.RequestCallback): void | ||
|
||
/** | ||
* Returns the token for the current session. | ||
*/ | ||
auth_token (): string|null | ||
|
||
/** | ||
* Get the current user's investment profile. | ||
* @param callback | ||
*/ | ||
investment_profile (callback: request.RequestCallback): void | ||
|
||
/** | ||
* Return all instruments, or those for a given symbol. | ||
* @param callback | ||
*/ | ||
instruments(callback: request.RequestCallback): void | ||
instruments(symbol: string, callback: request.RequestCallback): void | ||
|
||
/** | ||
* Get fundamental data about a symbol. | ||
* @param symbol | ||
* @param callback | ||
*/ | ||
fundamentals (symbol: string, callback: request.RequestCallback): void | ||
|
||
/** | ||
* Get the popularity for a specified stock. | ||
* @param symbol | ||
* @param callback | ||
*/ | ||
popularity (symbol: string, callback: request.RequestCallback): void | ||
|
||
/** | ||
* Returns account information for the current user session. | ||
* @param callback | ||
*/ | ||
accounts (callback: request.RequestCallback): void | ||
|
||
/** | ||
* Get the user's quote data for a specified stock. | ||
* @param symbol | ||
* @param callback | ||
*/ | ||
quote_data (symbol: string, callback: request.RequestCallback): void | ||
quote_data (symbol: string[], callback: request.RequestCallback): void | ||
|
||
/** | ||
* Get the user's order information for the given options or specific order. | ||
* @param options | ||
* @param callback | ||
*/ | ||
orders (options: Options.OrdersOptions, callback: request.RequestCallback): void | ||
orders (orderId: string, callback: request.RequestCallback): void | ||
|
||
/** | ||
* Get the user's position information. | ||
* @param callback | ||
*/ | ||
positions (callback: request.RequestCallback): void | ||
|
||
/** | ||
* Get the user's nonzero position information only. | ||
* @param callback | ||
*/ | ||
nonzero_positions (callback: request.RequestCallback): void | ||
|
||
/** | ||
* Place a buy order on a specified stock. | ||
* @param options | ||
* @param callback | ||
*/ | ||
place_buy_order (options: Options.BuySellOptions, callback: request.RequestCallback): void | ||
|
||
/** | ||
* Place a sell order on a specified stock. | ||
* @param options | ||
* @param callback | ||
*/ | ||
place_sell_order (options: Options.BuySellOptions, callback: request.RequestCallback): void | ||
|
||
/** | ||
* Cancel an order with the order object or order ID. | ||
* @param order | ||
* @param callback | ||
*/ | ||
cancel_order (order: object, callback: request.RequestCallback): void | ||
cancel_order (orderId: string, callback: request.RequestCallback): void | ||
|
||
/** | ||
* Get historical information for the given symbol. | ||
* @param symbol | ||
* @param intv | ||
* @param span | ||
* @param callback | ||
*/ | ||
historicals (symbol: string, intv: IntervalType, span: SpanType, callback: request.RequestCallback): void | ||
|
||
/** | ||
* Get user information. | ||
* @param callback | ||
*/ | ||
user (callback: request.RequestCallback): void | ||
|
||
/** | ||
* Returns the user's watchlists | ||
* @param callback | ||
*/ | ||
watchlists (callback: request.RequestCallback): void | ||
|
||
/** | ||
* Get the earnings information using either the symbol or instrument. | ||
* @param options | ||
* @param callback | ||
*/ | ||
earnings (options: Options.EarningsOptionsWithInstrument|Options.EarningsOptionsWithSymbol, callback: request.RequestCallback): void | ||
|
||
/** | ||
* Get the user's dividends information. | ||
* @param callback | ||
*/ | ||
dividends (callback: request.RequestCallback): void | ||
|
||
/** | ||
* Fetch splits for the given instrument. | ||
* @param instrument | ||
* @param callback | ||
*/ | ||
splits (instrument: string, callback: request.RequestCallback): void | ||
|
||
/** | ||
* Returns news for a given symbol. | ||
* @param symbol | ||
* @param callback | ||
*/ | ||
news (symbol: string, callback: request.RequestCallback): void | ||
|
||
/** | ||
* Returns information for the given tag. | ||
* Retrieve Robinhood's new Tags: In 2018, Robinhood Web will expose more | ||
* Social and Informational tools. You'll see how popular a security is with | ||
* other Robinhood users, MorningStar ratings, etc. | ||
* @param tag | ||
* @param callback | ||
*/ | ||
tag (tag: TagType, callback: request.RequestCallback): void | ||
|
||
/** | ||
* Perform a GET request against the given URL. | ||
* Used to get continued or paginated data from the API. Queries with long | ||
* results return a reference to the next set. | ||
* @param url | ||
* @param callback | ||
*/ | ||
url (url: string, callback: request.RequestCallback): void | ||
|
||
/** | ||
* | ||
* @param callback | ||
*/ | ||
sp500_down (callback: request.RequestCallback): void | ||
|
||
sp500_up (callback: request.RequestCallback): void | ||
} | ||
} | ||
|
||
export = robinhood |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import * as robinhood from '../../' | ||
|
||
const username = 'robinhood-user' | ||
const password = 'robinhood-pass' | ||
const mfaCode = '12345' | ||
|
||
const onLoginSuccess = () => { | ||
console.log('Login success, auth token is: ', api.auth_token) | ||
|
||
api.positions((err, res, body) => { | ||
if (err) { | ||
console.error('error fetching positions', err) | ||
} else if (res.statusCode !== 200) { | ||
console.log(`error fetching positions. received status code ${res.statusCode}`) | ||
} else { | ||
console.log('positions are: ', body) | ||
} | ||
}) | ||
|
||
api.historicals( | ||
'APPL', | ||
robinhood.IntervalTypes.FiveMinute, | ||
robinhood.SpanTypes.Day, | ||
(err, res, body) => { | ||
if (err) { | ||
console.error('error fetching historicals', err) | ||
} else if (res.statusCode !== 200) { | ||
console.log(`error fetching historicals. received status code ${res.statusCode}`) | ||
} else { | ||
console.log('historicals are: ', body) | ||
} | ||
} | ||
) | ||
} | ||
|
||
const api = robinhood({ | ||
username, | ||
password | ||
}, onLoginSuccess) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "es6", | ||
"module": "commonjs", | ||
"noEmit": true, | ||
"strict": true, | ||
}, | ||
"files": [ | ||
"./robinhood-types.test.ts" | ||
] | ||
} |