27 private DateTime _nextFundingRateApplication = DateTime.MaxValue;
35 var security = marginInterestRateParameters.
Security;
36 var time = marginInterestRateParameters.
Time;
38 if (!cryptoFuture.Invested)
41 _nextFundingRateApplication = DateTime.MaxValue;
44 else if (_nextFundingRateApplication == DateTime.MaxValue)
47 _nextFundingRateApplication = GetNextFundingRateApplication(time);
51 if(marginInterest ==
null)
56 while(time >= _nextFundingRateApplication)
63 var holdings = cryptoFuture.Holdings;
65 var positionValue = cryptoFuture.Holdings.GetQuantityValue(holdings.Quantity);
67 var funding = marginInterest.
InterestRate * positionValue.Amount;
77 positionValue.Cash.AddAmount(funding);
79 _nextFundingRateApplication = GetNextFundingRateApplication(_nextFundingRateApplication);
83 private static DateTime GetNextFundingRateApplication(DateTime currentTime)
85 if(currentTime.Hour >= 16)
88 return currentTime.Date.AddDays(1);
90 else if (currentTime.Hour >= 8)
92 return currentTime.Date.AddHours(16);
96 return currentTime.Date.AddHours(8);