Skip to content

Instantly share code, notes, and snippets.

@daviddwlee84
Last active April 11, 2025 03:14
Show Gist options
  • Save daviddwlee84/9f0ef8d8c2ba18efd18ef748cc7170bf to your computer and use it in GitHub Desktop.
Save daviddwlee84/9f0ef8d8c2ba18efd18ef748cc7170bf to your computer and use it in GitHub Desktop.
Easily get A-Share symbol market data as image from Easy Money
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>EastMoney K-line Picture Viewer</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 2em;
}
label {
display: block;
margin: 0.5em 0 0.2em;
}
input {
margin-bottom: 1em;
padding: 0.3em;
width: 200px;
}
#urlDisplay {
font-family: monospace;
margin-top: 1em;
}
</style>
</head>
<body>
<h1>EastMoney K-line Picture Viewer</h1>
<form id="controlForm">
<label for="symbol">Symbol:</label>
<input type="text" id="symbol" name="symbol" value="600519" required>
<label for="unitWidth">unitWidth: (-9 ~ 0)</label>
<input type="number" id="unitWidth" name="unitWidth" value="-6">
<label for="formula">Formula (RSI, CCI):</label>
<input type="text" id="formula" name="formula" value="RSI">
<label for="imageType">imageType (KXL, r):</label>
<input type="text" id="imageType" name="imageType" value="KXL">
<label for="timespan">Timespan:</label>
<input type="number" id="timespan" name="timespan" value="1744335466">
<br>
<button type="button" onclick="updateImage()">Update Image</button>
</form>
<div id="urlDisplay"></div>
<br>
<img id="resultImage" alt="EastMoney Chart" style="max-width: 100%; border: 1px solid #ccc;">
<script>
/**
* Determine the exchange prefix for an A-Share symbol.
* Rules:
* - If symbol starts with '6', return "1." (Shanghai).
* - If symbol starts with '0' or '3', return "0." (Shenzhen).
* - Otherwise, returns null.
*/
function getExchangePrefix(symbol) {
if (symbol.startsWith("6") || symbol.startsWith("11")) {
return "1.";
} else if (symbol.startsWith("0") || symbol.startsWith("3") || symbol.startsWith("12")) {
return "0.";
} else {
return null;
}
}
/**
* Build the URL and update the <img> element.
*/
function updateImage() {
// Get input values
var symbol = document.getElementById('symbol').value.trim();
var unitWidth = document.getElementById('unitWidth').value;
var formula = document.getElementById('formula').value.trim();
var imageType = document.getElementById('imageType').value.trim();
var timespan = document.getElementById('timespan').value;
var prefix = getExchangePrefix(symbol);
if (!prefix) {
alert("Unsupported or invalid A-Share symbol: " + symbol);
return;
}
// Construct URL for the API (daily frequency endpoint)
var url = "https://webquoteklinepic.eastmoney.com/GetPic.aspx?" +
"nid=" + encodeURIComponent(prefix + symbol) +
"&type=" +
"&unitWidth=" + encodeURIComponent(unitWidth) +
"&ef=" +
"&formula=" + encodeURIComponent(formula) +
"&imageType=" + encodeURIComponent(imageType) +
"&timespan=" + encodeURIComponent(timespan);
// Display the URL for debugging purposes
document.getElementById('urlDisplay').innerText = "Fetching URL:\n" + url;
// Update the image source
document.getElementById('resultImage').src = url;
}
</script>
</body>
</html>
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment