How to fit Binance API signature error msg - 1022?

Viewed 731

When I try to make a request I get the following error message:

code: -1022, Signature for this request is not valid

The request is being made to https://api.binance.com/sapi/v1/capital/address. There is no error when using the time stamp parameter. However, using the coin parameter or any other parameter will cause an error.

String path = '/sapi/v1/capital/deposit/address?';
String coin = 'coin=BTC';
int timeStamp = DateTime.now().millisecondsSinceEpoch;
String queryParams = '&recvWindow=60000' + '&timestamp=' + timeStamp.toString();
String secret = 'secret key';

List<int> messageBytes = utf8.encode(queryParams);
List<int> key = utf8.encode(secret);
Hmac hmac = new Hmac(sha256, key);
Digest digest = hmac.convert(messageBytes);
String signature = hex.encode(digest.bytes);

String url = baseUrl + path + queryParams + "&signature=" + signature;

  void _fetchPosts() async {
    final response = await http.get(url, headers: {
      "Accept": "application/json",
      "X-MBX-APIKEY":
          "API-KEY"
    });```
0 Answers
Related