Im trying to make a report for a trading system with Powershell. I have one txt-file (owned.txt) that contains my current tickers:
DNO.OL
EQNR.OL
And another txt-file (signals.txt) that contains buy/sell signals:
DNO.OL,Sell,25.01.2021,7.1580
DSV.CO,Buy,25.01.2021,982.4000
If one of the lines in signals.txt contains a ticker (eks "DNO.OL") with "Sell" that is also in owned.txt. I want to add that line from signals.txt to the report and remove that ticker (eks "DNO.OL") from owned.txt.
If one of the lines in signals.txt contains a ticker (eks "DVS.CO") with "Buy" and that ticker is not in owned.txt. I want that line from signals.txt to be added to the report and the ticker added (eks "DVS.CO") to the owned.txt file.
I have started with this code but it does not work as I want.
$report = "C:\temp\report.txt"
$ToDaySignals = Get-Content "C:\temp\signals.txt"
$OwnedList = "C:\temp\owned.txt"
ForEach ($line in $ToDaySignals)
{
$part = $line -split ","
If ( ((Get-Content $OwnedList) -notcontains $part[0]) -and (($part[1]) -eq "Buy") )
{
"Buy: " + $line | Out-file $report -Append
$part[0] | Out-File $OwnedList -Encoding utf8 -Append
}
If ( ((Get-Content $OwnedList) -contains $part[0]) -and (($part[1]) -eq "Sell") )
{
"Sell: " + $line | Out-file $report -Append
Set-Content -Path $OwnedList -Value (get-content -Path $OwnedList | Select-String -Pattern $part[0] -NotMatch)
}
}