Crates.io | kapacitor-multi-indicator-batch-udf |
lib.rs | kapacitor-multi-indicator-batch-udf |
version | 0.1.1 |
source | src |
created_at | 2024-08-15 13:05:58.52641 |
updated_at | 2024-08-15 13:11:12.40853 |
description | A multi-indicator batch UDF for Kapacitor |
homepage | https://github.com/suitable-name/kapacitor-udf-indicator-batch-rs |
repository | https://github.com/suitable-name/kapacitor-udf-indicator-batch-rs |
max_upload_size | |
id | 1338686 |
size | 92,779 |
This project implements a User-Defined Function (UDF) for Kapacitor, providing batch processing capabilities for multiple financial indicators. Currently, it supports Exponential Moving Average (EMA) and Simple Moving Average (SMA) calculations and can be easily extended for other indicators.
Clone the repository:
git clone https://github.com/suitable-name/kapacitor-udf-indicator-batch-rs
cd kapacitor-multi-indicator-udf
Build / Install the project:
cargo build --release
or
sudo cargo install --path . --root /usr/local
Start the UDF server:
./target/release/kapacitor-multi-indicator-udf
By default, the server listens on /tmp/indicator-batch.sock
. You can specify a different socket path using the -s
or --socket
option:
./target/release/kapacitor-multi-indicator-udf -s /path/to/custom/socket.sock
Configure Kapacitor to use this UDF. Add the following to your Kapacitor configuration file:
[udfs]
[udfs.functions]
[udfs.functions.indicator]
socket = "/tmp/kapacitor-multi-indicator-udf"
timeout = "10s"
Use the UDF in your TICKscripts:
batch
|query('''
SELECT "EUR"
FROM "stocks"."autogen"."ticker_data"
''')
.period(1d)
// Process one day's worth of data
.every(1d)
// Run the batch every day
.offset(0s)
// Start from the earliest data available
.groupBy('ticker')
@indicators()
.type('EMA')
.field('last_price')
.as('last_price_ema')
.period(14)
.ticker_field('ticker')
|influxDBOut()
.database('stocks')
.retentionPolicy('autogen')
.measurement('Stocks_EMA_batch')
.tag('kapacitor', 'true')
type
: The type of indicator to calculate (EMA
or SMA
)period
: The period for the indicator calculationfield
: The field name in the incoming data to use for calculationsas
: The field name to use for the calculated indicator value in the outputticker_field
: The field name containing the ticker or symbol for the data pointTo run with debug logging:
RUST_LOG=debug ./target/release/kapacitor-multi-indicator-udf
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.