Last active
March 2, 2022 00:58
-
-
Save x-limitless-x/e885d030c4215e88761a55983fb3d707 to your computer and use it in GitHub Desktop.
This file contains 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
# ----------------------------------------------------- | |
# Variables Section | |
# ----------------------------------------------------- | |
<# | |
.SYNOPSIS | |
Convert-CSV for cointracking.info | |
.DESCRIPTION | |
Will import a CSV file from Daedalus and convert it to a csv file. Compatible with cointracking.info | |
.PARAMETER InputFile | |
The input CSV file. | |
.PARAMETER OutputCSVFile | |
The filename and location of the CSV File you want to output. | |
.EXAMPLE | |
PS C:\> .\Convert-CSV.ps1 -InputFile "C:\Input.csv" -OutputCSVFile "C:\Output-Fixed.csv" | |
.NOTES | |
Does not handle staking rewards because those aren't included in Daedalus CSV | |
Get staking reward CSV from pooltool.io | |
Author: Blake Drumm (https://github.com/x-limitless-x) | |
#> | |
[OutputType([string])] | |
param | |
( | |
[Parameter(HelpMessage = 'The input CSV file.')] | |
[string]$InputFile, | |
[Parameter(HelpMessage = 'The filename and location of the CSV File you want to output.')] | |
[string]$OutputCSVFile | |
) | |
BEGIN | |
{ | |
Function Time-Stamp | |
{ | |
$TimeStamp = Get-Date -Format "MM/dd/yyyy hh:mm:ss tt" | |
return "$TimeStamp - " | |
} | |
Write-Host "$(Time-Stamp)Starting script" | |
# If -InputFile not detected during execution, look in C:\input.csv | |
if (!$InputFile) | |
{ | |
$InputFile = "C:\input.csv" | |
} | |
$ImportedCSV = Import-Csv -Path $InputFile | |
# If -OutputCSVFile not detected during execution, export to C:\output-fixed.csv | |
if (!$OutputCSVFile) | |
{ | |
$OutputCSVFile = 'C:\output-fixed.csv' | |
} | |
$OutputCSVFile = "C:\output-fixed.csv" | |
$ExchangeName = 'Daedalus' | |
$Comment = 'Daedalus Powershell Import Script' | |
$TradeGroup = '' | |
$DateTimeFormat = "MM/dd/yyyy hh:mm:ss tt" | |
} | |
PROCESS | |
{ | |
$array = $null | |
$array = @() | |
foreach ($line in $ImportedCSV) | |
{ | |
Write-Host "$(Time-Stamp)Working on $($line.Id)" | |
if ($line.Type -eq 'Received') | |
{ | |
$array += [PSCustomObject]@{ | |
'Type' = 'Deposit' | |
'Buy Amount' = "$(($line.'TOTAL (ADA)' | Out-String -Width 4096) -replace "\s", '')" | |
'Buy Currency' = 'ADA' | |
'Sell Amount' = '' | |
'Sell Currency' = '' | |
'Fee' = '' | |
'Fee Currency' = '' | |
'Exchange' = $ExchangeName | |
'Trade-Group' = $TradeGroup | |
'Comment' = "$($Comment) - $(Get-Date -Format "MM/dd/yyyy hh:mm:ss tt")" | |
'Date' = "$(($line.'Date & time' | Get-Date -Format $DateTimeFormat))" | |
'Tx-ID' = $line.Id | |
} | |
} | |
else | |
{ | |
$array += [PSCustomObject]@{ | |
'Type' = 'Withdrawal' | |
'Buy Amount' = '' | |
'Buy Currency' = '' | |
'Sell Amount' = $line.'Sent amount (ADA)' | |
'Sell Currency' = 'ADA' | |
'Fee' = $line.'Fee (ADA)' | |
'Fee Currency' = 'ADA' | |
'Exchange' = $ExchangeName | |
'Trade-Group' = $TradeGroup | |
'Comment' = "$($Comment) - $(Get-Date -Format $DateTimeFormat)" | |
'Date' = "$($line.'Date & time' | Get-Date -Format $DateTimeFormat)" | |
'Tx-ID' = $line.Id | |
} | |
} | |
} | |
} | |
END | |
{ | |
Write-Host "$(Time-Stamp)Finished processing input CSV" | |
# Uncomment the below line to see the output in the console window: | |
#$array | Select-Object 'Type', 'Buy Amount', 'Buy Currency', 'Sell Amount', 'Sell Currency', 'Fee', 'Fee Currency', 'Exchange', 'Trade Group', 'Comment', 'Date', 'Tx-ID' | Format-Table * -AutoSize | |
# Export to CSV | |
$array | Select-Object 'Type', 'Buy Amount', 'Buy Currency', 'Sell Amount', 'Sell Currency', 'Fee', 'Fee Currency', 'Exchange', 'Trade Group', 'Comment', 'Date', 'Tx-ID' | Export-Csv -Path $OutputCSVFile -NoTypeInformation | |
Write-Host "$(Time-Stamp)Exported file to: " -NoNewline | |
Write-Host $OutputCSVFile -ForegroundColor Green | |
Write-Host "$(Time-Stamp)Script Completed!" | |
# ----------------------------------------------------- | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment