@elevenyellow.com/switchain-api-client
Advanced tools
Comparing version 0.2.0 to 1.0.0
{ | ||
"name": "@elevenyellow.com/switchain-api-client", | ||
"version": "0.2.0", | ||
"version": "1.0.0", | ||
"description": "client module to access switchains's api", | ||
@@ -26,2 +26,3 @@ "main": "index.js", | ||
"dependencies": { | ||
"chai-as-promised": "^7.1.1", | ||
"request": "^2.87.0", | ||
@@ -28,0 +29,0 @@ "request-promise": "^4.2.2" |
112
src/index.js
@@ -5,3 +5,3 @@ const request = require("request-promise"); | ||
exports.init = function({ apiKey }) { | ||
function init({ apiKey }) { | ||
return { | ||
@@ -22,30 +22,40 @@ getMarketInfo: () => getMarketInfo({ apiKey }), | ||
}; | ||
}; | ||
} | ||
exports.getMarketInfo = getMarketInfo = async function({ apiKey }) { | ||
async function getMarketInfo({ apiKey }) { | ||
const uri = `${apiUrl}marketinfo/`; | ||
const response = await request({ | ||
uri, | ||
headers: { Authorization: `Bearer ${apiKey}` }, | ||
json: true | ||
}); | ||
try { | ||
const response = await request({ | ||
uri, | ||
headers: { Authorization: `Bearer ${apiKey}` }, | ||
json: true | ||
}); | ||
// console.log("SwitchainApi.getOffer", { response }); | ||
// console.log("SwitchainApi.getOffer", { response }); | ||
return { info: response, error: null }; | ||
}; | ||
return response; | ||
} catch (error) { | ||
console.log(`switchainApiClient.getMarketInfo.error: ${error}`); | ||
throw error; | ||
} | ||
} | ||
exports.getOffer = getOffer = async function({ pair, apiKey }) { | ||
async function getOffer({ pair, apiKey }) { | ||
const uri = `${apiUrl}offer/`; | ||
const response = await request({ | ||
uri, | ||
headers: { Authorization: `Bearer ${apiKey}` }, | ||
qs: { pair }, | ||
json: true | ||
}); | ||
try { | ||
const response = await request({ | ||
uri, | ||
headers: { Authorization: `Bearer ${apiKey}` }, | ||
qs: { pair }, | ||
json: true | ||
}); | ||
return { offer: response, error: null }; | ||
}; | ||
return response; | ||
} catch (error) { | ||
console.log(`switchainApiClient.getOffer.error: ${error}`); | ||
throw error; | ||
} | ||
} | ||
exports.postOrder = postOrder = async function({ | ||
async function postOrder({ | ||
toAddress, | ||
@@ -59,30 +69,42 @@ refundAddress, | ||
const uri = `${apiUrl}order/`; | ||
const response = await request({ | ||
uri, | ||
method: "POST", | ||
body: { | ||
toAddress, | ||
refundAddress, | ||
pair, | ||
fromAmount, | ||
signature | ||
}, | ||
json: true, | ||
headers: { Authorization: `Bearer ${apiKey}` } | ||
}); | ||
try { | ||
const response = await request({ | ||
uri, | ||
method: "POST", | ||
body: { | ||
toAddress, | ||
refundAddress, | ||
pair, | ||
fromAmount, | ||
signature | ||
}, | ||
json: true, | ||
headers: { Authorization: `Bearer ${apiKey}` } | ||
}); | ||
// console.log({ response }); | ||
// console.log({ response }); | ||
return { order: response, error: null }; | ||
}; | ||
return response; | ||
} catch (error) { | ||
console.log(`switchainApiClient.postOrder.error: ${error}`); | ||
throw error; | ||
} | ||
} | ||
exports.getOrderStatus = getOrderStatus = async function({ orderId, apiKey }) { | ||
async function getOrderStatus({ orderId, apiKey }) { | ||
const uri = `${apiUrl}order/${orderId}`; | ||
const response = await request({ | ||
uri, | ||
headers: { Authorization: `Bearer ${apiKey}` }, | ||
json: true | ||
}); | ||
try { | ||
const response = await request({ | ||
uri, | ||
headers: { Authorization: `Bearer ${apiKey}` }, | ||
json: true | ||
}); | ||
return { status: response, error: null }; | ||
}; | ||
return response; | ||
} catch (error) { | ||
console.log(`switchainApiClient.getOrderStatus.error: ${error}`); | ||
throw error; | ||
} | ||
} | ||
module.exports = { init, getMarketInfo, getOffer, postOrder, getOrderStatus }; |
@@ -1,4 +0,15 @@ | ||
const { assert, expect } = require("chai"); | ||
const { getOffer, postOrder, getOrderStatus, init } = require("../src"); | ||
var chai = require("chai"); | ||
var chaiAsPromised = require("chai-as-promised"); | ||
chai.use(chaiAsPromised); | ||
const { assert, expect } = chai; | ||
const { | ||
getMarketInfo, | ||
getOffer, | ||
postOrder, | ||
getOrderStatus, | ||
init | ||
} = require("../src"); | ||
let apiKey; | ||
@@ -19,20 +30,27 @@ try { | ||
const result = await getMarketInfo({ apiKey }); | ||
console.log({ result }); | ||
expect(result.info).to.be.an("array"); | ||
// console.log({ result }); | ||
expect(result).to.be.an("array"); | ||
}); | ||
}); | ||
describe("getOffer", async function() { | ||
it("It gets an offer", async function() { | ||
it("It gets an offer for ETH-DAI", async function() { | ||
const pair = "ETH-DAI"; | ||
const result = await getOffer({ pair, apiKey }); | ||
// console.log({ result }); | ||
expect(result.offer.pair).to.be.equal(pair); | ||
expect(result.offer.signature).to.be.a("string"); | ||
expect(result.offer.quote).to.be.a("string"); | ||
expect(result.offer.maxLimit).to.be.a("string"); | ||
expect(result.offer.expiryTs).to.be.a("number"); | ||
expect(result.pair).to.be.equal(pair); | ||
expect(result.signature).to.be.a("string"); | ||
expect(result.quote).to.be.a("string"); | ||
expect(result.maxLimit).to.be.a("string"); | ||
expect(result.expiryTs).to.be.a("number"); | ||
}); | ||
it("It gets an offer for BTC-ETH", async function() { | ||
const pair = "BTC-ETH"; | ||
// const result = await getOffer({ pair, apiKey }); | ||
// console.log({ result }); | ||
expect(getOffer({ pair, apiKey })).to.be.rejected; | ||
}); | ||
}); | ||
describe("postOrder/getOrderStatus", async function() { | ||
xit("It posts an order and checks the status", async function() { | ||
it("It posts an order and checks the status", async function() { | ||
this.timeout(20000); | ||
@@ -42,3 +60,3 @@ const pair = "ETH-DAI"; | ||
const { signature } = offerResponse.offer; | ||
const { signature } = offerResponse; | ||
const toAddress = "0x668bf158d4A34A77145d2084C70a5B98b4280eDD"; | ||
@@ -58,13 +76,13 @@ const refundAddress = "0xb45166124a842ce57e1a86b7a975bb4effae1494"; | ||
expect(orderResponse.order.orderId).to.be.a("string"); | ||
expect(orderResponse.order.rate).to.be.a("string"); | ||
expect(orderResponse.order.exchangeAddress).to.be.a("string"); | ||
expect(orderResponse.order.toAddress).to.be.equal(toAddress); | ||
expect(orderResponse.order.refundAddress).to.be.equal(refundAddress); | ||
expect(orderResponse.order.fromAmount).to.be.equal(fromAmount); | ||
expect(orderResponse.orderId).to.be.a("string"); | ||
expect(orderResponse.rate).to.be.a("string"); | ||
expect(orderResponse.exchangeAddress).to.be.a("string"); | ||
expect(orderResponse.toAddress).to.be.equal(toAddress); | ||
expect(orderResponse.refundAddress).to.be.equal(refundAddress); | ||
expect(orderResponse.fromAmount).to.be.equal(fromAmount); | ||
const { orderId } = orderResponse.order; | ||
const { orderId } = orderResponse; | ||
const statusResponse = await getOrderStatus({ orderId, apiKey }); | ||
// console.log({ statusResponse }); | ||
expect(statusResponse.status.status).to.be.equal("waiting"); | ||
expect(statusResponse.status).to.be.equal("waiting"); | ||
}); | ||
@@ -78,9 +96,9 @@ }); | ||
// console.log({ result }); | ||
expect(result.offer.pair).to.be.equal(pair); | ||
expect(result.offer.signature).to.be.a("string"); | ||
expect(result.offer.quote).to.be.a("string"); | ||
expect(result.offer.maxLimit).to.be.a("string"); | ||
expect(result.offer.expiryTs).to.be.a("number"); | ||
expect(result.pair).to.be.equal(pair); | ||
expect(result.signature).to.be.a("string"); | ||
expect(result.quote).to.be.a("string"); | ||
expect(result.maxLimit).to.be.a("string"); | ||
expect(result.expiryTs).to.be.a("number"); | ||
}); | ||
}); | ||
}); |
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
7744
185
1
3
+ Addedchai-as-promised@^7.1.1
+ Addedassertion-error@2.0.1(transitive)
+ Addedchai@5.2.0(transitive)
+ Addedchai-as-promised@7.1.2(transitive)
+ Addedcheck-error@1.0.32.1.1(transitive)
+ Addeddeep-eql@5.0.2(transitive)
+ Addedget-func-name@2.0.2(transitive)
+ Addedloupe@3.1.3(transitive)
+ Addedpathval@2.0.0(transitive)