Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #1

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
17 changes: 17 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"env": {
"browser": true,
"commonjs": true,
"es2021": true
},
"extends": [
"standard"
],
"parserOptions": {
"ecmaVersion": 12
},
"rules": {
"semi": ["warn", "always"],
"qoutes": ["warn", "always"]
}
}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_module
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be node_modules

Suggested change
node_module
node_modules

.env
15 changes: 10 additions & 5 deletions client.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,29 @@
const crypto = require('crypto');
const https = require('https');
require('dotenv').config();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
require('dotenv').config();
const nconf = require('nconf');


const apiKey = "add api key here";
const privateKey = "add private key here";
const apiKey = process.env.API_KEY;
const privateKey = process.env.PRIVATE_KEY;
Comment on lines +5 to +6
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest using nconf over dotenv, it's far more "12 factor" and a better user experience.

Suggested change
const apiKey = process.env.API_KEY;
const privateKey = process.env.PRIVATE_KEY;
const ENV_SEPARATOR = '__';
const KEY = 'btcmarkets';
const ENV_PATTERN = new RegExp(`/^${KEY.toUpperCase()}${ENV_SEPARATOR}/`);
nconf
.env({
separator: ENV_SEPARATOR,
match: ENV_PATTERN,
lowerCase: true,
parseValues: true,
transform(obj) {
obj.key.replace(ENV_PATTERN, '');
return obj;
},
})
.argv({
apiKey: {
describe: 'prefix of all new packages created',
},
privateKey: {
describe: 'prefix of all new packages created',
}
});
const apiKey = nconf.get('apiKey');
const privateKey = nconf.get('privateKey');

Now the cli is used like this:

node client.js --apiKey=something --privateKey=another-thing

or

BTCMARKETS_API_KEY=something \
BTCMARKETS_API_PRIVATE=another-thing \
node client.js 

you'll also get :

node client.js --help

const baseUrl = "api.btcmarkets.net";

function postHttp (path, dataObj) {
const postHttp = (path, dataObj) => {
const data = JSON.stringify(dataObj);
const now = Date.now();
var message = path + "\n" + now + "\n";

if (data) {
message += data;
}

const signature = signMessage(privateKey, message);

let headers = {
"Accept": "application/json",
"Accept-Charset": "UTF-8",
'Content-Length': Buffer.byteLength(data),
"Content-Type": "application/json",
};

headers.apikey = apiKey;
headers.timestamp = now;
headers.signature = signature;
Expand All @@ -42,14 +47,14 @@ function postHttp (path, dataObj) {

};

function signMessage(secret, message) {
const signMessage = (secret, message) => {
var key = Buffer.from(secret, 'base64');
var hmac = crypto.createHmac('sha512', key);
var signature = hmac.update(message).digest('base64');
return signature;
}

function getOpenOrdersByMarket() {
const getOpenOrdersByMarket = () => {
const data = {
currency: 'AUD',
instrument: 'XRP',
Expand Down
1 change: 1 addition & 0 deletions node_modules/.bin/acorn

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

1 change: 1 addition & 0 deletions node_modules/.bin/eslint

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

1 change: 1 addition & 0 deletions node_modules/.bin/esparse

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

1 change: 1 addition & 0 deletions node_modules/.bin/esvalidate

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

1 change: 1 addition & 0 deletions node_modules/.bin/js-yaml

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

1 change: 1 addition & 0 deletions node_modules/.bin/node-which

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

1 change: 1 addition & 0 deletions node_modules/.bin/rimraf

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

1 change: 1 addition & 0 deletions node_modules/.bin/semver

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

22 changes: 22 additions & 0 deletions node_modules/@babel/code-frame/LICENSE

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

19 changes: 19 additions & 0 deletions node_modules/@babel/code-frame/README.md

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

167 changes: 167 additions & 0 deletions node_modules/@babel/code-frame/lib/index.js

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

57 changes: 57 additions & 0 deletions node_modules/@babel/code-frame/package.json

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

22 changes: 22 additions & 0 deletions node_modules/@babel/helper-validator-identifier/LICENSE

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

Loading