Last active
April 23, 2020 21:36
-
-
Save Alirun/cd0c9a30d5fdea3f8ed314da5146e581 to your computer and use it in GitHub Desktop.
SwapRate SDK Release: Example short
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
// 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