Skip to content

Commit 4cd7a6f

Browse files
committed
Add support for fetching transaction logs from Deribit API
Implemented `GetTransactionLogAsync` and `GetAllTransactionLogsAsync` methods to retrieve transaction logs with pagination support. Added related `TransactionLogResult` and `TransactionLogEntry` classes to handle the API response structure. This enhancement allows for detailed transaction tracking and log retrieval.
1 parent fbc97b9 commit 4cd7a6f

File tree

2 files changed

+68
-2
lines changed

2 files changed

+68
-2
lines changed

src/Prodigy.Solutions.Deribit.Client/AccountManagement/DeribitAccountManagementClient.cs

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,33 @@ public Task<AccountSummaryResponse> GetAccountSummaryAsync(string currency, int?
3939

4040
return _deribitClient.InvokeAsync<IReadOnlyCollection<PositionResult>>("private/get_positions", requestObject);
4141
}
42+
43+
public Task<TransactionLogResult> GetTransactionLogAsync(CurrencyKind currency, DateTimeOffset startDate,
44+
DateTimeOffset endDate, string? query = null, int count = 100, int? continuation = null)
45+
{
46+
dynamic requestObject = new ExpandoObject();
47+
requestObject.currency = currency;
48+
requestObject.start_timestamp = startDate.ToUnixTimeMilliseconds();
49+
requestObject.end_timestamp = endDate.ToUnixTimeMilliseconds();
50+
if (query != null) requestObject.query = query;
51+
requestObject.count = count;
52+
if (continuation.HasValue) requestObject.continuation = continuation.Value;
53+
54+
return _deribitClient.InvokeAsync<TransactionLogResult>("private/get_transaction_log", requestObject);
55+
}
56+
57+
public async IAsyncEnumerable<TransactionLogEntry> GetAllTransactionLogsAsync(CurrencyKind currency,
58+
DateTimeOffset startDate, DateTimeOffset endDate, string? query = null, int countPerPage = 100)
59+
{
60+
int? continuation = null;
61+
do
62+
{
63+
var result = await GetTransactionLogAsync(currency, startDate, endDate, query, countPerPage, continuation);
64+
continuation = result.Continuation;
65+
foreach (var log in result.Logs ?? Array.Empty<TransactionLogEntry>())
66+
yield return log;
67+
} while (continuation != null);
68+
}
4269
}
4370

4471
public class PositionResult
@@ -99,4 +126,43 @@ public enum PositionDirection
99126
Zero,
100127
Buy,
101128
Sell
102-
}
129+
}
130+
131+
public class TransactionLogResult
132+
{
133+
public int? Continuation { get; set; }
134+
public IReadOnlyCollection<TransactionLogEntry>? Logs { get; set; }
135+
}
136+
137+
public class TransactionLogEntry
138+
{
139+
public decimal Amount { get; set; }
140+
public decimal Balance { get; set; }
141+
public decimal Cashflow { get; set; }
142+
public decimal Change { get; set; }
143+
public decimal? Commission { get; set; }
144+
public decimal? Contracts { get; set; }
145+
public required string Currency { get; set; }
146+
public decimal Equity { get; set; }
147+
public long Id { get; set; }
148+
public object? Info { get; set; }
149+
public string? InstrumentName { get; set; }
150+
public decimal InterestPl { get; set; }
151+
public decimal MarkPrice { get; set; }
152+
public string? OrderId { get; set; }
153+
public decimal? Position { get; set; }
154+
public decimal? Price { get; set; }
155+
public string? PriceCurrency { get; set; }
156+
public bool ProfitAsCashflow { get; set; }
157+
public decimal SessionRpl { get; set; }
158+
public decimal SessionUpl { get; set; }
159+
public string? Side { get; set; }
160+
public long Timestamp { get; set; }
161+
public decimal TotalInterestPl { get; set; }
162+
public string? TradeId { get; set; }
163+
public required string Type { get; set; }
164+
public long UserId { get; set; }
165+
public string? UserRole { get; set; }
166+
public long UserSeq { get; set; }
167+
public required string Username { get; set; }
168+
}

src/Prodigy.Solutions.Deribit.Client/Prodigy.Solutions.Deribit.Client.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
44
<TargetFramework>net8.0</TargetFramework>

0 commit comments

Comments
 (0)