StocksCoreApiSharp 1.0.3
dotnet add package StocksCoreApiSharp --version 1.0.3
NuGet\Install-Package StocksCoreApiSharp -Version 1.0.3
<PackageReference Include="StocksCoreApiSharp" Version="1.0.3" />
paket add StocksCoreApiSharp --version 1.0.3
#r "nuget: StocksCoreApiSharp, 1.0.3"
// Install StocksCoreApiSharp as a Cake Addin #addin nuget:?package=StocksCoreApiSharp&version=1.0.3 // Install StocksCoreApiSharp as a Cake Tool #tool nuget:?package=StocksCoreApiSharp&version=1.0.3
StocksCoreApiSharp
This is the core C# library to manage stocks for our StocksWatch application built with .NET MAUI.
Nuget
Usage
Depots & Watchlists
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"));
Stocks
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.
Database
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 | net5.0 was computed. net5.0-windows was computed. net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.1 is compatible. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.1
- CommunityToolkit.Mvvm (>= 8.2.1)
- RCoreSharp (>= 1.0.9)
-
net6.0
- CommunityToolkit.Mvvm (>= 8.2.1)
- RCoreSharp (>= 1.0.9)
-
net7.0
- CommunityToolkit.Mvvm (>= 8.2.1)
- RCoreSharp (>= 1.0.9)
NuGet packages (2)
Showing the top 2 NuGet packages that depend on StocksCoreApiSharp:
Package | Downloads |
---|---|
StocksCoreApiSharp.SQLite
An extension for the StocksCoreApiSharp library which enables SQLite support. |
|
StocksCoreApiSharp.Realm
An extension for the StocksCoreApiSharp library which enables SQLite support. |
GitHub repositories
This package is not used by any popular GitHub repositories.
Check GitHub releases for changelog.