dydx-v3-python icon indicating copy to clipboard operation
dydx-v3-python copied to clipboard

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

Open oeawFebe opened this issue 3 years ago • 13 comments

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 avatar May 01 '22 09:05 oeawFebe

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 avatar May 01 '22 14:05 oeawFebe

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

oeawFebe avatar May 02 '22 22:05 oeawFebe

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"

KittenCN avatar May 06 '22 05:05 KittenCN

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.

SC4RECOIN avatar Jul 10 '22 19:07 SC4RECOIN

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 avatar Aug 11 '22 11:08 akipponn

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 ...

akipponn avatar Aug 12 '22 13:08 akipponn

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

same problem. any solution?

dfkai avatar Jan 20 '23 05:01 dfkai

Even I am facing this issue when integrating with Typescript.

shah-smit avatar Jan 21 '23 14:01 shah-smit

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

LonYui avatar Feb 10 '23 02:02 LonYui

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

shah-smit avatar Feb 12 '23 05:02 shah-smit

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: @.***>

LonYui avatar Feb 12 '23 06:02 LonYui

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.

sheungon avatar Apr 06 '23 09:04 sheungon

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

claudio-1980 avatar Feb 26 '24 17:02 claudio-1980