Method GenerateBudgetReportAsync
- Namespace
- WhalesSecret.TradeScriptLib.API.TradingV1
- Assembly
- WhalesSecret.TradeScriptLib.dll
GenerateBudgetReportAsync(CancellationToken)
Generates a budget report.
Task<BudgetReport> GenerateBudgetReportAsync(CancellationToken cancellationToken)
Parameters
cancellationToken
CancellationTokenCancellation token that allows the caller to cancel the operation.
Returns
- Task<BudgetReport>
Budget report.
Remarks
Trading strategy budget is associated with trade API client when BudgetRequest is used in ConnectionOptions parameter when the connection is established. The budget request includes the initial budget, which is a listing of all assets and their respective amounts that the client can use and is restricted by. The budget request also includes the primary asset, which is the asset in which the value of the budget is calculated.
For example, the budget request can define the initial budget to be 0.1
BTC and 5,000
EUR. If the primary asset is set to BTC, the budget's initial value will
be calculated in BTC. Let's say the price of 1 BTC at the start time is 80,000
EUR. The initial value of the budget will be 0.1 + 5,000 / 80,000 = 0.1625
BTC.
Let's assume then that the client makes trades and by doing so gains 0.02
BTC and loses 400
EUR including trading fees. Suppose further that the price of
1 BTC changes to 85,000 EUR. Using GenerateBudgetReportAsync(CancellationToken) we can generate report that will give us the current value of the budget in
the primary asset as well as profit and loss. In our example, the current value of the budget will be 0.1 + 0.02 + (5,000 - 400) / 85,000 = 0.12 + 0.05176 = 0.17176
BTC. Therefore, the profit will be calculated as 0.17176 - 0.1625 = 0.00926
BTC.
Note that the budget does not take into account the actual balance in the exchange wallet. It is a mechanism that is implemented within an instance of a trade API client. It is possible to create multiple trade API client instances, each with different budget, trading a different strategy. This is useful when you want to compare different strategies side by side. However, you must make sure that your exchange wallet balance is sufficient to cover the budgets of all clients that are running simultaneously. Also note that due to the nature of some order types and due to deficiencies of API of some exchanges, you should have some buffer in your exchange wallet on top of the sum of all simultaneously running budgets.
Exceptions
- NotAvailableException
Thrown if the trade API client was created without budget.
- OperationFailedException
Thrown if it was not possible to calculate the value of the budget.
- OperationCanceledException
Thrown if the operation was canceled.
- NotConnectedTimeoutException
Thrown if the connection strategy associated with this instance is BlockUntilReconnectedOrTimeout with non-infinite timeout value and this timeout expired while the connection to the exchange is interrupted. That is, this exception does not limit the request itself, it rather limits the period of time that allows the client to recover from the interruption of the connection to the exchange.
- NotConnectedException
Thrown if the connection strategy is FailInstantlyIfNotConnected and the connection to the exchange is interrupted.