Skip to content

Commit

Permalink
Changes:
Browse files Browse the repository at this point in the history
* Order queryStringParameters alphabetically
* Add buyToAddress
  • Loading branch information
vnistor committed Nov 14, 2018
1 parent 7df7cd2 commit 45e46cf
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 7 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ parameters: `ledgerid`
### getBankAccount
parameters: `accountid`

## __Trade__
### buyToAddress
parameters: `walletid`, `address`, `ccy1`, `cost` and, optionally for XRP, `address_tag`

---

### Credit:
Expand Down
45 changes: 40 additions & 5 deletions coinflux.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const axios = require('axios');
const crypto = require('crypto');
const qs = require('qs');

// Default options
const defaults = {
Expand All @@ -15,9 +14,9 @@ const defaults = {
};
const methods = {
public : ["getRates", "getRate"],
private : ["getFluxes", "getFlux", "getFluxAddresses", "getFluxOfAddress", "newSellAddress", "getWallets", "getWallet", "getLedger", "getLedgerTx", "getWalletHistory", "getWalletHistoryTx", "getBankAccounts", "getBankAccount"],
private : ["getFluxes", "getFlux", "getFluxAddresses", "getFluxOfAddress", "newSellAddress", "getWallets", "getWallet", "getLedger", "getLedgerTx", "getWalletHistory", "getWalletHistoryTx", "getBankAccounts", "getBankAccount", "buyToAddress"],
get: ["getRates", "getRate", "getFluxes", "getFlux", "getFluxAddresses", "getFluxOfAddress", "getWallets", "getWallet", "getLedger", "getLedgerTx", "getWalletHistory", "getWalletHistoryTx", "getBankAccounts", "getBankAccount"],
post: ["newSellAddress"]
post: ["newSellAddress", "buyToAddress"]
}
const paths = {
getRates: "/public/rates",
Expand All @@ -34,12 +33,20 @@ const paths = {
getWalletHistory: "/private/wallets/{walletid}/history",
getWalletHistoryTx: "/private/wallets/{walletid}/history/{historyid}",
getBankAccounts: "/private/bankaccounts",
getBankAccount: "/private/bankaccounts/{accountid}"
getBankAccount: "/private/bankaccounts/{accountid}",
buyToAddress: "/private/trade/buy/toAddress"
}

// Create a signature for a request
const getMessageSignature = (path, queryStringParameters, secret, nonce) => {
const message = qs.stringify(queryStringParameters);
const qs = require('qs');

// Function to sort paramaters alphabetically
function alphabeticalSort(a, b) {
return a.localeCompare(b);
}

const message = qs.stringify(queryStringParameters, {sort: alphabeticalSort});
const secret_buffer = Buffer.from(secret, 'hex');
const hash = new crypto.createHash('sha256');
const hmac = new crypto.createHmac('sha512', secret_buffer);
Expand Down Expand Up @@ -256,6 +263,28 @@ class CoinFluxClient {
throw new Error("Missing parmater: accountid");
}
break;
case 'buyToAddress':
verb = 'POST';
if (!params.walletid) {
throw new Error("Missing parmater: walletid");
}

if (!params.address) {
throw new Error("Missing parmater: address");
}

if (!params.cost) {
throw new Error("Missing parmater: cost");
}

if (!params.ccy1) {
throw new Error("Missing parmater: ccy1");
}

if (Object.keys(params).length > 5) {
throw new Error("Call accepts the following parameters: walletid, address, cost, ccy1");
}
break;
}

const url = this.config.url[this.config.env] + path;
Expand Down Expand Up @@ -301,4 +330,10 @@ class CoinFluxClient {

}

function sorted(o) {
let p = Object.create(null);
for (const k of Object.keys(o).sort()) p[k] = o[k];
return p;
}

module.exports = CoinFluxClient;
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "coinflux-api",
"version": "0.0.4",
"version": "0.0.5",
"description": "coinflux.com API client library for NodeJS",
"keywords": [
"coinflux",
Expand Down

0 comments on commit 45e46cf

Please sign in to comment.