- Iris : Cardano DEX data aggregator
- Iris SDK : SDK for interacting with Iris
- Dexter : Cardano DEX swap aggregator
- Automate any trading strategy.
- Receive notifications on placed orders.
- Run backtests on historical data using Iris.
- Auto-cancel long pending orders.
npm i @sluder/breeze
yarn add @sluder/breeze
Breeze can be included in any application to provide automated Cardano DEX trading. Here is a snippet to instantiate a TradeEngine :
const engine: TradeEngine = new TradeEngine(
[
new CustomStrategy({
runEveryMilliseconds: 5 * 1000, // Strategy will run every 5 secs
autoCancelAfterSeconds: 60 * 5, // Orders will cancel after 5 mins
walletAccountIndex: 0, // Separate strategy balances within the same wallet
params: {
slippagePercent: 5,
// ... other parameters your strategy requires
},
}),
// ... other strategies
],
{
appName: 'TradingBot',
canSubmitOrders: true,
irisWebsocketHost: process.env.IRIS_WEBSOCKET_HOST ?? '',
irisApiHost: process.env.IRIS_API_HOST ?? '',
seedPhrase: process.env.SEED_PHRASE?.split(',') ?? [],
submissionProviderConfig: {
kupoUrl: (process.env.KUPO_SECURE === 'true' ? 'https://' : 'http://') + (process.env.KUPO_HOST ?? '') + ':' + process.env.KUPO_PORT,
ogmiosUrl: (process.env.OGMIOS_SECURE === 'true' ? 'https://' : 'http://') + (process.env.OGMIOS_HOST ?? '') + ':' + process.env.OGMIOS_PORT,
},
logDirectory: '../logs',
neverSpendAda: 10, // 10 ADA will never be spent & used as a buffer for network fees
backtest: { // Runs a local API server for submitting backtests
port: 9999,
enabled: true,
},
database: {
file: './src/database/bot.db',
},
notifications: {
notifiers: [
new SlackNotifier(process.env.SLACK_OAUTH_TOKEN ?? '', <
8000
span class="pl-s1">process.env.SLACK_CHANNEL_ID ?? ''),
],
},
}
);
await engine.boot();
All custom strategies must extend the BaseStrategy
interface, and is called upon automatically depending on the setup.
For acting on live websocket data, implement the onWebsocketMessage(message: WsResponse)
function to receive all DEX updates.
To run your strategy on a timer, implement the onTimer()
function which is called on an interval depending on the runEveryMilliseconds
.
All possible functions a strategy can implement from Breeze :
/**
* Strategy is being backtested. Do some set up.
*/
public beforeBacktest(app: TradeEngine, backtest: Backtest): Promise<any>;
/**
* Iris data is being pulled within this gap. Allows some data set up.
*/
public beforeDataPull(fromTimestamp: number, toTimestamp: number): Promise<any>;
/**
* Strategy is being shutdown. Cleanup.
*/
public onShutdown(app: TradeEngine): Promise<any>;
/**
* Receiving a new websocket message from Iris.
*/
public onWebsocketMessage(message: WsResponse): Promise<any>;
/**
* Runs on interval set on the engine configuration.
*/
public onTimer(): Promise<any>;
Breeze allows backtests to be ran on your custom strategies. To accomplish this, a connector service (API) is ran on your local instance that you can use as you see fit.
Note : All wallet balances can be mocked for a backtest, and does not use actual balances in your connected wallet.
GET /backtest
Health check
POST /backtest
Run a backtest
- fromTimestamp | int = Unix timestamp for historical data
- toTimestamp | int = Unix timestamp for historical data
- strategyName | string = Name of custom strategy to run test on
- initialBalances | Map<string, bigint> = Concatenated asset IDs with balance
- filteredAssets | string[] = = Concatenated asset IDs
GET /backtest/status
Status of current backtest
GET /backtest/orders
Orders would've been made in current backtest
GET /strategies
Retrieve list of possible strategies to run backtest on
Breeze supplies the ability to trigger Slack notifications on orders made from your bot. This repository includes a partial Twilio implementation, but is not complete due to difficult laws preventing easy access to SMS notifications. An alternate SMS service may be included at some point.
Developers of this package are not liable for the loss of any funds, or issues related to the loss of funds. Use at your own risk.
A word of advice is to always start with very low funds when testing a strategy, or when first using Breeze to ensure everything is working as it should.
Have fun building your bot ;)
This documentation provides an overview of all classes within the /src
directory, including their main responsibilities and key methods.
- Location:
src/TradeEngine.ts
- Description: The core orchestrator for trading strategies, jobs, and services. Manages configuration, logging, and the lifecycle of strategies and jobs.
- Key Methods:
boot()
,shutdown()
,logInfo()
,logError()
, and various getters for services and configuration.
- Location:
src/BaseStrategy.ts
- Description: Abstract base for trading strategies. Defines the interface and shared logic for all strategies.
- Location:
src/entities/Order.ts
- Description: Represents a trade order.
- Location:
src/entities/BacktestOrder.ts
- Description: Represents an order used in backtesting.
- Location:
src/entities/Backtest.ts
- Description: Represents a backtest session.
- Location:
src/storage/BaseCacheStorage.ts
- Description: Abstract cache storage interface.
- Key Methods:
boot()
,setKey()
,getKey()
,deleteKey()
,flushAll()
,keys()
- Location:
src/storage/NodeCacheStorage.ts
- Description: Implements cache storage using the
node-cache
library.
- Location:
src/services/WalletService.ts
- Description: Manages wallet loading, balance tracking, and integration with Lucid and Dexter.
- Location:
src/services/OrderService.ts
- Description: Handles order-related events, especially those from the websocket.
- Location:
src/services/NotificationService.ts
- Description: Sends notifications using configured notifiers.
- Location:
src/services/IndicatorService.ts
- Description: Provides access to various indicator modules (trend, volume, volatility, momentum).
- Location:
src/services/DatabaseService.ts
- Description: Manages the SQLite database connection and migrations. Provides access to query runners.
- Location:
src/services/ConnectorService.ts
- Description: Sets up and runs the Express API server, registering controllers for strategies and backtesting.
OrderQueryRunner
(src/services/runners/OrderQueryRunner.ts
): Runs queries related to orders.BacktestQueryRunner
(src/services/runners/BacktestQueryRunner.ts
): Runs queries related to backtests.
- Location:
src/notifiers/BaseNotifier.ts
- Description: Abstract base for notification services.
- Location:
src/notifiers/TwilioNotifier.ts
- Description: Sends notifications via Twilio SMS.
- Location:
src/notifiers/SlackNotifier.ts
- Description: Sends notifications to Slack channels.
- Location:
src/jobs/BaseJob.ts
- Description: Abstract base for scheduled jobs.
- Location:
src/jobs/AutoCancelJob.ts
- Description: Cancels orders that have not been settled within a configured time.
- Location:
src/indicators/BaseIndicator.ts
- Description: Abstract base for all indicator classes.
TrendIndicators
(src/indicators/trend/TrendIndicators.ts
): Provides SMA, EMA, TSMA, and TEMA calculations.SMA
(src/indicators/trend/sma.ts
): Simple Moving Average.EMA
(src/indicators/trend/ema.ts
): Exponential Moving Average.TSMA
(src/indicators/trend/tsma.ts
): Triple Simple Moving Average.TEMA
(src/indicators/trend/tema.ts
): Triple Exponential Moving Average.
VolumeIndicators
(src/indicators/volume/VolumeIndicators.ts
): Placeholder for volume-based indicators.
VolatilityIndicators
(src/indicators/volatility/VolatilityIndicators.ts
): Placeholder for volatility-based indicators.
MomentumIndicators
(src/indicators/momentum/MomentumIndicators.ts
): Placeholder for momentum-based indicators.
- Location:
src/api/BaseController.ts
- Description: Abstract base for API controllers.
- Location:
src/api/StrategyController.ts
- Description: API controller for strategy-related endpoints.
- Location:
src/api/BacktestController.ts
- Description: API controller for backtest-related endpoints.
For more details on each class, see the respective source files in /src
.