You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- [Get a user's portfolio](#get-a-users-portfolio)
64
-
- [Placing an order](#placing-an-order)
65
-
- [Options](#options)
66
-
- [Option chains](#option-chains)
61
+
- [Saving & loading a user](#saving--loading-a-user)
62
+
- [Get a user's portfolio](#get-a-users-portfolio)
63
+
- [Placing an order](#placing-an-order)
64
+
- [Options](#options)
65
+
- [Option chains](#option-chains)
67
66
- Algorithm Library
68
67
- [Scheduler](#scheduler)
69
68
- Data Library
@@ -190,43 +189,6 @@ User.load()
190
189
191
190
However, authentication tokens issued by Robinhood expire after 24 hours. Version 1.4.5 takes this into account and [```User.isAuthenticated()```](https://github.com/Ladinn/algotrader/blob/master/docs/ROBINHOOD.md#User) will return ```false``` if the token has expired. Make sure to check for this and re-authenticate if necessary. When re-authenticating, you will need to provide a password either through CLI or when calling [```User.authenticate()```](https://github.com/Ladinn/algotrader/blob/master/docs/ROBINHOOD.md#User) as the first parameter.
192
191
193
-
194
-
##### Automatic re-authentication
195
-
196
-
You can use [```User.reauthenticate```](https://github.com/Ladinn/algotrader/blob/master/docs/ROBINHOOD.md#User) function to re-authenticate the user automatically when the authentication token is expired (after 24 hours). To do this you have to use securely saved refresh token.
197
-
198
-
You can save and restore a user data including a refresh token using [```User.serialize```](https://github.com/Ladinn/algotrader/blob/master/docs/ROBINHOOD.md#User) (right after user has been authenticated) and [```User.deserialize```](https://github.com/Ladinn/algotrader/blob/master/docs/ROBINHOOD.md#User) functions.
199
-
200
-
**Note:**[```User.safe```](https://github.com/Ladinn/algotrader/blob/master/docs/ROBINHOOD.md#User) does not save a refresh token by security reason.
201
-
202
-
```js
203
-
constauthenticatedUser; // In state right after `authenticate` called, but not after `load`.
204
-
constdata=authenticatedUser.serialize();
205
-
206
-
// Save the data in your secure storage
207
-
// superSecureStorage.save(userId, data);
208
-
```
209
-
210
-
```js
211
-
// Restore the data from your secure storage
212
-
// const data = superSecureStorage.load(userId);
213
-
214
-
User.deserialize(data)
215
-
.then(restoredUser=> {
216
-
if(!restoredUser.isAuthenticated())
217
-
restoredUser.reauthenticate()
218
-
.then(myUser=> {
219
-
// Now you can use your user
220
-
// Don't forget to save it
221
-
// superSecureStorage.save(userId, data);
222
-
}).catch(error=> {
223
-
// Make sure to always catch possible errors.
224
-
// You probably need to re-authenticate using username and password here.
225
-
});
226
-
}
227
-
);
228
-
```
229
-
230
192
#### Get a user's portfolio
231
193
There are a good amount of query functions that you can run on the user's portfolio. Using your [```User```](https://github.com/Ladinn/algotrader/blob/master/docs/ROBINHOOD.md#User) instance, you can grab the portfolio using [```User.getPortfolio```](https://github.com/Ladinn/algotrader/blob/master/docs/ROBINHOOD.md#User) which returns a new [```Portfolio```](https://github.com/Ladinn/algotrader/blob/master/docs/ROBINHOOD.md#Portfolio) object.
232
194
```js
@@ -377,53 +339,25 @@ Here is an example of how you would sort an option chain by strike price and exp
@@ -436,39 +370,28 @@ For scheduling tasks, running backtests, and paper-trading, the algorithm librar
436
370
437
371
Using the [```Scheduler```](https://github.com/Ladinn/algotrader/blob/master/docs/ALGORITHM.md#scheduler) class, you'll be able to define exactly when you want a function to run using the following methods:
438
372
439
-
-```onMarketOpen(offset)```
373
+
-```Scheduler.onMarketOpen(offset, f)```
440
374
- Runs every morning when the NYSE opens. (Typically 9:30 AM EST)
441
375
- Offset is in milliseconds and can be positive (after) or negative (before).
442
-
-```onMarketClose(offset)```
376
+
-```Scheduler.onMarketClose(offset, f)```
443
377
- Runs every afternoon when the NYSE closes. (Typically 4:00 PM EST)
444
378
- Offset is in milliseconds and can be positive (after) or negative (before).
445
-
-```every(minutes, extended)```
379
+
-```Scheduler.every(minutes, extended, f)```
446
380
- Runs every ```x``` minutes during market hours or during typical extended trading hours. (9 AM EST - 6 PM EST)
447
381
448
-
But first, you'll need to create a new instance of the Scheduler. Here's an easy example that runs a function 5 minutes before the market opens and another one every 30 minutes during regular trading hours:
382
+
Here's an easy example that runs a function 5 minutes before the market opens and another one every 30 minutes during regular trading hours:
449
383
450
384
```js
451
385
constScheduler=algotrader.Algorithm.Scheduler;
452
386
453
-
constopeningTask=newScheduler(functionrun() {
454
-
console.log("Running!");
387
+
Scheduler.onMarketOpen(-5*60000, () => {
388
+
// Function to run five minutes before the market opens
//This is optional, but returns a promise with the next invocation time
391
+
Scheduler.every(30, false, ()=> {
392
+
//Function to run every 1/2 hour
459
393
});
460
394
```
461
-
```js
462
-
constScheduler=algotrader.Algorithm.Scheduler;
463
-
464
-
consthalfHourTask=newScheduler(functionrun() {
465
-
console.log("Running!");
466
-
});
467
-
468
-
halfHourTask.every(30, false);
469
-
```
470
-
To cancel a task, just call ```cancel``` after it has been scheduled.
471
-
472
395
For documentation on all Scheduler functions, visit the [```Algorithm Library Docs.```](https://github.com/Ladinn/algotrader/blob/master/docs/ALGORITHM.md#scheduler)
0 commit comments