Skip to content

Instantly share code, notes, and snippets.

@LukeL99
Last active February 21, 2022 21:07
Show Gist options
  • Save LukeL99/6d918fa0a51bf0e42280e79191f5ce39 to your computer and use it in GitHub Desktop.
Save LukeL99/6d918fa0a51bf0e42280e79191f5ce39 to your computer and use it in GitHub Desktop.
daedalus-cointracking.ipynb
Display the source blob
Display the rendered blob
Raw
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"name": "daedalus-cointracking.ipynb",
"provenance": [],
"collapsed_sections": [],
"authorship_tag": "ABX9TyOMbdYEiCVdmBAUo/tdEHI3",
"include_colab_link": true
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"language_info": {
"name": "python"
},
"widgets": {
"application/vnd.jupyter.widget-state+json": {
"07c7ff818684449faab7b3fe5e9246e0": {
"model_module": "@jupyter-widgets/controls",
"model_name": "FileUploadModel",
"model_module_version": "1.5.0",
"state": {
"_view_name": "FileUploadView",
"_counter": 0,
"style": "IPY_MODEL_e8a8507476054bdcb42fd46b8290aa46",
"_dom_classes": [],
"description": "Upload",
"multiple": false,
"_model_name": "FileUploadModel",
"data": [],
"button_style": "",
"_view_module": "@jupyter-widgets/controls",
"_model_module_version": "1.5.0",
"accept": ".csv",
"_view_count": null,
"disabled": false,
"_view_module_version": "1.5.0",
"error": "",
"description_tooltip": null,
"metadata": [],
"_model_module": "@jupyter-widgets/controls",
"layout": "IPY_MODEL_636bead4b4304c47ba7990ecf100f70a",
"icon": "upload"
}
},
"e8a8507476054bdcb42fd46b8290aa46": {
"model_module": "@jupyter-widgets/controls",
"model_name": "ButtonStyleModel",
"model_module_version": "1.5.0",
"state": {
"_view_name": "StyleView",
"_model_name": "ButtonStyleModel",
"_view_module": "@jupyter-widgets/base",
"_model_module_version": "1.5.0",
"_view_count": null,
"button_color": null,
"font_weight": "",
"_view_module_version": "1.2.0",
"_model_module": "@jupyter-widgets/controls"
}
},
"636bead4b4304c47ba7990ecf100f70a": {
"model_module": "@jupyter-widgets/base",
"model_name": "LayoutModel",
"model_module_version": "1.2.0",
"state": {
"_view_name": "LayoutView",
"grid_template_rows": null,
"right": null,
"justify_content": null,
"_view_module": "@jupyter-widgets/base",
"overflow": null,
"_model_module_version": "1.2.0",
"_view_count": null,
"flex_flow": null,
"width": null,
"min_width": null,
"border": null,
"align_items": null,
"bottom": null,
"_model_module": "@jupyter-widgets/base",
"top": null,
"grid_column": null,
"overflow_y": null,
"overflow_x": null,
"grid_auto_flow": null,
"grid_area": null,
"grid_template_columns": null,
"flex": null,
"_model_name": "LayoutModel",
"justify_items": null,
"grid_row": null,
"max_height": null,
"align_content": null,
"visibility": null,
"align_self": null,
"height": null,
"min_height": null,
"padding": null,
"grid_auto_rows": null,
"grid_gap": null,
"max_width": null,
"order": null,
"_view_module_version": "1.2.0",
"grid_template_areas": null,
"object_position": null,
"object_fit": null,
"grid_auto_columns": null,
"margin": null,
"display": null,
"left": null
}
}
}
}
},
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "view-in-github",
"colab_type": "text"
},
"source": [
"<a href=\"https://colab.research.google.com/gist/LukeL99/6d918fa0a51bf0e42280e79191f5ce39/daedalus-cointracking.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
"cell_type": "code",
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 49,
"referenced_widgets": [
"07c7ff818684449faab7b3fe5e9246e0",
"e8a8507476054bdcb42fd46b8290aa46",
"636bead4b4304c47ba7990ecf100f70a"
]
},
"id": "eC2VElqggsxU",
"outputId": "8e1c4b65-4bd2-4991-88ea-e0fb4c359878"
},
"source": [
"# Daedalus to Cointracking script v1.0\n",
"# Author: Luke Libraro - [email protected]\n",
"# \n",
"# Will import a CSV file from Daedalus and convert it to a csv file (output.csv)\n",
"# compatible with cointracking.info\n",
"# Notes: Tested against US currency and date formats only\n",
"# Tested with on Windows newlines\n",
"# Does not handle staking rewards because those aren't included in Daedalus CSV\n",
"# Get staking reward CSV from pooltool.io\n",
"\n",
"# ipywidgets Version 7.6.3\n",
"import ipywidgets as widgets\n",
"import pandas as pd\n",
"import io\n",
"\n",
"exchange_name = 'Daedalus'\n",
"trade_group = ''\n",
"comment = 'Daedalus import script'\n",
"\n",
"from IPython.display import display\n",
"\n",
"def convert_df(daedalus_df):\n",
" tx_list = []\n",
" for index, row in daedalus_df.iterrows():\n",
" if(row['Type'] == 'Received'):\n",
" tx_list.append({'Type': 'Deposit', 'Buy Amount': str(row['TOTAL (ADA)']).replace(',', ''),\n",
" 'Buy Currency': 'ADA', 'Sell Amount': '',\n",
" 'Sell Currency': '', 'Fee': '', 'Fee Currency': '',\n",
" 'Exchange' : exchange_name, 'Trade-Group': trade_group,\n",
" 'Comment': comment, 'Date': row['Date & time'],\n",
" 'Tx-ID': row['ID']})\n",
" else:\n",
" tx_list.append({'Type': 'Withdrawal', 'Buy Amount': '',\n",
" 'Buy Currency': '', 'Sell Amount': str(row['Sent amount (ADA)']).replace(',', ''),\n",
" 'Sell Currency': 'ADA', 'Fee': row['Fee (ADA)'],\n",
" 'Fee Currency': 'ADA', 'Exchange' : exchange_name,\n",
" 'Trade-Group': trade_group, 'Comment': comment, \n",
" 'Date': row['Date & time'],\n",
" 'Tx-ID': row['ID']})\n",
" ct_df = pd.DataFrame(tx_list)\n",
" display(ct_df)\n",
" return ct_df\n",
"\n",
"def handle_upload(file):\n",
" output = io.StringIO(initial_value=file['new'][0].decode())\n",
" df = pd.read_csv(output)\n",
" df_out = convert_df(df)\n",
" # Cointracking doesn't handle trailing newline well, strip last newline from \n",
" # CSV and write to file\n",
" csv_string = df_out.to_csv(index = False)\n",
" with open('output.csv', 'w') as file:\n",
" file.write(csv_string.rstrip())\n",
"\n",
"uploader = widgets.FileUpload(accept='.csv', multiple=False)\n",
"display(uploader)\n",
"uploader.observe(handle_upload, names='data')"
],
"execution_count": null,
"outputs": [
{
"output_type": "display_data",
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "07c7ff818684449faab7b3fe5e9246e0",
"version_minor": 0,
"version_major": 2
},
"text/plain": [
"FileUpload(value={}, accept='.csv', description='Upload')"
]
},
"metadata": {}
}
]
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment