Unhandled exception. System.ArgumentException: Conversion from DateTime to Timestamp requires the DateTime kind to be Utc (Parameter 'dateTime')
at Google.Protobuf.WellKnownTypes.Timestamp.FromDateTime(DateTime dateTime)
at Program.Main(String[] args) in C:\C#_DEV\Test\TinkofTest\Program.cs:line 14
using Google.Protobuf.WellKnownTypes;
internal class Program
{
private static void Main(string[] args)
{
var settings = new Tinkoff.InvestApi.InvestApiSettings()
{
AccessToken = "token"
};
var client = Tinkoff.InvestApi.InvestApiClientFactory.Create(settings);
var getTechAnalysis = client.MarketData.GetTechAnalysis(new Tinkoff.InvestApi.V1.GetTechAnalysisRequest
{
IndicatorType = Tinkoff.InvestApi.V1.GetTechAnalysisRequest.Types.IndicatorType.Rsi,
InstrumentUid = "a22a1263-8e1b-4546-a1aa-416463f104d3",
From = Timestamp.FromDateTimeOffset(new DateTime(2023,12,31)),
To = Timestamp.FromDateTime(DateTime.Now),
Interval = Tinkoff.InvestApi.V1.GetTechAnalysisRequest.Types.IndicatorInterval.OneDay,
TypeOfPrice = Tinkoff.InvestApi.V1.GetTechAnalysisRequest.Types.TypeOfPrice.High,
Length = 96,
//Deviation =
//{
// DeviationMultiplier =
// {
// Units = 266,
// Nano= 905
// }
//}
}); ;
foreach (var techAnalysis in getTechAnalysis.TechnicalIndicators)
{
Console.WriteLine(
$"{techAnalysis.Timestamp} {techAnalysis.MiddleBand}");
}
}
}
Deviation
From = Timestamp.FromDateTimeOffset(new DateTime(2023, 12, 31).ToUniversalTime()),
To = Timestamp.FromDateTime(DateTime.UtcNow),
у меня ваш код компилируется и исполняется с отказом авторизации, что логично..From = Timestamp.FromDateTime(new DateTime(2023, 12, 31).ToUniversalTime()),
To = Timestamp.FromDateTime(DateTime.UtcNow),
проDeviation
пока не понял..
Conversion from DateTime to Timestamp requires the DateTime kind to be Utc (Parameter 'dateTime')
Timestamp.FromDateTime(DateTime.Now)
Timestamp.FromDateTimeOffset(new DateTime(2023,12,31)),