Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save martinhbramwell/c7c90828f049457a1ba87bd62c779b8d to your computer and use it in GitHub Desktop.
Save martinhbramwell/c7c90828f049457a1ba87bd62c779b8d to your computer and use it in GitHub Desktop.
Postman Collection for Kraken Rest API
{
"info": {
"_postman_id": "d7e3ee8c-fc3b-4aca-bc0b-3f4afc890eb6",
"name": "Kraken",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
},
"item": [
{
"name": "Private",
"item": [
{
"name": "Balance",
"event": [
{
"listen": "prerequest",
"script": {
"exec": [
""
],
"type": "text/javascript"
}
}
],
"protocolProfileBehavior": {
"disableCookies": true
},
"request": {
"method": "POST",
"header": [
{
"key": "API-Sign",
"type": "text",
"value": "{{api_signature}}"
}
],
"body": {
"mode": "urlencoded",
"urlencoded": [
{
"key": "nonce",
"value": "{{api_nonce}}",
"type": "text"
}
]
},
"url": {
"raw": "{{Site}}/{{API Version}}/private/Balance",
"host": [
"{{Site}}"
],
"path": [
"{{API Version}}",
"private",
"Balance"
]
}
},
"response": []
},
{
"name": "Add Order",
"event": [
{
"listen": "test",
"script": {
"exec": [
"const jsonData = JSON.parse(responseBody);",
"console.log('jsonData')",
"console.log()",
"const lastOrderNumber = jsonData.result.txid[0];",
"",
"pm.collectionVariables.set('LastOrderNumber', lastOrderNumber)",
""
],
"type": "text/javascript"
}
},
{
"listen": "prerequest",
"script": {
"exec": [
""
],
"type": "text/javascript"
}
}
],
"protocolProfileBehavior": {
"disableCookies": true,
"disableUrlEncoding": false
},
"request": {
"method": "POST",
"header": [
{
"key": "API-Sign",
"type": "text",
"value": "{{api_signature}}"
},
{
"key": "Ticket",
"value": " 6011748",
"type": "text"
}
],
"body": {
"mode": "urlencoded",
"urlencoded": [
{
"key": "nonce",
"value": "{{api_nonce}}",
"type": "text"
},
{
"key": "pair",
"value": "UNIETH",
"type": "text"
},
{
"key": "type",
"value": "buy",
"type": "text"
},
{
"key": "ordertype",
"value": "limit",
"type": "text"
},
{
"key": "price",
"value": "0.0083",
"type": "text"
},
{
"key": "volume",
"value": "1",
"type": "text"
},
{
"key": "close[ordertype]",
"value": "stop-loss-limit",
"type": "text"
},
{
"key": "close[price]",
"value": "0.0082",
"type": "text"
},
{
"key": "close[price2]",
"value": "0.00815",
"type": "text"
},
{
"key": "validate",
"value": "true",
"type": "text",
"disabled": true
}
]
},
"url": {
"raw": "https://api.kraken.com/0/private/AddOrder",
"protocol": "https",
"host": [
"api",
"kraken",
"com"
],
"path": [
"0",
"private",
"AddOrder"
]
}
},
"response": []
},
{
"name": "Open Orders",
"event": [
{
"listen": "prerequest",
"script": {
"exec": [
""
],
"type": "text/javascript"
}
}
],
"protocolProfileBehavior": {
"disableCookies": true
},
"request": {
"method": "POST",
"header": [
{
"key": "API-Sign",
"type": "text",
"value": "{{api_signature}}"
}
],
"body": {
"mode": "urlencoded",
"urlencoded": [
{
"key": "nonce",
"value": "{{api_nonce}}",
"type": "text"
}
]
},
"url": {
"raw": "{{Site}}/{{API Version}}/private/OpenOrders",
"host": [
"{{Site}}"
],
"path": [
"{{API Version}}",
"private",
"OpenOrders"
]
}
},
"response": []
},
{
"name": "Cancel Order",
"event": [
{
"listen": "test",
"script": {
"exec": [
""
],
"type": "text/javascript"
}
},
{
"listen": "prerequest",
"script": {
"exec": [
""
],
"type": "text/javascript"
}
}
],
"protocolProfileBehavior": {
"disableCookies": true,
"disableUrlEncoding": false
},
"request": {
"method": "POST",
"header": [
{
"key": "API-Sign",
"type": "text",
"value": "{{api_signature}}"
},
{
"key": "Ticket",
"value": " 6011748",
"type": "text"
}
],
"body": {
"mode": "urlencoded",
"urlencoded": [
{
"key": "nonce",
"value": "{{api_nonce}}",
"type": "text"
},
{
"key": "txid",
"value": "OGNQUE-TUUAL-RDNR6Z",
"type": "text"
}
]
},
"url": {
"raw": "https://api.kraken.com/0/private/CancelOrder",
"protocol": "https",
"host": [
"api",
"kraken",
"com"
],
"path": [
"0",
"private",
"CancelOrder"
]
}
},
"response": []
},
{
"name": "Closed Orders",
"event": [
{
"listen": "prerequest",
"script": {
"exec": [
""
],
"type": "text/javascript"
}
}
],
"protocolProfileBehavior": {
"disableCookies": true
},
"request": {
"method": "POST",
"header": [
{
"key": "API-Sign",
"type": "text",
"value": "{{api_signature}}"
}
],
"body": {
"mode": "urlencoded",
"urlencoded": [
{
"key": "nonce",
"value": "{{api_nonce}}",
"type": "text"
}
]
},
"url": {
"raw": "{{Site}}/{{API Version}}/private/ClosedOrders",
"host": [
"{{Site}}"
],
"path": [
"{{API Version}}",
"private",
"ClosedOrders"
]
}
},
"response": []
}
],
"event": [
{
"listen": "prerequest",
"script": {
"type": "text/javascript",
"exec": [
"const private = postman.getEnvironmentVariable(\"PKey\");",
"// console.log(\"stopLossLimit = \" + stopLossLimit)",
"",
"let api_body_string = '';",
"let sep = '';",
"function reformat(elem) {",
" if (! elem.disabled) {",
" api_body_string += sep + encodeURIComponent(elem.key) + '=' + elem.value;",
" sep = '&';",
" }",
"}",
"",
"function visible() {",
" console.log('visible')",
"}",
"",
"const api_secret = CryptoJS.enc.Base64.parse(private);",
"const api_nonce = (Date.now() * 1000).toString();",
"const api_endpoint = \"/0/private/\" + pm.request.url.path[2];",
"",
"const api_body = pm.request.body.urlencoded",
"// console.log(api_body)",
"api_body.upsert({key: 'nonce', value: api_nonce})",
"api_body.each(reformat);",
"console.log(api_body_string)",
"",
"api_sha256 = CryptoJS.SHA256(api_nonce + api_body_string);",
"api_sign = CryptoJS.algo.HMAC.create(CryptoJS.algo.SHA512, api_secret);",
"api_sign.update(api_endpoint, api_secret);",
"api_sign.update(api_sha256, api_secret);",
"api_sign = api_sign.finalize().toString(CryptoJS.enc.Base64);",
"",
"pm.globals.set(\"api_nonce\", api_nonce);",
"pm.globals.set(\"api_signature\", api_sign);",
""
]
}
},
{
"listen": "test",
"script": {
"type": "text/javascript",
"exec": [
""
]
}
}
]
},
{
"name": "Public",
"item": [
{
"name": "All Assets",
"event": [
{
"listen": "prerequest",
"script": {
"exec": [
""
],
"type": "text/javascript"
}
}
],
"protocolProfileBehavior": {
"disableCookies": true
},
"request": {
"auth": {
"type": "noauth"
},
"method": "GET",
"header": [],
"url": {
"raw": "{{Site}}/{{API Version}}/public/Assets",
"host": [
"{{Site}}"
],
"path": [
"{{API Version}}",
"public",
"Assets"
]
}
},
"response": []
}
],
"auth": {
"type": "noauth"
},
"event": [
{
"listen": "prerequest",
"script": {
"type": "text/javascript",
"exec": [
""
]
}
},
{
"listen": "test",
"script": {
"type": "text/javascript",
"exec": [
""
]
}
}
]
}
],
"auth": {
"type": "apikey",
"apikey": [
{
"key": "key",
"value": "API-Key",
"type": "string"
},
{
"key": "value",
"value": "{{api_key}}",
"type": "string"
}
]
},
"event": [
{
"listen": "prerequest",
"script": {
"type": "text/javascript",
"exec": [
""
]
}
},
{
"listen": "test",
"script": {
"type": "text/javascript",
"exec": [
""
]
}
}
],
"variable": [
{
"key": "Site",
"value": "https://api.kraken.com"
},
{
"key": "API Version",
"value": "0"
},
{
"key": "LastOrderNumber",
"value": ""
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment