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

'network' issue when has special character #6

Open
zonbloginc opened this issue Nov 28, 2023 · 6 comments
Open

'network' issue when has special character #6

zonbloginc opened this issue Nov 28, 2023 · 6 comments

Comments

@zonbloginc
Copy link

zonbloginc commented Nov 28, 2023

I perform a withdrawal with MxcSpotV3 ->privates()->withdraw($data) and everything work fine except if I try to do anything with $data = ['network' => 'BEP20(BSC)'] or any network that contains special characters, like SPACE, or ' - '.

It made the query URL to be differ than expected:

API server expected: /api/v3/capital/withdraw/apply?coin=USDT&address=zzqqqqqqqqqq&amount=10&network=BEP20(BSC)&memo=MX10086&timestamp={{timestamp}}&signature={{signature}}

The real one with the mxc repo: /api/v3/capital/withdraw/apply?coin=USDT&address=zzqqqqqqqqqq&amount=10&network=BEP20%28BSC%29&memo=MX10086&timestamp={{timestamp}}&signature={{signature}}

It seems it can't convert these characters correct when pushing to the API servers. If I use the 'network' with simple type, such as ERC20, OP, MATIC, then there is no issue at all.

Can you take a look at this?

@zonbloginc
Copy link
Author

zonbloginc commented Nov 29, 2023

After spending a short time to figure out, it seems the error message would be:

{"code":700002,"msg":"Signature for this request is not valid.","_method":"POST","_url":"https://api.mexc.com/api/v3/capital/withdraw/apply","_httpcode":400} {"userId":"tony","exception":"[object] (Lin\Mxc\Exceptions\Exception(code: 0): {"code":700002,"msg":"Signature for this request is not valid.","_method":"POST","_url":"https:\/\/api.mexc.com\/api\/v3\/capital\/withdraw\/apply","_httpcode":400}

Somehow, if use special characters in query URL, it didn't work and led to this 'signature' error.

Worked version: coin=USDT&network=EOS&address=XXX&amount=100&withdrawOrderId=TEST&timestamp=1701231754000

Didn't work: coin=USDT&network=EOS%28TEST%29&address=XXX&amount=100&withdrawOrderId=TEST&timestamp=1701231859000

I tried to build query URL manually but didn't work too: coin=USDT&network=EOS(TEST)&address=XXX&amount=100&withdrawOrderId=TEST&timestamp=1701231754000

To clarify that your repo didn't have withdraw() function, I created a new one in SpotV3\Privates:

// POST /api/v3/capital/withdraw/apply //
public function withdraw(array $data=[]){
$this->type='POST';
$this->path='/api/v3/capital/withdraw/apply';
$this->data=$data;
return $this->exec();
}

https://mexcdevelop.github.io/apidocs/spot_v3_en/#withdraw

@zhouaini528
Copy link
Owner

After spending a short time to figure out, it seems the error message would be:

{"code":700002,"msg":"Signature for this request is not valid.","_method":"POST","_url":"https://api.mexc.com/api/v3/capital/withdraw/apply","_httpcode":400} {"userId":"tony","exception":"[object] (Lin\Mxc\Exceptions\Exception(code: 0): {"code":700002,"msg":"Signature for this request is not valid.","_method":"POST","_url":"https://api.mexc.com/api/v3/capital/withdraw/apply","_httpcode":400}

Somehow, if use special characters in query URL, it didn't work and led to this 'signature' error.

Worked version: coin=USDT&network=EOS&address=XXX&amount=100&withdrawOrderId=TEST&timestamp=1701231754000

Didn't work: coin=USDT&network=EOS%28TEST%29&address=XXX&amount=100&withdrawOrderId=TEST&timestamp=1701231859000

I tried to build query URL manually but didn't work too: coin=USDT&network=EOS(TEST)&address=XXX&amount=100&withdrawOrderId=TEST&timestamp=1701231754000

To clarify that your repo didn't have withdraw() function, I created a new one in SpotV3\Privates:

// POST /api/v3/capital/withdraw/apply // public function withdraw(array $data=[]){ $this->type='POST'; $this->path='/api/v3/capital/withdraw/apply'; $this->data=$data; return $this->exec(); }

https://mexcdevelop.github.io/apidocs/spot_v3_en/#withdraw

Signature issues, special characters, may all require no encoding, I tried to solve this problem.

@zhouaini528
Copy link
Owner

After spending a short time to figure out, it seems the error message would be:

{"code":700002,"msg":"Signature for this request is not valid.","_method":"POST","_url":"https://api.mexc.com/api/v3/capital/withdraw/apply","_httpcode":400} {"userId":"tony","exception":"[object] (Lin\Mxc\Exceptions\Exception(code: 0): {"code":700002,"msg":"Signature for this request is not valid.","_method":"POST","_url":"https://api.mexc.com/api/v3/capital/withdraw/apply","_httpcode":400}

Somehow, if use special characters in query URL, it didn't work and led to this 'signature' error.

Worked version: coin=USDT&network=EOS&address=XXX&amount=100&withdrawOrderId=TEST&timestamp=1701231754000

Didn't work: coin=USDT&network=EOS%28TEST%29&address=XXX&amount=100&withdrawOrderId=TEST&timestamp=1701231859000

I tried to build query URL manually but didn't work too: coin=USDT&network=EOS(TEST)&address=XXX&amount=100&withdrawOrderId=TEST&timestamp=1701231754000

To clarify that your repo didn't have withdraw() function, I created a new one in SpotV3\Privates:

// POST /api/v3/capital/withdraw/apply // public function withdraw(array $data=[]){ $this->type='POST'; $this->path='/api/v3/capital/withdraw/apply'; $this->data=$data; return $this->exec(); }

https://mexcdevelop.github.io/apidocs/spot_v3_en/#withdraw

else $this->options['form_params']=$this->data;

QQ20231129-151627

The post submission data is in the form_params way, and the special characters in it are not encoded, why is your submission data a GET URL splicing?

@zonbloginc
Copy link
Author

I discussed to one of MEXC supporter on this issue and he said:

  1. the URL data: http_build_query($this->data) need to be encoded, so use http_build_query is satisfy the requirement.
  2. the POST URL doesn't need encode

picpic

The post submission data is in the form_params way, and the special characters in it are not encoded, why is your submission data a GET URL splicing?

This is the log version of http_build_query($this->data) in signature() function, not the POST URL.

coin=USDT&network=EOS&address=XXX&amount=100&withdrawOrderId=TEST&timestamp=1701231754000

I still can't pass this annoying issue, maybe the error came from their API server?

@zhouaini528
Copy link
Owner

I discussed to one of MEXC supporter on this issue and he said:

  1. the URL data: http_build_query($this->data) need to be encoded, so use http_build_query is satisfy the requirement.
  2. the POST URL doesn't need encode

picpic

The post submission data is in the form_params way, and the special characters in it are not encoded, why is your submission data a GET URL splicing?

This is the log version of http_build_query($this->data) in signature() function, not the POST URL.

coin=USDT&network=EOS&address=XXX&amount=100&withdrawOrderId=TEST&timestamp=1701231754000

I still can't pass this annoying issue, maybe the error came from their API server?

I found a way you can try

echo $url=urldecode(http_build_query($arr));

@zonbloginc
Copy link
Author

Actually, I tried to build the query string for signature manually with/without encode and it still didn't work. MEXC also has recently changed the list of withdrawal networks into special character mode. Right now, most of networks have special characters in them, except several ones, such as EOS, OKT ...

So withdraw asset through API seems not possible at this moment.

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