Skip to content

Instantly share code, notes, and snippets.

@muyexi
Created January 14, 2023 06:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save muyexi/fb580ac4bef1604cd9de29b1fc602434 to your computer and use it in GitHub Desktop.
Save muyexi/fb580ac4bef1604cd9de29b1fc602434 to your computer and use it in GitHub Desktop.
Futu.ipynb
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "view-in-github",
"colab_type": "text"
},
"source": [
"<a href=\"https://colab.research.google.com/gist/muyexi/fb580ac4bef1604cd9de29b1fc602434/futu.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
"cell_type": "markdown",
"source": [
"1. From [Futu](https://www.futunn.com/) export A-share ETF / Index Constituents as a CSV file.\n",
"2. Upload the file here and convert to TradingView Watchlist.\n",
"\n"
],
"metadata": {
"id": "tbQegmLV_khp"
}
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "MqPQ1boaCIHd"
},
"outputs": [],
"source": [
"from io import StringIO\n",
"import pprint\n",
"\n",
"import pandas as pd\n",
"import numpy as np\n",
"\n",
"from google.colab import files\n",
"\n",
"uploaded = files.upload()\n",
"\n",
"for file_name in uploaded.keys():\n",
" file_content = uploaded[file_name].decode(\"utf-16\") \n",
" name = file_name.replace(\"csv\", \"txt\")\n",
"\n",
" df = pd.read_csv(StringIO(file_content), delimiter=\"\\t\", converters={'代码': str})\n",
"\n",
" if \"代码\" in df.columns:\n",
" df[\"代码\"] = np.where(df[\"代码\"].str.startswith('6'), \"SSE:\" + df[\"代码\"], \"SZSE:\" + df[\"代码\"])\n",
" df[\"代码\"].to_csv(name, header = False, index = False)\n",
" \n",
" files.download(name)"
]
}
],
"metadata": {
"colab": {
"provenance": [],
"authorship_tag": "ABX9TyMq3GJbxNECc2q48Fr6fs7f",
"include_colab_link": true
},
"kernelspec": {
"display_name": "Python 3",
"name": "python3"
},
"language_info": {
"name": "python"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment