torreyleonard / algotrader

Simple algorithmic stock and option trading for Node.js.
https://www.npmjs.com/package/algotrader
Apache License 2.0
637 stars 120 forks source link

auth #6

Closed trapadulli closed 5 years ago

trapadulli commented 6 years ago

has auth broken? I haven't looked into it I was just made aware all my trades are failing.

this is the error message:

node:64416) UnhandledPromiseRejectionWarning: Error:

Not Found

The requested URL /api-token-auth/ was not found on this server.

thanks

trapadulli commented 6 years ago

is this project abandoned?

trapadulli commented 6 years ago

fixed it good enough. updated authenticate:

authenticate() {

    const _this = this;
    return new Promise((resolve, reject) => {
        request.post({
            uri: _this.url + "/oauth2/token/",

            form: {
                username: _this.username,
                password: _this.password,
                client_id: 'c82SH0WZOsabOXGP2sxqcj34FxkvfnWRZBKlBjFS',
                grant_type: "password",
                scope: "internal"
            }
        }, (error, response, body) => {

            if (error) reject(error);
            else if (response.statusCode !== 200) reject(new LibraryError(body));
            else {
                _this.token = JSON.parse(body).access_token;
                //console.log(_this.url)
                _this.getAccount().then(account => {
                    //console.log(account)
                    _this.account = account.account_number;
                    _this.password = _this.password;
                    resolve(_this);
                }).catch(error => reject(error));
            }

        })
    })
}
trapadulli commented 6 years ago

...and updated header authenticate in relevant methods:

headers: { 'Authorization': 'Bearer ' + _this.token }

dakridge commented 6 years ago

Thanks! I don't think this project is updated frequently. Hey may take a few [more] weeks to merge your PR

torreyleonard commented 5 years ago

Thanks @trapadulli for providing this! Sorry for the delay in the update, but this has been updated in 1.4.0 and along with a few other features.