-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
initial setup and added deals endpoints
- Loading branch information
Showing
7 changed files
with
223 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# http://editorconfig.org | ||
root = true | ||
|
||
[*] | ||
charset = utf-8 | ||
end_of_line = lf | ||
indent_size = 2 | ||
indent_style = space | ||
insert_final_newline = true | ||
max_line_length = 80 | ||
trim_trailing_whitespace = true | ||
|
||
[*.md] | ||
max_line_length = 0 | ||
trim_trailing_whitespace = false | ||
|
||
[COMMIT_EDITMSG] | ||
max_line_length = 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. | ||
.idea | ||
|
||
# dependencies | ||
/node_modules | ||
/.pnp | ||
.pnp.js | ||
|
||
# testing | ||
/coverage | ||
|
||
# production | ||
/build | ||
|
||
# misc | ||
.DS_Store | ||
.env.local | ||
.env.development.local | ||
.env.test.local | ||
.env.production.local | ||
|
||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# 3commas API NodeJs wrapper | ||
|
||
NodeJS wrapper for [Official 3commas API](https://github.com/3commas-io/3commas-official-api-docs/) | ||
|
||
⚠️ Currently work in progress ⚠️ | ||
|
||
[3commas.io](https://3commas.io/?c=3cnode) is collection of smart tools for cryptocurrency traders and investors to minimize risks, limit losses, grow profits, and manage their trades and portfolios across multiple exchanges. | ||
|
||
--- | ||
|
||
## How to use | ||
|
||
### Set up | ||
|
||
Add node module using npm or yarn | ||
|
||
```bash | ||
npm install --save https://github.com/rentorm/3commas-api-node/tarball/master | ||
``` | ||
|
||
or | ||
|
||
```bash | ||
yarn add https://github.com/rentorm/3commas-api-node/tarball/master | ||
``` | ||
|
||
### Using in your project | ||
|
||
add module import to your script and provide API credentials | ||
|
||
```js | ||
const threeCommasAPI = require('3commas-api-node') | ||
|
||
const api = new threeCommasAPI({ | ||
apiKey: '', | ||
apiSecret: '' | ||
}) | ||
``` | ||
|
||
see `example.js` for more details | ||
|
||
## To do | ||
|
||
- [x] add deals endpoints | ||
- [ ] add bots endpoints | ||
- [ ] add smart trades endpoints | ||
- [ ] add accounts endpoints | ||
|
||
--- | ||
|
||
by me a beer 🍺 | ||
|
||
BTC: 37N2MSShWExJGsKuAvBs9GEteUTrhZyvCi | ||
ETH: 0x9F5e35e7DCa77A6Ec7a307213C5F65bc6d010088 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
const threeCommasAPI = require('3commas-api-node') | ||
|
||
const api = new threeCommasAPI({ | ||
apiKey: '', | ||
apiSecret: '' | ||
}) | ||
|
||
// get last 20 active deals | ||
const showActiveDeals = async () => { | ||
let data = await api.getDeals({ | ||
limit: 20, | ||
scope: 'active', | ||
}) | ||
console.log(data) | ||
} | ||
|
||
showActiveDeals() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
'use strict' | ||
const querystring = require('querystring'); | ||
const crypto = require('crypto') | ||
const fetch = require('node-fetch') | ||
|
||
const API_URL = 'https://3commas.io' | ||
|
||
class threeCommasAPI { | ||
constructor(opts = {}) { | ||
this._url = opts.url || API_URL | ||
this._apiKey = opts.apiKey || '' | ||
this._apiSecret = opts.apiSecret || '' | ||
} | ||
|
||
generateSignature (requestUri, reqData) { | ||
const request = requestUri + reqData | ||
return crypto.createHmac('sha256', this._apiSecret).update(request).digest('hex') | ||
} | ||
|
||
async makeRequest (method, path, params) { | ||
if (!this._apiKey || !this._apiSecret) { | ||
return new Error('missing api key or secret') | ||
} | ||
|
||
const sig = this.generateSignature(path, querystring.stringify(params)) | ||
|
||
try { | ||
let response = await fetch( | ||
`${this._url}${path}${querystring.stringify(params)}`, | ||
{ | ||
method: method, | ||
timeout: 30000, | ||
agent: '', | ||
headers: { | ||
'APIKEY': this._apiKey, | ||
'Signature': sig | ||
} | ||
} | ||
) | ||
|
||
return await response.json() | ||
} catch (e) { | ||
console.log(e); | ||
return false | ||
} | ||
} | ||
|
||
async getDeals (params) { | ||
return await this.makeRequest('GET', '/public/api/ver1/deals?', params) | ||
} | ||
|
||
async dealUpdateMaxSafetyOrders (deal_id, max_safety_orders) { | ||
return await this.makeRequest('POST', `/public/api/ver1/deals/${deal_id}/update_max_safety_orders?`, { deal_id, max_safety_orders }) | ||
} | ||
|
||
async dealPanicSell (deal_id) { | ||
return await this.makeRequest('POST', `/public/api/ver1/deals/${deal_id}/panic_sell?`, { deal_id }) | ||
} | ||
|
||
async dealCancel (deal_id) { | ||
return await this.makeRequest('POST', `/public/api/ver1/deals/${deal_id}/cancel?`, { deal_id }) | ||
} | ||
|
||
async dealUpdateTp (deal_id, new_take_profit_percentage) { | ||
return await this.makeRequest('POST', `/public/api/ver1/deals/${deal_id}/update_tp?`, { deal_id, new_take_profit_percentage }) | ||
} | ||
|
||
async getDeal (deal_id) { | ||
return await this.makeRequest('GET', `/public/api/ver1/deals/${deal_id}/show?`, { deal_id }) | ||
} | ||
|
||
} | ||
|
||
module.exports = threeCommasAPI |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
"name": "3commas-api-node", | ||
"version": "0.1.0", | ||
"description": "3commas API NodeJS wrapper", | ||
"main": "index.js", | ||
"engines": { | ||
"node": ">=8" | ||
}, | ||
"keywords": [ | ||
"3commas", | ||
"nodejs", | ||
"wrapper", | ||
"bots", | ||
"trading" | ||
], | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/rentorm/3commas-api-node.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/rentorm/3commas-api-node/issues" | ||
}, | ||
"author": "Rento", | ||
"license": "gpl-3.0", | ||
"dependencies": { | ||
"node-fetch": "^2.3.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. | ||
# yarn lockfile v1 | ||
|
||
|
||
node-fetch@^2.3.0: | ||
version "2.3.0" | ||
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.3.0.tgz#1a1d940bbfb916a1d3e0219f037e89e71f8c5fa5" | ||
integrity sha512-MOd8pV3fxENbryESLgVIeaGKrdl+uaYhCSSVkjeOb/31/njTpcis5aWfdqgNlHIrKOLRbMnfPINPOML2CIFeXA== |