nathanramoscfa / etradebot

Tools for automated trading on E-Trade
https://etradebot.readthedocs.io/en/latest/index.html
MIT License
12 stars 6 forks source link

invalid decimal literal #20

Closed jpg0203 closed 9 months ago

jpg0203 commented 9 months ago

I'm encountering a SyntaxError: invalid decimal literal error and could use some assistance in understanding and resolving the issue. The error arises from a call to ast.literal_eval() with the string "(e trade cookie )". While investigating, I'm unsure why Python is attempting to interpret this string as a decimal literal. If you could provide any insights or suggestions on how to address this problem, I'd greatly appreciate it. i may just be being dumb here but i cant seem to figure this out.

here is the log im getting

from utils.list_accounts import get_account_list Traceback (most recent call last): File "", line 1, in File "/home/jpg02/etradebot/utils/list_accounts.py", line 13, in etrade_cookie = ast.literal_eval(keyring.get_password("etrade", "etrade_cookie")) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/jpg02/anaconda3/envs/etradebot/lib/python3.11/ast.py", line 62, in literal_eval node_or_string = parse(node_or_string.lstrip(" \t"), mode='eval') ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/jpg02/anaconda3/envs/etradebot/lib/python3.11/ast.py", line 50, in parse return compile(source, filename, mode, flags, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "", line 1 "(cookie)" ^ SyntaxError: invalid decimal literal

thank you

nathanramoscfa commented 9 months ago

If you received a valid cookie from E-Trade customer service, it should look something like this:

{'name': 'SWH', 'value': 'GRDKRORF5-he5abv74-25oj', 'domain': '.etrade.com', 'secure': True, 'httpOnly': True}

You would then use keyring to store locally on your computer:

import keyring
keyring.set_password("etrade", "etrade_cookie", "{'name': 'SWH', 'value': 'GRDKRORF5-he5abv74-25oj', 'domain': '.etrade.com', 'secure': True, 'httpOnly': True}"

keyring can only saves your cookie as a string, but the cookie is given to you in the form a dictionary, like this -> {key, value} -> so you must save it to keyring wrapped with quotation marks like the example above. Try that out to see if fixes your error.

jpg0203 commented 9 months ago

If you received a valid cookie from E-Trade customer service, it should look something like this:

{'name': 'SWH', 'value': 'GRDKRORF5-he5abv74-25oj', 'domain': '.etrade.com', 'secure': True, 'httpOnly': True}

You would then use keyring to store locally on your computer:

import keyring
keyring.set_password("etrade", "etrade_cookie", "{'name': 'SWH', 'value': 'GRDKRORF5-he5abv74-25oj', 'domain': '.etrade.com', 'secure': True, 'httpOnly': True}"

keyring can only saves your cookie as a string, but the cookie is given to you in the form a dictionary, like this -> {key, value} -> so you must save it to keyring wrapped with quotation marks like the example above. Try that out to see if fixes your error.

im getting a new error now all keyrings are in correctly

Traceback (most recent call last): File "", line 1, in File "/home/jpg02/etradebot/utils/list_accounts.py", line 16, in etrade = ETrade(consumer_key, consumer_secret, web_username, web_password, account_id, etrade_cookie) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/jpg02/etradebot/etrade/etrade.py", line 46, in init self.accounts, self.orders, self.market = self.auth.etrade_login() ^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/jpg02/etradebot/authentication/authentication.py", line 162, in etrade_login accounts, orders, market = self.access_api() ^^^^^^^^^^^^^^^^^ File "/home/jpg02/etradebot/authentication/authentication.py", line 144, in access_api verifier_code = oauth.get_verification_code(self.headless) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/jpg02/anaconda3/envs/etradebot/lib/python3.11/site-packages/pyetrade/authorization.py", line 98, in get_verification_code formated_auth_url = self.get_request_token() ^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/jpg02/anaconda3/envs/etradebot/lib/python3.11/site-packages/pyetrade/authorization.py", line 72, in get_request_token self.session.fetch_request_token(self.req_token_url) File "/home/jpg02/anaconda3/envs/etradebot/lib/python3.11/site-packages/requests_oauthlib/oauth1_session.py", line 287, in fetch_request_token token = self._fetch_token(url, **request_kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/jpg02/anaconda3/envs/etradebot/lib/python3.11/site-packages/requests_oauthlib/oauth1_session.py", line 369, in _fetch_token raise TokenRequestDenied(error % (r.status_code, r.text), r) requests_oauthlib.oauth1_session.TokenRequestDenied: Token request failed with code 400, response was '<!doctype html>HTTP Status 400 – Bad Request

HTTP Status 400 – Bad Request


Type Status Report

Message oauth_problem=timestamp_refused,oauth_acceptable_timestamps=1708624656-1708628256

Description The server cannot or will not process the request due to something that is perceived to be a client error (e.g., malformed request syntax, invalid request message framing, or deceptive request routing).


'.

nathanramoscfa commented 9 months ago

E-Trade added two-factor authentication by phone to the login process. This is causing the automatic login feature of ETradeBot to break. I have since deprecated the ETradeBot project, as, even if I found a workaround, E-Trade would likely just change something else within a few weeks. This has been the pattern. I have decided to work on other trading bots for platforms that are much more friendlier to developers of algorithmic trading programs such as Alpaca.

I appreciate your interest, and please follow me on GitHub so you are the first to know when I've released my next trading bot program.