Skip to content

Commit

Permalink
Update deribit client
Browse files Browse the repository at this point in the history
  • Loading branch information
prodigy committed Aug 6, 2024
1 parent 0d0d8fd commit b783139
Show file tree
Hide file tree
Showing 37 changed files with 903 additions and 703 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,95 +4,87 @@ namespace Prodigy.Solutions.Deribit.Client.AccountManagement;

public class AccountSummaryResponse
{
[JsonProperty("delta_total_map")]
public IReadOnlyDictionary<string, decimal>? DeltaTotalMap { get; set; }
[JsonProperty("margin_balance")]
public decimal? MarginBalance { get; set; }
[JsonProperty("futures_session_rpl")]
public decimal? FuturesSessionRpl { get; set; }
[JsonProperty("options_session_rpl")]
public int? OptionsSessionRpl { get; set; }
[JsonProperty("delta_total_map")] public IReadOnlyDictionary<string, decimal>? DeltaTotalMap { get; set; }

[JsonProperty("margin_balance")] public decimal? MarginBalance { get; set; }

[JsonProperty("futures_session_rpl")] public decimal? FuturesSessionRpl { get; set; }

[JsonProperty("options_session_rpl")] public int? OptionsSessionRpl { get; set; }

[JsonProperty("estimated_liquidation_ratio_map")]
public IReadOnlyDictionary<string, decimal>? EstimatedLiquidationRatioMap { get; set; }

[JsonProperty("session_upl")]
public decimal? SessionUpl { get; set; }
[JsonProperty("email")]
public string? Email { get; set; }
[JsonProperty("system_name")]
public string? SystemName { get; set; }
[JsonProperty("username")]
public string? Username { get; set; }
[JsonProperty("session_upl")] public decimal? SessionUpl { get; set; }

[JsonProperty("email")] public string? Email { get; set; }

[JsonProperty("system_name")] public string? SystemName { get; set; }

[JsonProperty("username")] public string? Username { get; set; }

[JsonProperty("interuser_transfers_enabled")]
public bool? InteruserTransfersEnabled { get; set; }

[JsonProperty("id")]
public int Id { get; set; }
[JsonProperty("id")] public int Id { get; set; }

[JsonProperty("estimated_liquidation_ratio")]
public decimal? EstimatedLiquidationRatio { get; set; }

[JsonProperty("options_gamma_map")]
public IReadOnlyDictionary<string, decimal>? OptionsGammaMap { get; set; }
[JsonProperty("options_vega")]
public decimal? OptionsVega { get; set; }
[JsonProperty("options_value")]
public decimal? OptionsValue { get; set; }
[JsonProperty("options_gamma_map")] public IReadOnlyDictionary<string, decimal>? OptionsGammaMap { get; set; }

[JsonProperty("options_vega")] public decimal? OptionsVega { get; set; }

[JsonProperty("options_value")] public decimal? OptionsValue { get; set; }

[JsonProperty("available_withdrawal_funds")]
public decimal? AvailableWithdrawalFunds { get; set; }

[JsonProperty("projected_delta_total")]
public decimal? ProjectedDeltaTotal { get; set; }

[JsonProperty("maintenance_margin")]
public decimal? MaintenanceMargin { get; set; }
[JsonProperty("total_pl")]
public decimal? TotalPl { get; set; }
[JsonProperty("limits")]
public LimitsInfo? Limits { get; set; }
[JsonProperty("options_theta_map")]
public IReadOnlyDictionary<string, decimal>? OptionsThetaMap { get; set; }
[JsonProperty("maintenance_margin")] public decimal? MaintenanceMargin { get; set; }

[JsonProperty("total_pl")] public decimal? TotalPl { get; set; }

[JsonProperty("limits")] public LimitsInfo? Limits { get; set; }

[JsonProperty("options_theta_map")] public IReadOnlyDictionary<string, decimal>? OptionsThetaMap { get; set; }

[JsonProperty("projected_maintenance_margin")]
public decimal? ProjectedMaintenanceMargin { get; set; }

[JsonProperty("available_funds")]
public decimal? AvailableFunds { get; set; }
[JsonProperty("login_enabled")]
public bool? LoginEnabled { get; set; }
[JsonProperty("options_delta")]
public decimal? OptionsDelta { get; set; }
[JsonProperty("balance")]
public decimal? Balance { get; set; }
[JsonProperty("available_funds")] public decimal? AvailableFunds { get; set; }

[JsonProperty("login_enabled")] public bool? LoginEnabled { get; set; }

[JsonProperty("options_delta")] public decimal? OptionsDelta { get; set; }

[JsonProperty("balance")] public decimal? Balance { get; set; }

[JsonProperty("security_keys_enabled")]
public bool? SecurityKeysEnabled { get; set; }

[JsonProperty("referrer_id")]
public object ReferrerId { get; set; }
[JsonProperty("mmp_enabled")]
public bool? MmpEnabled { get; set; }
[JsonProperty("equity")]
public decimal? Equity { get; set; }
[JsonProperty("futures_session_upl")]
public decimal? FuturesSessionUpl { get; set; }
[JsonProperty("fee_balance")]
public int? FeeBalance { get; set; }
[JsonProperty("currency")]
public string? Currency { get; set; }
[JsonProperty("options_session_upl")]
public decimal? OptionsSessionUpl { get; set; }
[JsonProperty("referrer_id")] public object ReferrerId { get; set; }

Check warning on line 68 in src/Prodigy.Solutions.Deribit.Client/AccountManagement/AccountSummaryResponse.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'ReferrerId' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

[JsonProperty("mmp_enabled")] public bool? MmpEnabled { get; set; }

[JsonProperty("equity")] public decimal? Equity { get; set; }

[JsonProperty("futures_session_upl")] public decimal? FuturesSessionUpl { get; set; }

[JsonProperty("fee_balance")] public int? FeeBalance { get; set; }

[JsonProperty("currency")] public string? Currency { get; set; }

[JsonProperty("options_session_upl")] public decimal? OptionsSessionUpl { get; set; }

[JsonProperty("projected_initial_margin")]
public decimal? ProjectedInitialMargin { get; set; }

[JsonProperty("options_theta")]
public decimal? OptionsTheta { get; set; }
[JsonProperty("creation_timestamp")]
public long CreationTimestamp { get; set; }
[JsonProperty("options_theta")] public decimal? OptionsTheta { get; set; }

[JsonProperty("creation_timestamp")] public long CreationTimestamp { get; set; }

[JsonProperty("self_trading_extended_to_subaccounts")]
public bool? SelfTradingExtendedToSubaccounts { get; set; }
Expand All @@ -103,54 +95,48 @@ public class AccountSummaryResponse
[JsonProperty("cross_collateral_enabled")]
public bool? CrossCollateralEnabled { get; set; }

[JsonProperty("margin_model")]
public string? MarginModel { get; set; }
[JsonProperty("margin_model")] public string? MarginModel { get; set; }

[JsonProperty("decimal?> options_vega_map")]
public IReadOnlyDictionary<string, decimal>? OptionsVegaMap { get; set; }

[JsonProperty("futures_pl")]
public decimal? FuturesPl { get; set; }
[JsonProperty("options_pl")]
public decimal? OptionsPl { get; set; }
[JsonProperty("type")]
public string? Type { get; set; }
[JsonProperty("futures_pl")] public decimal? FuturesPl { get; set; }

[JsonProperty("options_pl")] public decimal? OptionsPl { get; set; }

[JsonProperty("type")] public string? Type { get; set; }

[JsonProperty("self_trading_reject_mode")]
public string? SelfTradingRejectMode { get; set; }

[JsonProperty("initial_margin")]
public decimal? InitialMargin { get; set; }
[JsonProperty("spot_reserve")]
public int? SpotReserve { get; set; }
[JsonProperty("delta_total")]
public decimal? DeltaTotal { get; set; }
[JsonProperty("options_gamma")]
public decimal? OptionsGamma { get; set; }
[JsonProperty("session_rpl")]
public decimal? SessionRpl { get; set; }
[JsonProperty("initial_margin")] public decimal? InitialMargin { get; set; }

[JsonProperty("spot_reserve")] public int? SpotReserve { get; set; }

[JsonProperty("delta_total")] public decimal? DeltaTotal { get; set; }

[JsonProperty("options_gamma")] public decimal? OptionsGamma { get; set; }

[JsonProperty("session_rpl")] public decimal? SessionRpl { get; set; }

public class LimitsInfo
{
[JsonProperty("non_matching_engine")]
public NonMatchingEngine? NonMatchingEngine { get; set; }
[JsonProperty("matching_engine")]
public MatchingEngine? MatchingEngine { get; set; }
[JsonProperty("non_matching_engine")] public NonMatchingEngine? NonMatchingEngine { get; set; }

[JsonProperty("matching_engine")] public MatchingEngine? MatchingEngine { get; set; }
}

public class NonMatchingEngine
{
[JsonProperty("rate")]
public int? Rate { get; set; }
[JsonProperty("burst")]
public int? Burst { get; set; }
[JsonProperty("rate")] public int? Rate { get; set; }

[JsonProperty("burst")] public int? Burst { get; set; }
}

public class MatchingEngine
{
[JsonProperty("rate")]
public int? Rate { get; set; }
[JsonProperty("burst")]
public int? Burst { get; set; }
[JsonProperty("rate")] public int? Rate { get; set; }

[JsonProperty("burst")] public int? Burst { get; set; }
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Prodigy.Solutions.Deribit.Client.Authentication;
using System.Dynamic;
using Prodigy.Solutions.Deribit.Client.Authentication;
using Prodigy.Solutions.Deribit.Client.MarketData;

namespace Prodigy.Solutions.Deribit.Client.AccountManagement;
Expand All @@ -14,86 +15,82 @@ public DeribitAccountManagementClient(DeribitJsonRpcClient deribitClient, Deribi
_session = session;
}

public Task<AccountSummaryResponse> GetAccountSummaryAsync(string currency, int? subAccountId = null, bool? extended = null)
public Task<AccountSummaryResponse> GetAccountSummaryAsync(string currency, int? subAccountId = null,
bool? extended = null)
{
dynamic requestObject = new System.Dynamic.ExpandoObject();
dynamic requestObject = new ExpandoObject();
requestObject.currency = currency;

if (subAccountId.HasValue)
{
requestObject.subaccount_id = subAccountId.Value;
}

if (extended.HasValue)
{
requestObject.extended = extended.Value;
}
if (subAccountId.HasValue) requestObject.subaccount_id = subAccountId.Value;

if (extended.HasValue) requestObject.extended = extended.Value;

return _deribitClient.InvokeAsync<AccountSummaryResponse>("private/get_account_summary", requestObject);
}

public Task<IReadOnlyCollection<PositionResult>?> GetPositionsAsync(CurrencyKind currency, InstrumentKind? kind = null, int? subaccountId = null)
public Task<IReadOnlyCollection<PositionResult>?> GetPositionsAsync(CurrencyKind currency,
InstrumentKind? kind = null, int? subaccountId = null)
{
dynamic requestObject = new System.Dynamic.ExpandoObject();
dynamic requestObject = new ExpandoObject();
requestObject.currency = currency;

if (kind.HasValue) requestObject.kind = kind.Value;
if (subaccountId.HasValue) requestObject.subaccount_id = subaccountId.Value;

return _deribitClient.InvokeAsync<IReadOnlyCollection<PositionResult>>("private/get_positions", requestObject);
}
}

public class PositionResult
{
public decimal AveragePrice { get; init; }

public decimal? AveragePriceUsd { get; init; }

public decimal Delta { get; init; }

public PositionDirection Direction { get; init; }

public decimal? EstimatedLiquidationPrice { get; init; }

public decimal FloatingProfitLoss { get; init; }

public decimal FloatingProfitLossUsd { get; init; }

public decimal? Gamma { get; init; }

public decimal IndexPrice { get; init; }

public decimal InitialMargin { get; init; }

public required string InstrumentName { get; init; }

public decimal? InterestValue { get; init; }

public InstrumentKind Kind { get; init; }

public decimal Leverage { get; init; }

public decimal MaintenanceMargin { get; init; }

public decimal MarkPrice { get; init; }

public decimal OpenOrdersMargin { get; init; }

public decimal? RealizedFunding { get; init; }

public decimal RealizedProfitLoss { get; init; }

public decimal? SettlementPrice { get; init; }

public decimal Size { get; init; }

public decimal SizeCurrency { get; init; }

public decimal? Theta { get; init; }

public decimal TotalProfitLoss { get; init; }

public decimal? Vega { get; init; }
}

Expand All @@ -102,4 +99,4 @@ public enum PositionDirection
Zero,
Buy,
Sell
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
public class AuthRequest
{
public required AuthRequestGrantType GrantType { get; init; }

public string? RefreshToken { get; init; }

public string? SignatureData { get; init; }

public string? State { get; init; }

public string? Scope { get; init; }
}
Loading

0 comments on commit b783139

Please # to comment.