Skip to content

Instantly share code, notes, and snippets.

@Fyzu
Last active November 20, 2024 15:55
Show Gist options
  • Save Fyzu/d82d8a5778c91f5ca116ea22035263e9 to your computer and use it in GitHub Desktop.
Save Fyzu/d82d8a5778c91f5ca116ea22035263e9 to your computer and use it in GitHub Desktop.
dxLink CHART Service
interface DXLinkChartIndicator {
lang: string
content: string
}
interface IndicatorParameter {
type: 'number' | 'string' | 'boolean'
name: string
}
interface DXLinkIndicatorState {
enabled: boolean
error?: string
inParameters?: IndicatorParameter[],
outParameters?: IndicatorParameter[]
}
const indicators: Record<string, DXLinkChartIndicator> = {
sma: {
lang: "dxScript",
content: "in depth = 10;out sma = sma(close, depth)"
}
}
const chart = new DXLinkChart({ indicators })
chart.addIndicatorsStateListener((indicatorsState: Record<string, DXLinkIndicatorState>) => {
// ...
})
interface DXLinkChartSubscription {
symbol: string
fromTime: number
}
interface DXLinkInboundIndicatorsParameters {
[key: string]: {
[key: string]: number
}
}
const subscription: DXLinkChartSubscription = {
symbol: "AAPL{=d}",
fromTime: 0
}
const parameters: DXLinkInboundIndicatorsParameters = {
sma: {
depth: 14
}
}
chart.setSubscription(subscription, parameters)
interface DXLinkChartSetup {
acceptAggregationPeriod: number,
acceptDataFormat: 'FULL'
acceptCandleFields: string[]
}
const setup: DXLinkChartSetup = {
acceptAggregationPeriod: 1,
acceptDataFormat: 'FULL',
acceptCandleFields: ['open', 'close', 'high', 'low', 'volume']
}
interface DXLinkChartConfig {
aggregationPeriod: number,
dataFormat: 'FULL'
candleFields: string[]
}
chart.setup(setup)
chart.addConfigListener((config: DXLinkChartConfig) => {
// ...
})
chart.removeIndicators(['sma'])
interface DXLinkChartCandle {
time: number
open: number
close: number
high: number
low: number
volume: number
}
interface DXLinkChartIndicatorsResults {
[key: string]: {
[key: string]: number[]
}
}
chart.addDataListener((candles: DXLinkChartCandle[], indicatorsResults: DXLinkChartIndicatorsResults, reset: boolean, pending: boolean) => {
// ...
})
{
"type": "CHANNEL_REQUEST",
"channel": 5,
"service": "CHART",
"parameters": {
"indicators": {
"indi-1": {
"lang": "dxScript",
"content": "in depth = 14; out sma = sma(close, depth)"
},
"indi-2": {
"lang": "dxScript",
"content": "in depth = 14; out sma = sma(close, depth)"
},
"indi-3": {
"lang": "dxScript",
"content": "in depth = 14; out sma = sma(close, depth)"
}
}
}
}
{
"type": "CHANNEL_OPENED",
"channel": 5,
"service": "CHART",
"parameters": {
"indicators": {
"indi-1": {
"lang": "dxScript",
"content": "in depth = 14; out sma = sma(close, depth)"
},
"indi-2": {
"lang": "dxScript",
"content": "in depth = 14; out sma = sma(close, depth)"
},
"indi-3": {
"lang": "dxScript",
"content": "in depth = 14; out sma = sma(close, depth)"
}
}
}
}
{
"type": "CHART_INDICATORS",
"channel": 5,
"indicators": {
"indi-1": {
"enabled": true
"inParameters": [{ "type": "number", "name": "depth", "defaultValue": 14 }],
"outParameters": [{ "type": "number", "name": "sma" }]
},
"indi-2": {
"enabled": false,
"error": "Max compilation time exceeded, compilation took more than 400ms"
},
"indi-3": {
"enabled": false,
"error": "1[1:19]: syntax error: [@7,18:18=',',<47>,1:18]"
},
"indi-4": {
"enabled": true,
"inParameters": [],
"outParameters": [
{ "type": "number", "name": "close" },
{ "type": "number", "name": "open" }
]
}
}
}
{
"type": "CHART_SUBSCRIPTION",
"channel": 5,
"subscription": {
"symbol": "AAPL{=d}",
"fromTime": 0
},
"indicatorsParameters": {
"indi-1": {
"depth": 3
}
}
}
{
"type": "CHART_CONFIG",
"channel": 5,
"aggregationPeriod": 1.0,
"dataFormat": "FULL",
"candleFields": ["open", "high", "close", "index"]
}
{
"type": "CHART_DATA",
"channel": 5,
"reset": true,
"pending": true,
"candles": [
{"open": 12, "high": 13, "close": 14, "index": "123123123"},
{"open": 12, "high": 13, "close": 14, "index": "123123123"},
{"open": 12, "high": 13, "close": 14, "index": "123123123"},
{"open": 12, "high": 13, "close": 14, "index": "123123123"}
],
"indicators": {
"indi-1": {
"sma": [null, null, 12, 13]
},
"indi-4": {
"close": [14, 14, 14, 14],
"open": [12, 12, 12, 12]
}
}
}
{
"type": "CHART_DATA",
"channel": 5,
"reset": false,
"pending": false,
"candles": [
{"open": 12, "high": 13, "close": 14, "index": "123123123"},
],
"indicators": {
"indi-1": {
"sma": [13]
},
"indi-4": {
"close": [14, 14, 14, 14],
"open": [12, 12, 12, 12]
}
}
}
{
"type": "CHART_SETUP",
"channel": 5,
"acceptAggregationPeriod": 1.0,
"acceptDataFormat": "FULL",
"acceptCandleFields": ["open", "high", "close", "index"]
}
{
"type": "CHART_INDICATORS_REMOVE",
"channel": 5,
"remove": ["indi-1"]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment