Skip to main content

tradingview/chart/
study.rs

1use serde::{Deserialize, Serialize};
2use serde_json::Value;
3use std::collections::HashMap;
4use ustr::Ustr;
5
6use crate::pine_indicator::PineIndicator;
7
8/// An input value for a Pine Script indicator.
9///
10/// Can be either a plain string or a structured [`InputValue`] with value,
11/// format, and type fields.
12#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13#[serde(untagged)]
14pub enum IndicatorInput {
15    String(Ustr),
16    IndicatorInput(InputValue),
17}
18
19/// Structured indicator input with value, format, and type metadata.
20#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
21pub struct InputValue {
22    pub v: Value,
23    pub f: Value,
24    pub t: Value,
25}
26
27impl InputValue {
28    pub fn new(v: Value, f: Value, t: Value) -> InputValue {
29        InputValue { v, f, t }
30    }
31}
32
33/// A study configuration for a chart session.
34///
35/// - `Builtin` — A TradingView built-in indicator identified by name with
36///   key-value parameters.
37/// - `Pine` — A user-created or community Pine Script indicator.
38#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
39pub enum StudyConfiguration {
40    Builtin(String, HashMap<String, String>),
41    Pine(Box<PineIndicator>),
42}