Bitcoin Forum
May 24, 2024, 05:16:40 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
  Home Help Search Login Register More  
  Show Posts
Pages: « 1 2 3 [4]
61  Economy / Exchanges / Re: Need help with Poloniex API (buy/sell command errors) on: July 12, 2017, 09:32:36 AM
Here is my code:

Quote
// work in progress

// you need a poloniex API key and secret with trading option enabled
// you can test it with:
// = poloniex ("returnBalances","BTC")
// or
// = poloniex ("returnBalances")


function poloniex(command,parameter,subparam) {
      
  // I assume that all the keys are in the "keys" spreadsheet. The key is in cell A1 and the secret in cell A2
      
  var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("keys");
  
  var key = sheet.getRange("A1").getValue();
    
  var secret = sheet.getRange("A2").getValue();

  var nonce = 1495932972127042 + new Date().getTime();
    
  var payload = {
    "nonce": nonce,
    "command": command
  }
  
  var payloadEncoded = Object.keys(payload).map(function(param) {
    return encodeURIComponent(param) + '=' + encodeURIComponent(payload[param]);
  }).join('&');
    
  var uri = "https://poloniex.com/tradingApi";

  var signature = Utilities.computeHmacSignature(Utilities.MacAlgorithm.HMAC_SHA_512, payloadEncoded, secret);
    
  var stringSignature = "";
  
  for (i = 0; i < signature.length; i++) {
    var byte = signature;
    if (byte < 0)
      byte += 256;
    var byteStr = byte.toString(16);
    if (byteStr.length == 1) byteStr = '0'+byteStr;
    stringSignature += byteStr;
   }
    
  var headers = {
    "key": key,
    "sign": stringSignature
  }
  
  var params = {
    "method": "post",
    "headers": headers,
    "payload": payloadEncoded
  }
  
  var response = UrlFetchApp.fetch(uri, params);
  
  var dataAll = JSON.parse(response.getContentText());
  
  //Edited
  if (parameter === undefined) {
    Logger.log(JSON.stringify(dataAll))
    return JSON.stringify(dataAll) }
  else if(parameter != undefined && subparam === undefined) {
    return dataAll[parameter] }
  else if (parameter != undefined && subparam != undefined) {
    return dataAll[parameter][subparam] }
  //end edited
}
62  Economy / Exchanges / Need help with Poloniex API (buy/sell command errors) on: July 12, 2017, 04:17:05 AM
Hi,
I am creating a trading tool with google spreadsheets and google apps scripts (very similar to Javascript). Everything seems to be ok (check balances, get addresses,...) but the buy/sell command. When I place an order by this command: = poloniex("buy","USDT_ZEC",100,0.01) and the api response: {"error":"Total must be at least 0.0001."}.
I tried to change the param to other values but always get the same results (even when I change the pair name to a wrong name like BTC_XXX, it answered the same error). PLease help me to address this. Thanks in advance!
Pages: « 1 2 3 [4]
Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!