Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception: error.security.account-token-invalid #328

Open
NewEconomicsUK opened this issue Mar 15, 2024 · 7 comments
Open

Exception: error.security.account-token-invalid #328

NewEconomicsUK opened this issue Mar 15, 2024 · 7 comments

Comments

@NewEconomicsUK
Copy link

Greetings World!

I was testing my simple code:
buy = ig_service.create_open_position(epic='IX.D.DAX.DAILY.IP', direction='BUY') print(buy)

and the error appeared:
Exception: error.security.account-token-invalid

My requests using ig_service.fetch_open_positions() and ig_service.fetch_accounts() worked fine so I don't think the token is the problem?

Or am I wrong gentlemen?

Any guidance is much appreciated.

Kind regards

@galburn
Copy link

galburn commented Mar 15, 2024

It's working perfectly for me. Is you account Spreadbet or CFD? I'm only working with Spreadbet.

I send a lot more parameters, so perhaps you need to add some more such as size, stop_level...

Here's a snippet from my code...
```
resp = ig_service.create_open_position(
# currency_code=currency_code, # 2024-02-12
currency_code=CURRENCY_CODE,
direction = direction,
epic = epic,
expiry = expiry,
force_open = force_open,
guaranteed_stop = guaranteed_stop,
level = level,
limit_level = limit_level,
limit_distance = limit_distance,
order_type = order_type,
quote_id = quote_id,
size = size,
stop_distance = stop_distance,
stop_level = stop_level,
trailing_stop = trailing_stop, # Needed?
trailing_stop_increment = trailing_stop_increment, # Needed?
session=None,
)

@NewEconomicsUK
Copy link
Author

Thank you for your reply @galburn

I've try the following code and it works

resp = ig_service.create_open_position(
currency_code='GBP',
direction='BUY',
epic='IX.D.DAX.DAILY.IP',
order_type='MARKET',
expiry='DFB', #DFB in original
force_open='false',
guaranteed_stop='false',
size=0.5, level=None,
limit_distance=None,
limit_level=None,
quote_id=None,
stop_level=None,
stop_distance=None,
trailing_stop=None,
trailing_stop_increment=None)
resp
print(resp)

But it looks like if I change it to 'SELL', the error comes back again?

@galburn
Copy link

galburn commented Mar 18, 2024

I'll repeat my question. Is you account Spreadbet or CFD?

This looks to be a code or account issue, not a bug in the library. Please provide a complete minimal example that demonstrates the issue.

@NewEconomicsUK
Copy link
Author

The account I'm testing on is Spreadbet. It works fine if I space out the requests for at least 1 minute. Is that normal?

This is one of the codes

# resp = ig_service.create_open_position(
#     currency_code='GBP',
#     direction='SELL',
#     epic='IX.D.DAX.DAILY.IP',
#     order_type='MARKET',
#     expiry='DFB', #- does not work
#     force_open='false',
#     guaranteed_stop='false',
#     size=0.5, level=None,
#     limit_distance=None,
#     limit_level=None,
#     quote_id=None,
#     stop_level=None,
#     stop_distance=None,
#     trailing_stop=None,
#     trailing_stop_increment=None)
# resp
# print(resp)

@galburn
Copy link

galburn commented Mar 18, 2024

Well that code runs perfectly without error for me! Even if I remove all the hashes.

If you need further help, please take a look here...
here

It may well be that your library imports or versions are causing a problem. Or there is some other code mistake. This is why we insist upon a complete minimal example.

@NewEconomicsUK
Copy link
Author

It works fine on the first request but the second one showed the error until I waited a minute, and it worked fine again.

Does that mean there's a limit to how many requests we can put within a 1 minute period?

Many thanks

@galburn
Copy link

galburn commented Mar 18, 2024

There are API limits, but you should not be hitting them with one request per minute. I have no trouble sending one immediately after another.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants