title: Signature for this request is not valid error for Binance US API
body: <p>I am getting a signature not valid error while connecting to Binance API endpoints that require authentication. There is a similar query in following link however it is specific to Binance, I guess and this question is specific to Binance US. I tried to use the methods in below link though and it didn't work.</p>
  <p><a href="https://stackoverflow.com/questions/66725742/flutter-binance-api-signature">Flutter binance api signature</a></p>
  <p>Following is the Python code</p>
  <pre><code>import urllib.parse
  import hashlib
  import hmac
  import base64
  import requests
  
  api_url = &quot;https://api.binance.us&quot;
  
  # get binanceus signature
  def get_binanceus_signature(data, secret):
      postdata = urllib.parse.urlencode(data)
      message = postdata.encode()
      byte_key = bytes(secret, 'UTF-8')
      mac = hmac.new(byte_key, message, hashlib.sha256).hexdigest()
      return mac
  
  # Attaches auth headers and returns results of a POST request
  def binanceus_request(uri_path, data, api_key, api_sec):
      headers = {}
      headers['X-MBX-APIKEY'] = api_key
      signature = get_binanceus_signature(data, api_sec) 
      params={**data, &quot;signature&quot;: signature}           
      req = requests.get((api_url + uri_path), params=params, headers=headers)
      return req.text
  
  api_key = &quot;vmPUZE6mv9SD5VNHk4HlWFsOr6aKE2zvsw0MuIgwCIPy6utIco14y7Ju91duEh8A&quot;
  secret_key = &quot;NhqPtmdSJYdKjVHjA7PZj4Mge3R5YNiP1e3UZjInClVN65XAbvqqM6A7H5fATj0j&quot;
  
  uri_path = &quot;/api/v3/openOrders&quot;
  data = {
      &quot;symbol&quot;: &quot;BTCUSDT&quot;, 
      &quot;timestamp&quot;: 1499827319559
  }
  
  get_open_order_result = binanceus_request(uri_path, data, api_key, secret_key)
  </code></pre>
  <p>Here is the full dart code.</p>
  <pre><code>class BinanceUSRestClient {
    final String timestamp = DateTime.now().millisecondsSinceEpoch.toString();
  
    Future&lt;http.Response&gt; getResponse({
      required String secret,
      required String apiKey,
      required String path,
      Map&lt;String, dynamic&gt;? queryParams,
    }) async {
      //Header
      Map&lt;String, String&gt; headers = {};
      headers['X-MBX-APIKEY'] = apiKey;
  
      //Params
      Map&lt;String, dynamic&gt; params = {};
      if (queryParams != null) {
        params.addAll(queryParams);
      }
      params['signature'] = createSignature(secret, queryParams);
      params['timestamp'] = timestamp;
  
      final Uri uri = Uri.https('api.binance.us', path, params);
      http.Response response = await http.get(
        uri,
        headers: headers,
      );
      return response;
    }
  
    String createSignature(String secret, Map&lt;String, dynamic&gt;? data) {
      final String jsonString = jsonEncode(data);
      final List&lt;int&gt; message = utf8.encode(jsonString);
      final List&lt;int&gt; key = utf8.encode(secret);
      final List&lt;int&gt; mac = Hmac(sha256, key).convert(message).bytes;
      final String signature = hex.encode(mac);
      return signature;
    }
  }
  </code></pre>
  <p>If it helps, here is the <a href="https://docs.binance.us/?python#signature-authentication" rel="nofollow noreferrer">API documentation</a>. Could someone help me in resolving the error?</p>