-
Notifications
You must be signed in to change notification settings - Fork 279
chart scripting for pro dashboard #1931
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
const [output, setOutput] = useState<any>(null) | ||
const [parseErrors, setParseErrors] = useState<any[]>([]) | ||
|
||
useEffect(() => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hooks inside if could break react
@@ -491,7 +492,8 @@ export function ProDashboardAPIProvider({ | |||
deleteDashboard: deleteDashboardWithConfirmation, | |||
saveDashboard, | |||
saveDashboardName, | |||
copyDashboard | |||
copyDashboard, | |||
setItems |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
better to create handler within context for new chart or reuse existing
Here's some quick improvements i can think of based on my pinescript experience
|
LlamaScript Documentation
1. Overview
LlamaScript is a simple, powerful scripting language designed for fetching, analyzing, and visualizing financial data from the DeFiLlama ecosystem. It allows users to perform complex calculations, compare metrics across protocols and chains, and generate custom charts directly from a text-based input.
The core of LlamaScript is built around:
plot()
command to visualize any resulting data series.2. Basic Syntax
Variables
You can assign any expression to a variable for later use. This is useful for keeping your scripts clean and avoiding re-fetching the same data.
Plotting
The primary way to visualize data is with the
plot()
function.plot(series, [label], [chartType], [color], [dashed], [group])
series
: The time-series data to plot. This is the only required argument.label
(optionalstring
): The name that appears in the chart legend.chartType
(optionalstring
): Type of chart. Supports'area'
(default) or'bar'
.color
(optionalstring
): A valid CSS color (e.g.,'#ff0000'
,'red'
).Example:
Arithmetic Operations
Standard arithmetic operators (
+
,-
,*
,/
) can be used between two time-series, or a time-series and a number. The operation is performed "element-wise" for each timestamp.Example:
3. Data Fetching
Data is fetched using dedicated functions that return a special "Llama Entity". You must then access a property on this entity to get the time-series data.
protocol(name, [chainName])
Fetches a protocol entity.
name
: The protocol's slug (e.g.,'aave-v2'
,'uniswap-v3'
).chainName
(optional): The slug of a chain (e.g.,'ethereum'
,'arbitrum'
) to get data for that specific deployment.Available Properties:
.tvl
,.volume
,.fees
,.revenue
,.mcap
,.price
,.medianApy
Example:
chain(name)
Fetches a chain entity.
name
: The chain's slug (e.g.,'ethereum'
,'solana'
).Available Properties:
.tvl
,.volume
,.fees
,.revenue
,.users
,.txs
,.activeUsers
,.newUsers
,.gasUsed
.aggregators
,.perps
,.bridgeAggregators
,.perpsAggregators
,.options
.bribes
,.tokenTax
Example:
token(id)
Fetches a token entity.
id
: The token's Coingecko ID (e.g.,'bitcoin'
,'ethereum'
).Available Properties:
.price
,.volume
,.marketCap
Example:
4. Analytical Functions
These functions take one or more arguments (often a time-series) and return a new, transformed time-series.
ma(series, window)
plot(ma(token('bitcoin').price, 50))
ema(series, window)
plot(ema(protocol('gmx').fees, 14))
DIFF(series)
plot(DIFF(chain('ethereum').fees))
abs(series)
plot(abs(RETURNS(token('solana').price)))
pctChange(series)
plot(pctChange(protocol('aave-v2').tvl))
RETURNS(series, [type])
plot(RETURNS(token('ethereum').price, 'log'))
cumSum(series)
plot(cumSum(protocol('uniswap-v3').revenue))
lag(series, n)
n
periods.plot(lag(token('bitcoin').price, 7))
zscore(series)
plot(zscore(protocol('dydx').volume))
normalize(series)
plot(normalize(protocol('aave-v2').tvl))
drawdown(series)
plot(drawdown(token('bitcoin').price))
rolling(series, window, func)
func
can be'mean'
,'sum'
, or'stddev'
.plot(rolling(chain('ethereum').fees, 30, 'stddev'))
resample(series, interval)
plot(resample(token('bitcoin').price, 604800))
(weekly)clip(series, min, max)
min
-max
range.plot(clip(token('bitcoin').price, 20000, 30000))
if(condition, then, else)
condition
is true, returnsthen
, otherwiseelse
. Works element-wise.p = token('btc').price; plot(if(p > 60000, p, null))
sum(series)
MEAN(series)
MEDIAN(series)
MAX(series)
min(series)
STDDEV(series)
// Mostly useful as inputs to other functions
5. Chart Annotations
hline(value, [label])
value
.hline(5000000000, '5B TVL Level')
vline(timestamp, [label])
timestamp
.vline(1679529600, 'ARB Airdrop')