dydxprotocol / dydx-v3-python

Python client for dYdX (API v3)
Apache License 2.0
307 stars 174 forks source link

dydx3.errors.DydxApiError: DydxApiError(status_code=400, response={'errors': [{'msg': 'Invalid signature for order'}]}) #140

Open oeawFebe opened 2 years ago

oeawFebe commented 2 years ago

I have checked #75 and #96 . I think I have covered all the suggestions there. Still I get the error.

Could you help? Million thanks.

(Edited) My command to run geth might be wrong=> /path/to/geth --http --syncmode light --ws.origins="*"

import time

from dydx3 import Client
from dydx3.constants import API_HOST_MAINNET
from dydx3.constants import MARKET_ETH_USD
from dydx3.constants import API_HOST_MAINNET
from dydx3.constants import NETWORK_ID_MAINNET
from dydx3.constants import ORDER_SIDE_BUY
from dydx3.constants import ORDER_STATUS_OPEN
from dydx3.constants import ORDER_TYPE_LIMIT
from web3 import Web3

ETHEREUM_ADDRESS = '0xxxxxxx'

WEB3_PROVIDER_URL = 'http://localhost:xxxx' # I am running geth (/path/to/geth --http --syncmode light --ws.origins="*")
client = Client(
    network_id=NETWORK_ID_MAINNET,
    host=API_HOST_MAINNET,
    default_ethereum_address=ETHEREUM_ADDRESS,

    web3=Web3(Web3.HTTPProvider(WEB3_PROVIDER_URL)),
    eth_private_key='xxxxx',
    stark_private_key="0x0xxxxxx",
    api_key_credentials={"walletAddress": "0xxxxxxx", "secret": "xxxxx",
                         "key": "xxxxx", "passphrase": "xxxx", "legacySigning": False, "walletType": "METAMASK"}, # I got it from chrome developer mode. I have signed the transaction to approve dydx but have no funds in mainnet yet.
)

client.stark_private_key = "0xxxxxx"
client.stark_public_key = "0xxxxxx"

account_response = client.private.get_account(
    ethereum_address=ETHEREUM_ADDRESS,
)
position_id = account_response.data['account']['positionId']
order_params = {
    'position_id': position_id,
    'market': MARKET_ETH_USD,
    'side': ORDER_SIDE_BUY,
    'order_type': ORDER_TYPE_LIMIT,
    'post_only': True,
    'size': '0.01',
    'price': '20',
    'limit_fee': '0.0015',
    'expiration_epoch_seconds': time.time() + 65,
}
order_response = client.private.create_order(**order_params)

order_id = order_response['order']['id']
oeawFebe commented 2 years ago

Hi @oeawFebe if the error is metamask related. I will suggest you contact metamask support and click on the live chat message logo to talk with a Developer from metamask through their live chat Developers forum to help you sort this issue out right away. Click on the —> https://metamaskzendesk.helpsconnect.live/#

Thanks, it may be Metamask related because when I try to deposit funds via Metamask, dYdX site says "Your account is out of sync. Please reconnect your wallet and try again." I have contacted the support but has not got reply from any representatives.

However, I somehow feels it is due to my code (I suspect there are some bugs there, which I cannot find). Or maybe it is the command to run geth, which might be the cause (/path/to/geth --http --syncmode light --ws.origins="*").

oeawFebe commented 2 years ago

I let my metamask use my local node but the problem still persists. Why?

KittenCN commented 2 years ago

I have the same problem. My code and account has not been modified. Last month, they worked well, but today it does not work, and notice me "Invalid signature for order"

SC4RECOIN commented 2 years ago

Having a similar issue. Running a script to withdrawal that is giving me an error. Go on the web app and try to deposit and get an error "Your account is out of sync. Please reconnect your wallet and try again." Assuming the errors are related.

akipponn commented 2 years ago

I have the same issue as oeawFebe mentioned on top of this thread. (Differences are: I use Infura for a node, I generated Stark key with "client.onboarding.derive_stark_key()" method)

API key works and I could get position id and orders while signing with stark private key fails. I ran the following code:

import time
from dydx3 import Client
from dydx3.constants import API_HOST_MAINNET
from dydx3.constants import NETWORK_ID_MAINNET
from web3 import Web3
from dydx3.constants import MARKET_BTC_USD
from dydx3.constants import ORDER_SIDE_BUY
from dydx3.constants import ORDER_STATUS_OPEN
from dydx3.constants import ORDER_TYPE_LIMIT

WEB_PROVIDER_URL = "https://mainnet.infura.io/v3/..."
eth_address = "..."
eth_private_key = (
    "...""
)

client = Client(
    network_id=NETWORK_ID_MAINNET,
    host=API_HOST_MAINNET,
    default_ethereum_address=eth_address,
    eth_private_key=eth_private_key,
    web3=Web3(Web3.HTTPProvider(WEB_PROVIDER_URL)),
)

stark_key = client.onboarding.derive_stark_key()
api_key = client.onboarding.recover_default_api_key_credentials(eth_address)
print(f"stark key: {stark_key}")
print(f"api key: {api_key}")

client.api_key_credentials = api_key
client.stark_private_key = stark_key['private_key']

account_response = client.private.get_account()
position_id = account_response.data['account']['positionId']

print(position_id)

order_response=client.private.create_order(
  position_id=position_id,
  market=MARKET_BTC_USD,
  side=ORDER_SIDE_BUY,
  order_type=ORDER_TYPE_LIMIT,
  post_only=True,
  size='0.001',
  price='15000',
  limit_fee='0.0015',
  expiration_epoch_seconds=time.time() + 100,
)                                              

print(order_response.data)
akipponn commented 2 years ago

An update. As I made a comment on #150 , I could sign my transaction with other account with the same code just by changing Ethereum address and private key ...

imcda commented 1 year ago
DydxApiError: DydxApiError(status_code=400, response={'errors': [{'msg': 'Invalid signature for order'}]})

same problem. any solution?

shah-smit commented 1 year ago

Even I am facing this issue when integrating with Typescript.

LonYui commented 1 year ago

我今天重現了這個問題,我使用測試網絡

shah-smit commented 1 year ago

I manage to solve it, https://github.com/xtf-dapp/xtf-web-app/issues/4

LonYui commented 1 year ago

Ohh I also solve it

I config wrong on network I'd

Smit Shah @.***>於 2023年2月12日 週日,下午1:56寫道:

I manage to solve it, xtf-dapp/xtf-web-app#4 https://github.com/xtf-dapp/xtf-web-app/issues/4

— Reply to this email directly, view it on GitHub https://github.com/dydxprotocol/dydx-v3-python/issues/140#issuecomment-1426950112, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACI375SLM4P4I22FBJ3RSCLWXB3SDANCNFSM5UZTRVKA . You are receiving this because you commented.Message ID: @.***>

sheungon commented 1 year ago

I found the same issues too. And fixed by the following.

if testnet is used, ~network_id=NETWORK_ID_GOERLI~ network_id=NETWORK_ID_SEPOLIA should be used on creating the client = Client(.

Otherwise, network_id=NETWORK_ID_MAINNET should be used.

claudio-1980 commented 8 months ago

hi, I found the some problem, please some help Screenshot from 2024-02-26 12-09-03