Last active
April 11, 2025 03:14
-
-
Save daviddwlee84/9f0ef8d8c2ba18efd18ef748cc7170bf to your computer and use it in GitHub Desktop.
Easily get A-Share symbol market data as image from Easy Money
This file contains hidden or 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 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) + | |
"×pan=" + 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> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment