Last active
February 4, 2023 10:11
-
-
Save zushenyan/f5787c2e0b9767afacf71693cc85c496 to your computer and use it in GitHub Desktop.
tv bug report
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE HTML> | |
<html> | |
<head> | |
<title>TradingView Trading Terminal demo</title> | |
<meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,minimum-scale=1.0"> | |
<script type="text/javascript" src="charting_library/charting_library.standalone.js"></script> | |
<script type="text/javascript" src="datafeeds/udf/dist/bundle.js"></script> | |
<script type="text/javascript"> | |
const tvKey = "tv-tp" | |
const DefaultResolutions = ['1S', '1', '3', '5', '15', '30', '60', '120', '240', '360', '480', '720', '1D', '3D', '1W', '1M'] | |
const exchange = 'exc' | |
const symbols = { | |
'AAPL': { | |
symbol: 'AAPL', | |
full_name: 'AAPL', | |
ticker: 'AAPL', | |
type: 'Spot', | |
exchange, | |
pricescale: 100, | |
description: '', | |
} | |
} | |
const timestamps = [1669161600000, 1669248000000, 1669334400000, 1669420800000, 1669507200000, 1669593600000] | |
const history = timestamps.map((time, _i) => { | |
const i = _i + 1 | |
return { | |
time, | |
open: 50 * i, | |
high: 100 * i, | |
low: 10 * i, | |
close: 25 * i, | |
volume: 10 * i | |
} | |
}) | |
function initOnReady() { | |
widget = window.tvWidget = new TradingView.widget({ | |
fullscreen: true, | |
symbol: 'AAPL', | |
interval: '1D', | |
container: "tv_chart_container", | |
library_path: "charting_library/", | |
locale: "en", | |
timezone: Intl.DateTimeFormat().resolvedOptions().timeZone, | |
disabled_features: [ "order_panel", "trading_account_manager", 'right_toolbar', 'buy_sell_buttons' ], | |
enabled_features: [ "header_screenshot" ], | |
datafeed: { | |
onReady: (cb) => { | |
setTimeout(() => { | |
cb({ | |
exchanges: [{ name: exchange, value: exchange, desc: '' }], | |
symbols_types: [{ name: 'spot', value: 'Spot' }], | |
supported_resolutions: DefaultResolutions, | |
supports_marks: false, | |
supports_timescale_marks: false, | |
supports_time: true, | |
}) | |
}, 0) | |
}, | |
resolveSymbol: (symbolName, onResolve, onError) => { | |
const info = symbols[symbolName] | |
if (!info) { | |
onError(`error ${symbolName}`) | |
return | |
} | |
const result = { | |
description: info.description || '', | |
fractional: false, | |
has_seconds: true, | |
seconds_multipliers: ['1'], | |
has_intraday: true, | |
has_daily: true, | |
has_weekly_and_monthly: true, | |
minmov: 1, | |
minmove2: 0, | |
name: info.symbol, | |
full_name: info.fullName, | |
ticker: info.ticker, | |
timezone: 'Etc/UTC', | |
pricescale: info.pricescale, | |
session: '24x7', | |
type: info.type || '', | |
exchange: info.exchange || '', | |
listed_exchange: info.exchange || '', | |
format: 'price', | |
supported_resolutions: DefaultResolutions, | |
} | |
setTimeout(() => { | |
onResolve(result) | |
}, 0) | |
}, | |
searchSymbols: (userInput, exchange, symbolType, cb) => { | |
const result = Object.keys(symbols).map(v => symbols[v]) | |
cb(result) | |
}, | |
getBars: (symbolInfo, resolution, periodParams, onHistoryCb, onErrorCb) => { | |
const { firstDataRequest } = periodParams | |
const bars = history | |
onHistoryCb(firstDataRequest ? history : [], { noData: !firstDataRequest }) | |
}, | |
subscribeBars: () => {}, | |
unsubscribeBars: () => {}, | |
getQuotes: (symbols, onDataCallback, onErrorCallback) => { | |
onDataCallback([ | |
{ | |
s: 'ok', | |
n: 'AAPL', | |
v: { | |
ch: 0, | |
chp: 0, | |
short_name: 'AAPL', | |
exchange: "", | |
original_name: 'AAPL', | |
description: "AAPL", | |
lp: 173.68, | |
ask: 173.68, | |
bid: 173.68, | |
open_price: 173.68, | |
high_price: 173.68, | |
low_price: 173.68, | |
prev_close_price: 172.77, | |
volume: 173.68 | |
} | |
} | |
]) | |
}, | |
subscribeQuotes: (symbols, fastSymbols, onRealtimeCallback, listenerGUID) => { | |
onRealtimeCallback([ | |
{ | |
s: 'ok', | |
n: 'AAPL', | |
v: { | |
ch: 0, | |
chp: 0, | |
short_name: 'AAPL', | |
exchange: "", | |
original_name: 'AAPL', | |
description: "AAPL", | |
lp: 173.68, | |
ask: 173.68, | |
bid: 173.68, | |
open_price: 173.68, | |
high_price: 173.68, | |
low_price: 173.68, | |
prev_close_price: 172.77, | |
volume: 173.68 | |
} | |
} | |
]) | |
}, | |
unsubscribeQuotes: (listenerGUID) => {}, | |
}, | |
broker_factory: (host) => { | |
gHost = host | |
return { | |
positions: async () => [], | |
orders: async () => [], | |
executions: async () => [], | |
chartContextMenuActions: (e) => host.defaultContextMenuActions(e), | |
connectionStatus: () => 1, | |
isTradable: async (symbol) => true, | |
accountManagerInfo: () => { | |
return { | |
accountTitle: 'Trading Sample', | |
summary: [], | |
orderColumns: [], | |
positionColumns: [], | |
pages: [], | |
} | |
}, | |
placeOrder: async (order) => { | |
return { | |
id: `order-123`, | |
limitPrice: 130.0, | |
profit: 0, | |
qty: 2.0, | |
side: -1, | |
status: 6, | |
stopPrice: 160.0, | |
symbol: 'AAPL', | |
type: 1, | |
} | |
}, | |
modifyOrder: async (order) => {}, | |
cancelOrder: async (order) => {}, | |
editPositionBrackets: async (order) => {}, | |
closePosition: async (order) => {}, | |
reversePosition: async (id) => {}, | |
symbolInfo: async (symbol) => { | |
const minTick = await host.getSymbolMinTick(symbol) | |
return { | |
qty: { | |
min: 1, | |
max: 1e12, | |
step: 1, | |
}, | |
pipValue: 1, | |
pipSize: minTick, | |
minTick, | |
description: '', | |
} | |
}, | |
accountsMetainfo: async () => { | |
return [ | |
{ | |
id: '1', | |
name: 'test account' | |
} | |
] | |
}, | |
currentAccount: () => { | |
return '1' | |
}, | |
} | |
}, | |
}); | |
}; | |
window.addEventListener('DOMContentLoaded', initOnReady, false); | |
</script> | |
</head> | |
<body style="margin:0px;"> | |
<div id="tv_chart_container"></div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment