Skip to content

Instantly share code, notes, and snippets.

@davelab6
Forked from LukeL99/daedalus-cointracking.ipynb
Last active September 7, 2021 05:48
Show Gist options
  • Save davelab6/d9550672ee5439e3d24f35b250ed7f83 to your computer and use it in GitHub Desktop.
Save davelab6/d9550672ee5439e3d24f35b250ed7f83 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": "ABX9TyNWwNjD5pfx+eTXOHyYJA0C",
"include_colab_link": true
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"language_info": {
"name": "python"
},
"widgets": {
"application/vnd.jupyter.widget-state+json": {
"af697aba055c46b9b566fe92840756c3": {
"model_module": "@jupyter-widgets/controls",
"model_name": "FileUploadModel",
"state": {
"_view_name": "FileUploadView",
"_counter": 0,
"style": "IPY_MODEL_ccc20c1eb82c4386942c088fe1cd4540",
"_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_09bf8b55f9f24769bf8e1786b01bc2e7",
"icon": "upload"
}
},
"ccc20c1eb82c4386942c088fe1cd4540": {
"model_module": "@jupyter-widgets/controls",
"model_name": "ButtonStyleModel",
"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"
}
},
"09bf8b55f9f24769bf8e1786b01bc2e7": {
"model_module": "@jupyter-widgets/base",
"model_name": "LayoutModel",
"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": [
"af697aba055c46b9b566fe92840756c3",
"ccc20c1eb82c4386942c088fe1cd4540",
"09bf8b55f9f24769bf8e1786b01bc2e7"
]
},
"id": "eC2VElqggsxU",
"outputId": "d2696aec-3411-44a1-f332-de7e961b8e89"
},
"source": [
"# Daedalus to Cointracking script v1.0\n",
"# Author: Luke Libraro - lukel99@gmail.com\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': 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': 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')\n",
"from google.colab import files\n",
"files.download('output.csv')\n",
"from IPython.display import FileLink\n",
"FileLink('output.csv')"
],
"execution_count": 1,
"outputs": [
{
"output_type": "display_data",
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "af697aba055c46b9b566fe92840756c3",
"version_minor": 0,
"version_major": 2
},
"text/plain": [
"FileUpload(value={}, accept='.csv', description='Upload')"
]
},
"metadata": {
"tags": []
}
}
]
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment