-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e84d917
commit 3fa1085
Showing
2 changed files
with
67 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,52 @@ | ||
class Api { | ||
constructor({endpoint, passphrase}) { | ||
this.endpoint = endpoint; | ||
this.passphrase = passphrase; | ||
} | ||
|
||
_request(data) { | ||
return fetch(this.endpoint, { | ||
method: 'post', | ||
body: JSON.stringify(data) | ||
}).then(res => res.json()); | ||
} | ||
|
||
async _userpass() { | ||
const {userpass} = await this._request({ | ||
method: 'passphrase', | ||
passphrase: this.passphrase | ||
}); | ||
|
||
return userpass; | ||
} | ||
|
||
async request(data) { | ||
if (!this.userpass) { | ||
this.userpass = await this._userpass(); | ||
} | ||
|
||
return this._request(Object.assign({}, data, {userpass: this.userpass})); | ||
} | ||
|
||
botList() { | ||
return this.request({method: 'bot_list'}); | ||
} | ||
|
||
enableCoin(coin) { | ||
return this.request({method: 'enable', coin}); | ||
} | ||
|
||
portfolio() { | ||
return this.request({method: 'portfolio'}); | ||
} | ||
|
||
coins() { | ||
return this.request({method: 'getcoins'}); | ||
} | ||
|
||
ticker() { | ||
return this.request({method: 'ticker'}); | ||
} | ||
} | ||
|
||
export default Api; |
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