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

Invalid signature when creating orders in negative risk market #79

Open
dmitry-dzyuba-uinno opened this issue Jun 4, 2024 · 13 comments

Comments

@dmitry-dzyuba-uinno
Copy link

Overview

When trying to create an order in negative risk market, it gives me an error "invalid signature", creating orders for non-negative risk markets works fine.

Code sample

#...
resp = client.create_and_post_order(OrderArgs(
    price=0.01,
    size=5.0,
    side=BUY,
    token_id="23879627426961662812922169694268707374662971136118079896087093103802667054172"
))

Response

Traceback (most recent call last):
  File "/var/www/html/scripts/py-clob-client/create_and_post_order.py", line 32, in <module>
    resp = client.create_and_post_order(OrderArgs(
  File "/var/www/html/scripts/py-clob-client/py_clob_client/client.py", line 314, in create_and_post_order
    return self.post_order(ord)
  File "/var/www/html/scripts/py-clob-client/py_clob_client/client.py", line 305, in post_order
    return post("{}{}".format(self.host, POST_ORDER), headers=headers, data=body)
  File "/var/www/html/scripts/py-clob-client/py_clob_client/http_helpers/helpers.py", line 48, in post
    return request(endpoint, POST, headers, data)
  File "/var/www/html/scripts/py-clob-client/py_clob_client/http_helpers/helpers.py", line 41, in request
    raise PolyApiException(resp)
py_clob_client.exceptions.PolyApiException: PolyApiException[status_code=400, error_message={'error': 'invalid signature'}]

I was initially using version v0.11.0, but it's same on v0.16.0

@zlandme
Copy link

zlandme commented Aug 4, 2024

I had the same question, how can I resolve this question?

@dmitry-dzyuba-uinno
Copy link
Author

@zlandme I actually figured this out, the official example doesn't include this, but in recent versions you need to actually pass a parameter to the function if it's negative risk market or not. Here is an example:

ord = client.create_order(OrderArgs(
    price=args.price,
    size=args.size,
    side=args.side,
    token_id=args.token_id,
    expiration=args.expiration
), PartialCreateOrderOptions(
    neg_risk=args.neg_risk
))

resp = client.post_order(ord, order_type)

@zlandme
Copy link

zlandme commented Aug 5, 2024

@zlandme I actually figured this out, the official example doesn't include this, but in recent versions you need to actually pass a parameter to the function if it's negative risk market or not. Here is an example:

ord = client.create_order(OrderArgs(
    price=args.price,
    size=args.size,
    side=args.side,
    token_id=args.token_id,
    expiration=args.expiration
), PartialCreateOrderOptions(
    neg_risk=args.neg_risk
))

resp = client.post_order(ord, order_type)

@dmitry-dzyuba-uinno YEAH, you are right, It solved the problem of wrong signature, but I got a new problem, when I create_and_post order, it give me error "PolyApiException[status_code=400, error_message={'error': 'not enough balance / allowance'}]", I have done the approve, and there are funds in my account, and I can get the fund with my address in the collateral contract address. how can I resolve this question?

@vince-gt
Copy link

I'm having the same problem:
py_clob_client.exceptions.PolyApiException: PolyApiException[status_code=400, error_message={'error': 'invalid signature'}]
Tried with Python 3.12.3 then tried Python 3.9.10. negRisk true or false does not matter. Using the py-clob-client v0.17.5.
Tried rolling back a few versions with:
pip install --force-reinstall -v "py-clob-client==0.xx.x"
No luck.
@dmitry-dzyuba-uinno How did you resolve the invalid signature problem?

@vince-gt
Copy link

@zlandme I actually figured this out, the official example doesn't include this, but in recent versions you need to actually pass a parameter to the function if it's negative risk market or not. Here is an example:

ord = client.create_order(OrderArgs(
    price=args.price,
    size=args.size,
    side=args.side,
    token_id=args.token_id,
    expiration=args.expiration
), PartialCreateOrderOptions(
    neg_risk=args.neg_risk
))

resp = client.post_order(ord, order_type)

@dmitry-dzyuba-uinno YEAH, you are right, It solved the problem of wrong signature, but I got a new problem, when I create_and_post order, it give me error "PolyApiException[status_code=400, error_message={'error': 'not enough balance / allowance'}]", I have done the approve, and there are funds in my account, and I can get the fund with my address in the collateral contract address. how can I resolve this question?

Have you tried setting the token allowances as described in the read me? This script fixed it for me. I had to make some changes to get it to run though.
getTransactionCount -> get_transaction_count
buildTransaction -> build_transaction
rawTransaction -> raw_transaction

@vince-gt
Copy link

Got this working with help from Isulls50 on Discord.
"as a Python moron like countless above, it should be pinned that 'funder=' should be the browser Polymarket Wallet address in the top right under your profile name, NOT YOUR METAMASK! This was the solution to 'invalid signature' for me and i would bet thousands that it's what other people are messing up too"
https://discord.com/channels/710897173927297116/782024576275447848/1267323493209342073

@ben0x01
Copy link

ben0x01 commented Aug 31, 2024

Who solve the problem with - "py_clob_client.exceptions.PolyApiException: PolyApiException[status_code=400, error_message={'error': 'not enough balance / allowance'}]"?

I try to sell my positions but gett error

@hsz0403
Copy link

hsz0403 commented Oct 20, 2024

same as ben0x01

@ben0x01
Copy link

ben0x01 commented Oct 21, 2024

Bro, sometimes the library is stupid :D
Wait and restart use your script. I really cannot to understand why it's help, but it work)

But maybe u don't have approve. Check it and if u will have problem, give any time and restart!

@theo-wq
Copy link

theo-wq commented Oct 22, 2024

hi i have the same probleme but how do you import the "PartialCreateOrderOptions" Thanks a lot

@vince-gt
Copy link

You will likely get a quicker response on Discord https://discord.com/channels/710897173927297116/782024576275447848

@gaurav-gupta
Copy link

@zlandme I actually figured this out, the official example doesn't include this, but in recent versions you need to actually pass a parameter to the function if it's negative risk market or not. Here is an example:

ord = client.create_order(OrderArgs(
    price=args.price,
    size=args.size,
    side=args.side,
    token_id=args.token_id,
    expiration=args.expiration
), PartialCreateOrderOptions(
    neg_risk=args.neg_risk
))

resp = client.post_order(ord, order_type)

I used this PartialCreateOrderOptions but i am still getting the same invalid signature error. I am trying on Amoy(Polygon Testnet). I am using following Code:

chain_id=80002
host = "https://clob.polymarket.com/"
client = ClobClient(host, key=key, chain_id=chain_id, creds=creds)

order_args = OrderArgs(
price=0.61,
size=20.0,
side=BUY,
token_id="78822899299915307362556468638952770457130673485124805089798216644749639353797",
)
signed_order = client.create_order(order_args, PartialCreateOrderOptions(
neg_risk=True
))
print(signed_order)

GTC Order

resp = client.post_order(signed_order, OrderType.GTC)
print(resp)

@lucashhan
Copy link

@gaurav-gupta ,Yes I also met this problem after adding the PartialCreateOrderOptions

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

8 participants