Skip to content

Instantly share code, notes, and snippets.

@Alirun
Last active April 23, 2020 21:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Alirun/cd0c9a30d5fdea3f8ed314da5146e581 to your computer and use it in GitHub Desktop.
Save Alirun/cd0c9a30d5fdea3f8ed314da5146e581 to your computer and use it in GitHub Desktop.
SwapRate SDK Release: Example short
// Retrieve SwapRate configuration and get the DAI's address and maturity of swaps in 3 month
const { tokenAddress, maturity } = await findTokenAndMaturity()
// Find product with DAI token
const product = await findProduct(tokenAddress)
// Connect to charts (curves) updates to react on changes in the market
api.onCharts(charts => {
// Find quote for the desired maturity
const quote = charts.d.receiveFixed.find(data => data.timestamp === maturity).value
// If current quote on product is more than or equal desired, place an order to pick it up
if (quote >= quoteGte) {
placeOrder(product.productId, quote, maturity)
}
})
api.subscribeCharts(product.productId)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment