Skip to content

Commit

Permalink
add get price
Browse files Browse the repository at this point in the history
  • Loading branch information
thanhson1085 committed Apr 27, 2020
1 parent 4589196 commit 30ab5a0
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tomojs",
"version": "1.1.0",
"version": "1.1.1",
"description": "TomoChain JS SDK",
"keywords": [
"posv",
Expand Down
76 changes: 76 additions & 0 deletions tomox.js
Original file line number Diff line number Diff line change
Expand Up @@ -1563,6 +1563,82 @@ class TomoX {
})
}

async getCurrentEpochPrice (baseToken, quoteToken) {
return new Promise(async (resolve, reject) => {

try {
const jsonrpc = {
jsonrpc: '2.0',
method: 'tomox_getCurrentEpochPrice',
params: [ baseToken, quoteToken ],
id: 1
}

let url = urljoin(this.endpoint)
let options = {
method: 'POST',
url: url,
json: true,
headers: {
'content-type': 'application/json'
},
body: jsonrpc
}
request(options, (error, response, body) => {
if (error) {
return reject(error)
}
if (response.statusCode !== 200 && response.statusCode !== 201) {
return reject(body)
}

return resolve(body.result)

})
} catch(e) {
return reject(e)
}
})
}

async getLastEpochPrice (baseToken, quoteToken) {
return new Promise(async (resolve, reject) => {

try {
const jsonrpc = {
jsonrpc: '2.0',
method: 'tomox_getLastEpochPrice',
params: [ baseToken, quoteToken ],
id: 1
}

let url = urljoin(this.endpoint)
let options = {
method: 'POST',
url: url,
json: true,
headers: {
'content-type': 'application/json'
},
body: jsonrpc
}
request(options, (error, response, body) => {
if (error) {
return reject(error)
}
if (response.statusCode !== 200 && response.statusCode !== 201) {
return reject(body)
}

return resolve(body.result)

})
} catch(e) {
return reject(e)
}
})
}

}

module.exports = TomoX

0 comments on commit 30ab5a0

Please sign in to comment.