![]() |
VOOZH | about |
dotnet add package StocksCoreApiSharp.Realm --version 1.0.3
NuGet\Install-Package StocksCoreApiSharp.Realm -Version 1.0.3
<PackageReference Include="StocksCoreApiSharp.Realm" Version="1.0.3" />
<PackageVersion Include="StocksCoreApiSharp.Realm" Version="1.0.3" />Directory.Packages.props
<PackageReference Include="StocksCoreApiSharp.Realm" />Project file
paket add StocksCoreApiSharp.Realm --version 1.0.3
#r "nuget: StocksCoreApiSharp.Realm, 1.0.3"
#:package StocksCoreApiSharp.Realm@1.0.3
#addin nuget:?package=StocksCoreApiSharp.Realm&version=1.0.3Install as a Cake Addin
#tool nuget:?package=StocksCoreApiSharp.Realm&version=1.0.3Install as a Cake Tool
This is the core C# library to manage stocks for our StocksWatch application built with .NET MAUI.
Depot and WatchList objects can hold Stock items.
// Create a new depot
Depot myDepot = new("My depot")
{
DateOfCreation = DateTime.Now,
IsPrimaryDepot = true,
};
myDepot.Stocks.Add(new Stock("Daimler AG"));
// Create a new watchlist
WatchList myList = new("My watchlist")
{
DateOfCreation = DateTime.Now,
};
myList.Stocks.Add(new Stock("Daimler AG"));
The Stock object holds all necessary informaton about a stock or ETF.
// Create a new Stock item
Stock basf = new()
{
Name = "BASF",
ISIN = "DE000BASF111",
CurrentRate = 41.05,
};
// Add transactions to it
basf.Transactions.Add(new()
{
StockId = basf.Id,
DateOfCreation = DateTime.Now,
Amount = 100,
Price = 64.10,
Type = TransactionType.Buy,
});
basf.Transactions.Add(new()
{
StockId = basf.Id,
DateOfCreation = DateTime.Now,
Amount = 25,
Price = 60.10,
Type = TransactionType.Sell,
});
// Add dividends to it
basf.Dividends.Add(new()
{
StockId = basf.Id,
DateOfDividend = DateTime.Now,
AmountOfDividend = 3400.00,
Quantity = 100,
Tax = 300,
});
basf.Dividends.Add(new()
{
StockId = basf.Id,
DateOfDividend = DateTime.Now.AddYears(-1),
AmountOfDividend = 3400.00,
Quantity = 100,
Tax = 300,
});
Based on the Transaction and Dividend items, the Stock class will automatically calculate the amount of stocks hold, the total worth and growth.
The library supports SQLite by default. You either can create your own DatabaseHandler or use the provided one.
try
{
string databasePath = "testdatabase.db";
// Start with a clear database
if (File.Exists(databasePath))
{
File.Delete(databasePath);
}
DatabaseHandler.Instance = new DatabaseHandler(databasePath);
if (DatabaseHandler.Instance.IsInitialized)
{
await DatabaseHandler.Instance.InitTablesAsync();
Depot myDepot = new("My depot")
{
DateOfCreation = DateTime.Now,
};
Stock basf = new()
{
DepotId = myDepot.Id,
Name = "BASF",
ISIN = "DE000BASF111",
CurrentRate = 41.05,
};
basf.Transactions.Add(new()
{
StockId = basf.Id,
DateOfCreation = DateTime.Now,
Amount = 100,
Price = 64.10,
Type = TransactionType.Buy,
});
basf.Transactions.Add(new()
{
StockId = basf.Id,
DateOfCreation = DateTime.Now,
Amount = 25,
Price = 60.10,
Type = TransactionType.Sell,
});
basf.Dividends.Add(new()
{
StockId = basf.Id,
DateOfDividend = DateTime.Now,
AmountOfDividend = 3400.00,
Quantity = 100,
Tax = 300,
});
basf.Dividends.Add(new()
{
StockId = basf.Id,
DateOfDividend = DateTime.Now.AddYears(-1),
AmountOfDividend = 3400.00,
Quantity = 100,
Tax = 300,
});
var total = basf.TotalCosts;
var entryPrice = basf.EntrancePrice;
var dividend = basf.TotalDividends;
var growth = basf.Growth;
myDepot.Stocks.Add(basf);
Stock daimler = new()
{
DepotId = myDepot.Id,
Name = "Mercedes Benz AG",
ISIN = "DE0007100000",
CurrentRate = 55.60,
};
daimler.Transactions.Add(new()
{
StockId = daimler.Id,
DateOfCreation = DateTime.Now,
Amount = 100,
Price = 58.10,
Type = TransactionType.Buy,
});
daimler.Transactions.Add(new()
{
StockId = daimler.Id,
DateOfCreation = DateTime.Now,
Amount = 30,
Price = 38.10,
Type = TransactionType.Buy,
});
daimler.Dividends.Add(new()
{
StockId = daimler.Id,
DateOfDividend = DateTime.Now,
AmountOfDividend = 5000,
Quantity = 100,
Tax = 1200,
});
myDepot.Stocks.Add(daimler);
var totalDepotWorth = myDepot.TotalWorth;
var overallDividends = myDepot.OverallDividends;
await DatabaseHandler.Instance.SetStocksWithChildrenAsync(myDepot.Stocks.ToList(), true);
await DatabaseHandler.Instance.SetDepotWithChildrenAsync(myDepot);
Depot? dbDepot = await DatabaseHandler.Instance.GetDepotWithChildrenAsync(myDepot.Id);
Assert.IsNotNull(dbDepot);
string jsonOriginal = JsonConvert.SerializeObject(myDepot, Formatting.Indented);
string jsonDatabase = JsonConvert.SerializeObject(dbDepot, Formatting.Indented);
//Assert.IsTrue(myDepot == dbDepot);
// Test WatchList
WatchList watchList = new("My Watchlist")
{
DateOfCreation = DateTime.Now,
};
basf.WatchListId = watchList.Id;
watchList.Stocks.Add(basf);
daimler.WatchListId = watchList.Id;
watchList.Stocks.Add(daimler);
await DatabaseHandler.Instance.SetStocksWithChildrenAsync(watchList.Stocks.ToList(), true);
await DatabaseHandler.Instance.SetWatchListWithChildrenAsync(watchList);
var loadedWatchLists = await DatabaseHandler.Instance.GetWatchListsWithChildrenAsync();
Assert.IsTrue(loadedWatchLists?.Count > 0);
WatchList list = loadedWatchLists?.FirstOrDefault(l => l.Id == watchList.Id);
Assert.IsNotNull(list);
Assert.IsTrue(list.Stocks?.Count == 2);
// Check if the updating works
var stocks = await DatabaseHandler.Instance.GetStocksWithChildrenAsync();
Assert.IsTrue(stocks?.Count == 2);
await DatabaseHandler.Instance.CloseDatabaseAsync();
}
}
catch (Exception exc)
{
Assert.Fail(exc.Message);
}
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net7.0 net7.0 is compatible. net7.0-android net7.0-android was computed. net7.0-ios net7.0-ios was computed. net7.0-maccatalyst net7.0-maccatalyst was computed. net7.0-macos net7.0-macos was computed. net7.0-tvos net7.0-tvos was computed. net7.0-windows net7.0-windows was computed. net8.0 net8.0 was computed. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 was computed. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 was computed. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
This package is not used by any NuGet packages.
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.3 | 373 | 8/5/2023 |
Check GitHub releases for changelog.