Skip to content
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

[FEATURE] Built-in variables to fetch/filter available sources (Exchange, Type, Currency) #321

Open
nl8-gh opened this issue May 24, 2023 · 6 comments
Labels
enhancement New feature or request

Comments

@nl8-gh
Copy link

nl8-gh commented May 24, 2023

Ask | Request:
Seeking built-in variable(s) to get / filter sources from within an indicator --> 'Exchange(s)' | 'Type' | 'Currency'

Context:
For custom indicators I want to do some math on an e.g. USD Perp for BTC on every supported Exchange.
Rather adding them manually / hardcode related sources, a built-in var allows better flexibillity & more.

Benefit:
a) Kinda "optimistic" & unified User eXperience since less skilled noobs / users often aren't aware that they need to tweak things (especially on older scripts they might have found).
b) developers can provide better defaults (or even, if supported, an option in settings to either use a custom selection only or "all available" (Exchanges | Types | Currencies)

@nl8-gh nl8-gh added the enhancement New feature or request label May 24, 2023
@adeacetis adeacetis changed the title Built-in variables to fetch/filter available sources (Exchange, Type, Currency) [FEATURE] Built-in variables to fetch/filter available sources (Exchange, Type, Currency) May 24, 2023
@lmvdz
Copy link
Contributor

lmvdz commented May 25, 2023

maybe something like this?

script variables:

sources - for all
sources.perp - for all sources with perp type
sources.futures - for all sources with futures type
sources.spot - for all sources with spot type
sources.exchange.BINANCE - for all sources from BINANCE exchange
sources.filter(source => source.exchange === 'BINANCE' && source.type === 'PERP') - maybe for customization

or just have a filter tab where you can select which sources similar to how the sources search works

@nl8-gh
Copy link
Author

nl8-gh commented May 26, 2023

Thats a great starter! I even didn't think about how to actually implement it.

Following is a brain dump of my wet dreams.
Please expand the below & sorry for the text wall.

Setting the stage
exists definition result comments
exchanges \ enabledExchanges BINANCE, BYBIT, PHEMEX, ...
baseSymbol BTC, ETH, ADA, XRP, ...
quoteSymbol USD, USDT, USDC, ...
type \ pair see 1
diesabledExchanges Any, Other, Whatever see 2
activatedExchanges (internal function) enabledExchanges reduced by diesabledExchanges see 3
assetClass Crypto see 4
use_baseCurrency true ? <use defined string && in UI show text field with its value to let users modify it)> : na see 5
baseCurrency use_baseCurrency ? <quoteSymbol converted to specified quoteSymbol> : quoteSymbol
Example json for overrides

Could easily be extended to e.g. override chart settings amongst other stuff you might want developers allow to hook into by code.

{
  "Settings_Override": {
    "Exchange_Overrides": {
      "enabledExchange": [
        "ALL || Default || Array (e.g. ['Binance_US', 'ANY', 'Other']"
      ],
      "disabledExchange": "ALL || Default || Array (e.g. ['Binance_US', 'ANY', 'Other'])"
    },
    "AssetType_Overrides": {
      "Futures": false,
      "Perpetual": true,
      "Spot": true
    },
    "Symbols": {
      "baseSymbol": "BTC",
      "quoteSymbol": [
        "ALL || Array (e.g.  'USD', 'USDT', 'USDC')"
      ]
    },
    "baseCurrency": {
      "enabled": true,
      "quoteSymbol": "USD"
    }
  }
}

This way, its easy to refer to enabledExchangeto get e.g. activatedExchanges.Openprice

Footnotes

  1. Consider to rename type to assetType and pair to ticker for better code readability/context by using commonly used definitions

  2. Allow setting override to specify one ore more Exchanges to exclude

  3. If an Exchange listed is not supported yet, ignore it. But this way the developer can ensure that, once the defined exchange(s) gets added, remains disabled by default - for whatever reason but at least to ensure the indicator remains working as designed.

  4. Get future proof so you can add Stocks, CFD, Forex, ... later

  5. Allow conversion of different quoteSymbols to a user defined baseCurrency (unless already done?!). Example: if enabled do convert BUSD, USDC (whatever is not matching the defined baseCurrency to e.g USD which would increase the accuracy of any related math (price, volume, ....).
    To take it to the max, an option to perform calculation to be done by either a) converting to the underlaying exchanges' USD value (to sstick with USD for this example) prior aggregting the numbers or b) convert to the baseSymbol (e.g. #BTC) , then aggregate the numbers from all selcted exchanges against the real global USD price)

@Tucsky
Copy link
Owner

Tucsky commented May 27, 2023

maybe something like this?

script variables:

Not like this because someone might want to filter on multiple exchange, or combine multiple filters (type + exchange)

What you want is a source() function
taking parameter like source({ type: 'perp', quote: 'USDT' })
source({ type: 'spot', exchange: 'BITFINEX' })

From there, in the script transpilation parse these function calls and store the filters somewhere then we are going to need a second step to the transpilation dedicated to transpile these calls into actual markets data path (bars.renderer.sources[...])
so that the script is not retranspiled in it's entierty each time we change the pane's sources

by default should result in the average of the ohlc based on the given filters
but in a more advanced version of that implementation we could imagine a second parameter mathing one of the source field (close, high, vbuy etc) to aggregate into

spotcvd = source({type: 'spot'}, 'vbuy') - source({type: 'spot'}, 'vsell')

How useful would that be 😄

Tucsky added a commit that referenced this issue May 28, 2023
Tucsky added a commit that referenced this issue May 28, 2023
@Tucsky
Copy link
Owner

Tucsky commented May 28, 2023

draw close of spot markets available on the pane

line(source(close, type='spot'))

draw candlestick of spot markets available

candlestick(avg_ohlc(source(type='spot')))

cvd per type

line(
  cum(source(vbuy, type=spot) - source(vsell, type=spot)),
  title=spot cvd,
  color=limegreen
)
line(
  cum(source(vbuy, type=perp) - source(vsell, type=perp)), 
  title=perp cvd,
  color=slateblue
)

draw heikinashi of BITFINEX spot markets only

candlestick(avg_heikinashi(source(exchange=BITFINEX, type=spot)))

@Tucsky
Copy link
Owner

Tucsky commented May 31, 2023

@nl8-gh the feature is available on https://tucsky.github.io/aggr for testing

@adeacetis
Copy link
Collaborator

Just a reminder that when, or if, this is approved, documentation will need to be updated here: https://github.com/Tucsky/aggr/wiki/Introduction-to-scripting

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants