fix(price): Refactored price and integration tests

This commit is contained in:
Chris Troutner
2025-11-17 10:13:53 -08:00
parent 857b57240e
commit 4dabdac792
3 changed files with 0 additions and 127 deletions
-89
View File
@@ -29,21 +29,6 @@ class Price {
this.axios = axios
}
// This endpoint is deprecated. Documentation removed.
// async current (currency = 'usd') {
// try {
// const response = await this.axios.get(
// `https://index-api.bitcoin.com/api/v0/cash/price/${currency.toLowerCase()}`
// )
// // console.log(`response.data: ${JSON.stringify(response.data, null, 2)}`)
//
// return response.data.price
// } catch (err) {
// if (err.response && err.response.data) throw err.response.data
// else throw err
// }
// }
/**
* @api price.getUsd() getUsd()
* @apiName Price getUsd()
@@ -122,80 +107,6 @@ class Price {
}
}
/**
* @api price.getBchaUsd() getBchaUsd()
* @apiName Price getBchaUsd()
* @apiGroup Price
* @apiDescription Return current price of BCHA in USD.
* This endpoint gets the USD price of XEC from the Coinex API. The price
* denominated in BCHA comes from bch-api, so it has a better chance of
* working in Tor.
*
* @apiExample Example usage:
*(async () => {
* try {
* let current = await bchjs.Price.getBchaUsd();
* console.log(current);
* } catch(err) {
* console.error(err)
* }
*})()
*
* // 212.34
*/
async getBchaUsd () {
try {
const response = await this.axios.get(
`${this.restURL}price/bchausd`,
this.axiosOptions
)
// console.log(`response.data: ${JSON.stringify(response.data, null, 2)}`)
const bchaPrice = response.data.usd * 1000000
// Convert XEC denomination to BCHA denomination
return bchaPrice
} catch (err) {
if (err.response && err.response.data) throw err.response.data
else throw err
}
}
/**
* @api price.getXecUsd() getXecUsd()
* @apiName Price getXecUsd()
* @apiGroup Price
* @apiDescription Return current price of XEC in USD.
* This endpoint gets the USD price of XEC from the Coinex API. The price
* comes from bch-api, so it has a better chance of working in Tor.
*
* @apiExample Example usage:
*(async () => {
* try {
* let current = await bchjs.Price.getXecUsd();
* console.log(current);
* } catch(err) {
* console.error(err)
* }
*})()
*
* // 0.00021234
*/
async getXecUsd () {
try {
const response = await this.axios.get(
`${this.restURL}price/bchausd`,
this.axiosOptions
)
// console.log(`response.data: ${JSON.stringify(response.data, null, 2)}`)
return response.data.usd
} catch (err) {
if (err.response && err.response.data) throw err.response.data
else throw err
}
}
/**
* @api price.getBchUsd() getBchUsd()
* @apiName Price getBchUsd()
-1
View File
@@ -385,7 +385,6 @@ describe('#ElectrumX', () => {
assert.isAbove(sortedTransactions[0].height, sortedTransactions[1].height)
})
})
})
function sleep (ms) {
-37
View File
@@ -8,33 +8,6 @@ describe('#price', () => {
if (process.env.IS_USING_FREE_TIER) await sleep(1500)
})
// describe('#current', () => {
// describe('#single currency', () => {
// it('should get current price for single currency', async () => {
// const result = await bchjs.Price.current('usd')
// assert.notEqual(0, result)
// })
// })
// })
describe('#getUsd', () => {
it('should get the USD price of BCH', async () => {
const result = await bchjs.Price.getUsd()
// console.log(result)
assert.isNumber(result)
})
})
describe('#getBchaUsd', () => {
it('should get the USD price of BCHA', async () => {
const result = await bchjs.Price.getBchaUsd()
console.log(result)
assert.isNumber(result)
})
})
describe('#getBchUsd', () => {
it('should get the USD price of BCH', async () => {
const result = await bchjs.Price.getBchUsd()
@@ -44,16 +17,6 @@ describe('#price', () => {
})
})
describe('#rates', () => {
it('should get the price of BCH in several currencies', async () => {
const result = await bchjs.Price.rates()
// console.log(result)
assert.property(result, 'USD')
assert.property(result, 'CAD')
})
})
describe('#getPsffppPrice', () => {
it('should get the price of BCH in several currencies', async () => {
const result = await bchjs.Price.getPsffppPrice()