Crates.io | kapacitor-multi-indicator-stream-udf |
lib.rs | kapacitor-multi-indicator-stream-udf |
version | 0.1.1 |
source | src |
created_at | 2024-08-15 13:15:12.56955 |
updated_at | 2024-08-15 15:15:03.211009 |
description | A multi-indicator stream UDF for Kapacitor |
homepage | https://github.com/suitable-name/kapacitor-udf-indicator-stream-rs |
repository | https://github.com/suitable-name/kapacitor-udf-indicator-stream-rs |
max_upload_size | |
id | 1338712 |
size | 91,638 |
This project implements a User-Defined Function (UDF) for Kapacitor, providing streaming 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-stream-rs>
cd kapacitor-multi-indicator-stream-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-stream-udf
By default, the server listens on /tmp/indicator-stream.sock
. You can specify a different socket path using the -s
or --socket
option:
./target/release/kapacitor-multi-indicator-stream-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_stream]
socket = "/tmp/kapacitor-multi-indicator-stream-udf"
timeout = "10s"
Use the UDF in your TICKscripts:
stream
|from()
.measurement('ticker_data')
@indicator_stream()
.type('EMA')
.field('last_price')
.as('last_price_ema')
.period(14)
.ticker_field('ticker')
|influxDBOut()
.database('stocks')
.retentionPolicy('autogen')
.measurement('Stocks_EMA_stream')
.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-stream-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.