Skip to content

Instantly share code, notes, and snippets.

@umyuu
Created April 7, 2018 12:23
Show Gist options
  • Save umyuu/10c6bb7d1c7e5bcf75c9ca191e3dcabb to your computer and use it in GitHub Desktop.
Save umyuu/10c6bb7d1c7e5bcf75c9ca191e3dcabb to your computer and use it in GitHub Desktop.
var keys = {
    'api': 'APIキー',
    'secret': 'secretキー'
};
function get_nonce(){
  return  (new Date().getTime() / 1000).toFixed(0);
}
function toHexString(data) {
    return data.map(function(e) {
        return ('00' + (e & 0xFF).toString(16)).slice(-2);
    }).join("");
}
function create_postdata(keys, body){
  var sign = Utilities.computeHmacSignature(Utilities.MacAlgorithm.HMAC_SHA_512, body, keys.secret);
  return {
        'method': 'post',
        'headers': {
          'sign': toHexString(sign),
          'key': keys.api
        },
    'payload': body
  };
}

function EntryPoint() {
  var body= 'method=get_info&nonce=' + get_nonce();
  Logger.log(body);
  var post_data = create_postdata(keys, body);
  Logger.log(post_data);
  const endpoint = 'https://api.zaif.jp/tapi';
  var response = UrlFetchApp.fetch(endpoint, post_data);
  Logger.log("#############################");
  Logger.log(response);
  Logger.log("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
  Logger.log(response.getContentText());
}
@umyuu
Copy link
Author

umyuu commented Apr 7, 2018

Http Method    = "POST"
◇Format
+-----------+-----------------+
| Headers   |  Payload Data   |
+-----------+-----------------+
◇Headers
+-----------+-----------------+
|    sign   |      key        |
+-----------+-----------------+
sign           = HMAC-SHA512(secret-key, Payload Data)
key            = api-key
◇Payload Data
+-----------------------------+
|       Query Strings         |
+-----------------------------+
Query Strings  = (nonce
                  method
                  parameters)
nonce          = cnonce
                 ; MUST increment
method         = api-method
parameters     = api-parameters
                 ; Options 

◇参考情報
Zaif api document v1.1.1 ドキュメント トレードAPI 共通情報

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment