0

I try to get account information from Binance, using Matlab, but I get 404 error (not found).

The Binance API is explaned here Binance Api

I also found a post here, but did not help me to solve the problem

Binance cryptoexchange API “/account” 401 response

thanks for your help

function BinanceGetAccountInfo()

[key,secret]=key_secret('binance');    
timestamp=binanceServerTime;

queryString =['timestamp=' timestamp]
Signature = crypto(queryString, secret, 'HmacSHA256');
Signature=string(Signature)

url='https://api.binance.com/api/v3/';
url_ext='account';
url=[url url_ext '?' queryString '&signature=' Signature]

postparams=['X-MBX-APIKEY=' key]

header=http_createHeader('Content-Type','application/x-www-form-urlencoded')


[response,status] = urlread2(url,'POST',postparams,header);
verifStatus=status.status

end

function signStr = crypto(str, key, algorithm)
import java.net.*;
import javax.crypto.*;
import javax.crypto.spec.*;
import org.apache.commons.codec.binary.*

keyStr = java.lang.String(key);
key = SecretKeySpec(keyStr.getBytes('UTF-8'), algorithm);
mac = Mac.getInstance(algorithm);
mac.init(key);
toSignStr = java.lang.String(str);
signStr = java.lang.String(Hex.encodeHex( mac.doFinal(  toSignStr.getBytes('UTF-8'))));
end

function serverTime=binanceServerTime(adTime)
if nargin<1
adTime=0; %millisecondes
end
serverTime=urlread2('https://www.binance.com/api/v1/time');
serverTime=JSON.parse(serverTime);
serverTime=num2str(serverTime.serverTime+adTime);
end
Belkacem
  • 1
  • 4
  • 1
    I am assuming that you are using Volkan's FEX [submission](https://uk.mathworks.com/matlabcentral/fileexchange/50478-woulgar-tradesman) as you are using the `key_secret` method at the start of the code. If you inspect the method, you will find that Binance is not yet supported in that code. – Paolo Jun 29 '18 at 19:32
  • What sort of information do you want to retrieve from Matlab, just information regarding your account? – Paolo Jun 29 '18 at 19:37
  • Hi, thanks for your ansewer, * yes I am using Volkan's FEX submission, the author did not implement the api binance, and it's what I am trying to do. The information account is just an example, to let me know how to deal with authentification. The final goal is to implement the whol Binance API (balance account, sell/buy order....). *If you can help with this it will be great! Thanks – Belkacem Jun 29 '18 at 21:22
  • Of corse I modified the key_secret method to support binance, so this function is not the problem. – Belkacem Jun 29 '18 at 21:30
  • 1
    Can you share the `key_secret` method then, and any other helper functions that you are using so that I can help? I am, or better was, a crypto enthusiast myself :) – Paolo Jun 29 '18 at 22:18
  • You can find that fuction at Volkan's code, just put your keys there (unless you want me to give you mine!) – Belkacem Jun 29 '18 at 23:11
  • I found his code but how did you configure it for it to work on Binance? – Paolo Jun 29 '18 at 23:15

1 Answers1

0

Try my FEX Submission: MATLAB-Binance-API

After setting it up you can get your account info by calling:

spot.accountInfo

The submission supports all spot account endpoints - you can buy/sell with any order type on a spot account. I'm also planning to extend the submission with further releases; margin endpoints and websockets are next on my list.

  • Hi, thanks , I tryed it, the source code is awsome, but still cant guet the connection : " Undefined function or variable 'QueryParameter'. Error in sendRequest (line 44) QP = QueryParameter(s); " Can you help, please ? I use Matlab R2016b – Belkacem Oct 02 '21 at 09:53
  • Hi Belkacem, I assume your comment relates to this [thread](https://github.com/hughestu/MATLAB-Binance-API/issues/4), in which case it was a compatibility issue. You used R2016a, correct? – Turlough Hughes Oct 03 '21 at 16:25