Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save evan-coygo/8d8e63e2c6ffe25964631e173be94742 to your computer and use it in GitHub Desktop.
Save evan-coygo/8d8e63e2c6ffe25964631e173be94742 to your computer and use it in GitHub Desktop.
// 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
// code while using different exchanges, trade pairs, etc.
const exchangeInput = coygo.input({
type: coygo.inputTypes.exchange,
label: 'The exchange to use',
description: 'The exchange that this bot will trade on.'
});
const tradePairInput = coygo.input({
type: coygo.inputTypes.tradePair,
label: 'The trade pair to use',
description: 'The trade pair that this bot will trade on.'
});
const orderAmountInput = coygo.input({
type: coygo.inputTypes.number,
label: 'Order amount',
description: 'The amount for each order submitted',
min: 0
});
// buy orders use the "ask" rate that a seller is asking for
const buyRatePercentBelowAskInput = coygo.input({
type: coygo.inputTypes.number,
min: 0,
label: 'Buy order rate % below ask',
description: 'This determines the rate at which each buy order will be submitted. Buy orders will use a rate at a certain % below the current ask. **For example,** if this is set to zero buy orders will use the current ask rate. If this is set to 0.5, buy orders will use a rate at 0.5% below the ask rate.'
});
// sell orders use the "bid" rate that a buyer is bidding to buy
const sellRatePercentAboveBidInput = coygo.input({
type: coygo.inputTypes.number,
min: 0,
label: 'Sell rate % above bid',
description: 'This determines the rate at which each sell order will be submitted. Sell orders will use a rate at a certain % above the current bid. **For example,** if this is set to zero sell orders will use the current bid rate. If this is set to 0.5, sell orders will use a rate at 0.5% above the bid rate.'
});
const cancelOrderThresholdInput = coygo.input({
type: coygo.inputTypes.number,
label: 'Cancel order threshold %',
min: 0.1,
description: "If the difference between the current ask/bid rate and any open order's rate is greater than this percent, that order will be cancelledand re-submitted at a new price. **For example**, if this is set to 3 then any open orders with a rate > 3% away from the current ask/bid will be cancelled and re-submitted."
});
// set up a Market to interact with an exchange
const marketToUse = coygo.market({
exchange: exchangeInput,
baseSymbol: tradePairInput.baseSymbol,
quoteSymbol: tradePairInput.quoteSymbol
});
// access this trade pair's order book
const orderBook = coygo.orderBook({
market: marketToUse
});
let orderAmount = orderAmountInput;
if (marketToUse && marketToUse.baseSymbolDecimalCount) {
// set decimal count accordingly for this exchange's precision limits
orderAmount = parseFloat(orderAmount.toFixed(marketToUse.baseSymbolDecimalCount));
}
/*
Create persisted data to keep track of any orders or waiting status
*/
// there will always be one buy and one sell order open at any time. record them so we can access them in later intervals
const buyOrder = coygo.persistedData();
const sellOrder = coygo.persistedData();
// canceling an order can take a variable amount of time so we will record when we're waiting for a buy
// or sell order to be finish being canceled
const isWaitingForBuyToCancel = coygo.persistedData(false);
const isWaitingForSellToCancel = coygo.persistedData(false);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment