Skip to content

Instantly share code, notes, and snippets.

@wlib
Created December 8, 2017 18:44
Show Gist options
  • Save wlib/b03f8acf5f90bd240f6d21adf04c08e0 to your computer and use it in GitHub Desktop.
Save wlib/b03f8acf5f90bd240f6d21adf04c08e0 to your computer and use it in GitHub Desktop.
function getWidgetURL(options) {
const url = new URL("https://s.tradingview.com/widgetembed/");
const defaultOptions = {
symbol: "BTCUSD",
interval: 60,
hidesidetoolbar: 0,
symboledit: 1,
saveimage: 1,
toolbarbg: "f1f3f6",
theme: "Light",
style: 1,
timezone: "America/New_York",
locale: "en"
};
const finalOptions = Object.assign({}, defaultOptions, options);
for (let key in finalOptions) {
url.searchParams.set(key, finalOptions[key]);
}
return url.href;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment