Giter Site home page Giter Site logo

Comments (7)

emmtte avatar emmtte commented on June 4, 2024

Poloniex and Kucoin are blank because I have still some problems with the code.
Need to work on it

from cryptocurrency-portfolio.

Popcaughan avatar Popcaughan commented on June 4, 2024

Well, here's the code I use for Polo and it works fine.

// THIS IS THE PART THAT SHOWS YOU HOW TO DO PRIVATE CALLS with the POST METHOD and your Poloniex secret key

function getPoloBalances(key, secret){

var api_key = key;
var api_secret = secret;

// First you create a nonce, which is an incremental random number, to do so, we can use the current date time summed with a number
var nonce = 9465426902234426 + new Date().getTime();

// First choose a command from here https://poloniex.com/support/api/ seeing if it require specific options
// Then, we set the variable 'p' as a string which combine the command & any related parameter (if any) & the nonce.
// in this case we specified the account=all parameter for the command=returnCompleteBalances as it gives us also loans and on orders balances

var p = "command=returnCompleteBalances&account=all&nonce="+nonce;

// Then, we sign this variable 'p' with our secret key (taken from the API of Poloniex) to obtain a new string 'signature'
var signature = Utilities.computeHmacSignature(Utilities.MacAlgorithm.HMAC_SHA_512, p, api_secret);

// Then, we convert the resulting string: from an array of byte (which is a standard output) to HEX
signature = signature.map(function(byte) {
return ('0' + (byte & 0xFF).toString(16)).slice(-2);
}).join('')

// Then we create the variable 'headers' and we specify in the object "Key" the API key associated with the secret key (always taken from the API of Poloniex), and we pass the 'signature' output string to the object "Sign"
var headers = {
"Key" : api_key,
"Sign" : signature
};

// then we define 'options' as POST method, specifying the headers and the payload

var options = {
"method" : "POST",
"headers": headers,
"payload": p
};

// Then we fetch the url passing the 'options' which make us call the command and sign it

var url = "https://poloniex.com/tradingApi";
var response2 = UrlFetchApp.fetch(url, options);

// Then we parse the fetched url in the var 'json2'
var json2 = JSON.parse(response2.getContentText());

from cryptocurrency-portfolio.

jceelen avatar jceelen commented on June 4, 2024

@ManuCart I am working on a similar project but with a focus on getting the order history maybe we help each other a bit. I am not a very experienced developer but I am trying to adapt this rest client for Google Apps: https://github.com/Satoshinaire/kucoin-api

from cryptocurrency-portfolio.

emmtte avatar emmtte commented on June 4, 2024

@jceelen Good to see that, I was first focused too with order history but it was to complex for me because we need to work with ledger, BNB fees, ETH market... Too much solution to implement but have no much time. Good luck!

from cryptocurrency-portfolio.

emmtte avatar emmtte commented on June 4, 2024

@Popcaughan thanks for the code added Poloniex
Need to work on Kucoin

from cryptocurrency-portfolio.

Popcaughan avatar Popcaughan commented on June 4, 2024

Hi, below is what I've got for kucoin. Any chance you could take a look at Bitstamp? At the moment my Google Sheet connects to a VPS running node.js code to download stamp balances, but I'd love to do it directly.

Please note that Bitstamp requires API key, secret and customer number to create your signature.

Anyway, here's the kucoin code:

function kucoin(){

 var host = 'https://api.kucoin.com';
 var endpoint ='/v1/account/balance';
 var nonce = '' + Date.parse(new Date());
 var strForSign = endpoint + '/' + nonce + '/';
 var signatureStr = Utilities.base64Encode(strForSign, Utilities.Charset.UTF_8);
 var digest = Utilities.computeHmacSha256Signature(signatureStr, priv_key, Utilities.Charset.UTF_8);

 // https://pthree.org/2016/02/26/digest-algorithms-in-google-spreadsheets/
 var hexstr = '';
 for (i = 0; i < digest.length; i++) {
   var val = (digest[i]+256) % 256;
   hexstr += ('0'+val.toString(16)).slice(-2);
 }

 var url = host + endpoint;
 var options = {
   'headers' : {
     'KC-API-KEY': pub_key,
     'KC-API-NONCE': nonce,
     'KC-API-SIGNATURE': hexstr
    }
 }

 var jsondata = UrlFetchApp.fetch(url, options);
 var data   = JSON.parse(jsondata.getContentText());

// {msg=Operation succeeded., code=OK, data=[{coinType=KCS, balance=0, freezeBalanceStr=0.0, balanceStr=0.0, freezeBalance=0}, {coinType=XRB, balance=0, freezeBalanceStr=0.0, balanceStr=0.0, freezeBalance=0},
for(var x in data.data){
var balance = parseFloat(data.data[x].balance);
if (balance > 0) {
var asset = data.data[x].coinType
array.push({'currency': asset, 'balance': balance, 'market': "Kucoin"});
}
}
}

from cryptocurrency-portfolio.

emmtte avatar emmtte commented on June 4, 2024

Hi @Popcaughan
Thank you for your help for Poloniex and Kucoin.
I try to find something for Bitstamp.
I will work on it.
I close this issue, feel free to open an other about bitstamp

from cryptocurrency-portfolio.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.