|
1 | 1 | # Tradier Client |
2 | | -Node Tradier Brokerage Client |
| 2 | +Node.js Tradier Brokerage API written in typescript. |
| 3 | + |
| 4 | +Current Functionality |
| 5 | + * Market Data |
| 6 | + * Fundamentals (Beta use at own risk) |
| 7 | + |
| 8 | +Future Planned Functionality |
| 9 | + * Stream Endpoint |
| 10 | + * OAuth Authentication |
| 11 | + * Account |
| 12 | + * Trading |
| 13 | + * Watchlist |
| 14 | + |
| 15 | +### Tradier |
| 16 | +Brokerage Reinvented. |
| 17 | + |
| 18 | +Tradier is a REST-based, open, and secure API for investors, advisors, and traders. |
| 19 | + |
| 20 | +[Tradier Documentation](https://documentation.tradier.com/) |
| 21 | + |
| 22 | +#### Access Token |
| 23 | +You will receive your Tradier API Access Token after you create an account. |
| 24 | + |
| 25 | +Depending on what type of account you create will determine the type of access token you will receive. |
| 26 | + * [Sandbox](https://developer.tradier.com/user/sign_up) |
| 27 | + * [Brokerage](https://brokerage.tradier.com/signup) |
| 28 | + |
| 29 | + Note: Sandbox does not work with every endpoint and may contain delayed information. |
| 30 | + |
| 31 | +## Installation |
| 32 | +``` |
| 33 | +npm i --save @reycodev/tradier-client |
| 34 | +``` |
| 35 | + |
| 36 | +## Usage |
| 37 | +Initialize the client. |
| 38 | +```Typescript |
| 39 | +import { TradierAccountType, TradierClient, TradierClientOptions } from '@reycodev/tradier-client'; |
| 40 | + |
| 41 | +const options: TradierClientOptions = { |
| 42 | + accessToken: '##########' // Token receieved after creating tradier account |
| 43 | + accountType: TradierAccountType.SANDBOX // Depends on type of account created. |
| 44 | +} |
| 45 | + |
| 46 | +const tradier: TradierClient = new TradierClient(options); |
| 47 | + |
| 48 | +``` |
| 49 | +#### Market |
| 50 | +Implemented Endpoints: |
| 51 | + * [Get Quotes](https://documentation.tradier.com/brokerage-api/markets/get-quotes) |
| 52 | + * [Get Option Chains](https://documentation.tradier.com/brokerage-api/markets/get-options-chains) |
| 53 | + * [Get Option Strikes](https://documentation.tradier.com/brokerage-api/markets/get-options-strikes) |
| 54 | + * [Get Option Expirations](https://documentation.tradier.com/brokerage-api/markets/get-options-expirations) |
| 55 | + * [Get Historical Quotes](https://documentation.tradier.com/brokerage-api/markets/get-history) |
| 56 | + * [Get Time and Sales](https://documentation.tradier.com/brokerage-api/markets/get-timesales) |
| 57 | + * [Get ETB Securities](https://documentation.tradier.com/brokerage-api/markets/get-etb) |
| 58 | + * [Get Clock](https://documentation.tradier.com/brokerage-api/markets/get-clock) |
| 59 | + * [Get Calendar](https://documentation.tradier.com/brokerage-api/markets/get-calendar) |
| 60 | + * [Get Companies](https://documentation.tradier.com/brokerage-api/markets/get-search) |
| 61 | + * [Get Lookup Symbol](https://documentation.tradier.com/brokerage-api/markets/get-lookup) |
| 62 | + |
| 63 | +Examples: |
| 64 | +```Typescript |
| 65 | +// Get Quotes |
| 66 | +tradier.market.getQuotes(['spy', 'amd']) |
| 67 | + .then((response) => console.log('response', response)) |
| 68 | + .catch((error) => console.error(error)); |
| 69 | +// Get Option Questions |
| 70 | +tradier.market.getOptionChains('spy', '2019-05-17') |
| 71 | + .then((response) => console.log('response', response)) |
| 72 | + .catch((error) => console.error(error)); |
| 73 | +``` |
| 74 | + |
| 75 | +#### Fundamentals |
| 76 | +Implemented Endpoints: |
| 77 | + * [Get Company](https://documentation.tradier.com/brokerage-api/markets/fundamentals/get-company) |
| 78 | + * [Get Corporate Calendars](https://documentation.tradier.com/brokerage-api/markets/fundamentals/get-calendars) |
| 79 | + * [Get Dividends](https://documentation.tradier.com/brokerage-api/markets/fundamentals/get-dividends) |
| 80 | + * [Get Corporate Actions](https://documentation.tradier.com/brokerage-api/markets/fundamentals/get-corporate-actions) |
| 81 | + * [Get Rations](https://documentation.tradier.com/brokerage-api/markets/fundamentals/get-ratios) |
| 82 | + * [Get Financial Reports](https://documentation.tradier.com/brokerage-api/markets/fundamentals/get-financials) |
| 83 | + * [Get Price Statistics](https://documentation.tradier.com/brokerage-api/markets/fundamentals/get-statistics) |
| 84 | + |
| 85 | +Examples: |
| 86 | +```Typescript |
| 87 | +// Get Company Information |
| 88 | +tradier.fundamentals.getCompany(['spy', 'amd']) |
| 89 | + .then((response) => console.log('response', response)) |
| 90 | + .catch((error) => console.error(error)); |
| 91 | + // Get Corporate Calendars |
| 92 | +tradier.fundamentals.getCorporateCalendars(['spy', 'amd']) |
| 93 | + .then((response) => console.log('response', response)) |
| 94 | + .catch((error) => console.error(error)); |
| 95 | +``` |
| 96 | + |
| 97 | +## Development |
| 98 | +Decisions: |
| 99 | + * Trying to follow Inversion of Control with Dependency Injection (Needs some more refactoring) |
| 100 | + * Went with promises but thought about observables (rxjs) but didn't want to have that dependency. |
| 101 | + * Observables seem like a viable option because it could help with real time updates. |
| 102 | + |
| 103 | +Improvements: |
| 104 | + * Add Linting |
| 105 | + * Add Unit Tests |
| 106 | + * Add Typings for responses |
| 107 | + * Add more endpoints for tradier |
| 108 | + * Add bundling process to allow for use on different environments such as browser. |
| 109 | + |
| 110 | +## Miscellaneous |
| 111 | +#### NestJs |
| 112 | +Planned on creating a Nestjs library using this package. |
| 113 | +In the mean time, you can follow this to create your own. |
| 114 | + |
| 115 | +tradier.service.ts |
| 116 | +```Typescript |
| 117 | +import { Injectable } from '@nestjs/common'; |
| 118 | +import { TradierClient } from '@reycodev/tradier-client'; |
| 119 | + |
| 120 | +@Injectable() |
| 121 | +export class TradierService extends TradierClient {} |
| 122 | + |
| 123 | +``` |
| 124 | + |
| 125 | +tradier.module.ts |
| 126 | +```Typescript |
| 127 | +import { Module, Provider } from '@nestjs/common'; |
| 128 | +import { TradierClient, TradierAccountType, TradierClientOptions } from '@reycodev/tradier-client'; |
| 129 | + |
| 130 | +import { TradierService } from './services'; |
| 131 | + |
| 132 | +// Recomend not commiting access token |
| 133 | +const tradierToken: string = '######' |
| 134 | + |
| 135 | +// Probably should be its own file. |
| 136 | +const tradierServiceFactory: Provider = { |
| 137 | + provide: TradierService, |
| 138 | + useFactory: () => { |
| 139 | + return new TradierClient({ |
| 140 | + accessToken: tradierToken, |
| 141 | + accountType: TradierAccountType.SANDBOX, |
| 142 | + }); |
| 143 | + } |
| 144 | +} |
| 145 | + |
| 146 | +@Module({ |
| 147 | + imports: [], |
| 148 | + providers: [ |
| 149 | + tradierServiceFactory, |
| 150 | + ], |
| 151 | + exports: [ |
| 152 | + TradierService, |
| 153 | + ], |
| 154 | +}) |
| 155 | +export class TradierModule {} |
| 156 | + |
| 157 | +``` |
0 commit comments