Skip to content

Instantly share code, notes, and snippets.

@evan-coygo
evan-coygo / example.js
Created November 20, 2019 22:48
Coygo API Setup
import { Coygo, SUPPORTED_EXCHANGE_IDS } from 'coygo-api';
const coygo = new Coygo({
apKey: '<coygo api key>',
exchanges: [
{
exchangeId: SUPPORTED_EXCHANGE_IDS.KRAKEN,
apikey: '<kraken api key>',
apiSecret: '<kraken api secret>'
},
// configure basic information about your bot strategy
coygo.configure({
// which types of orders this strategy supports
orderTypes: [
coygo.orderTypes.market, // this indicates your strategy uses market orders
coygo.orderTypes.limit // this indicates your strategy uses limit orders
]
});
// Create configurable input values for this Strategy. On the "Configure" screen you can use
// an interface to set these to whatever you'd like. This allows you to re-use the same Strategy
// configure basic information about your bot strategy
coygo.configure({
// which types of orders this strategy supports
orderTypes: [
coygo.orderTypes.limit // this indicates your strategy uses limit orders
]
});
// Create configurable input values for this Strategy. On the "Configure" screen you can use
// an interface to set these to whatever you'd like. This allows you to re-use the same Strategy
/*
Determine if orders should be submitted or cancelled
*/
let shouldSubmitBuyOrder = false;
let shouldCancelBuyOrder = false;
let shouldSubmitSellOrder = false;
let shouldCancelSellOrder = false;
// determine if it's time to submit or cancel the buy order
/*
Submit or cancel orders when appropriate
*/
// handle submiting or canceling the buy order when instructed
if (shouldSubmitBuyOrder) {
// calculate the buy order rate using configured inputs
// example: if "ask" is 100 and "buyRatePercentBelowAskInput" is 2, buyOrderRate = 100 * (1 - (2 / 100) = 98
let buyOrderRate = orderBook.ask * (1 - (buyRatePercentBelowAskInput / 100));