Tinkoff / invest-openapi-csharp-sdk

Apache License 2.0
100 stars 33 forks source link

Пустой Response на примере из readme (Tinkoff.Trading.OpenApi.Network.OpenApiInvalidResponseException) #107

Open WhiteBlackGoose opened 2 years ago

WhiteBlackGoose commented 2 years ago

Аналог #46, которое закрыто и, видимо, последующий ответ (пятидневной давности) никто не увидел.

Пример из readme:

using Tinkoff.Trading.OpenApi.Network;

var token = File.ReadAllText("mypath");

var connection = ConnectionFactory.GetConnection(token);
var context = connection.Context;

var portfolio = await context.PortfolioAsync();

foreach (var position in portfolio.Positions)
{
    Console.WriteLine(position.Figi);
}

Падает в PortfolioAsync():

Unhandled exception. Tinkoff.Trading.OpenApi.Network.OpenApiInvalidResponseException: Unable to handle response.
Response:
Продолжение stack trace ``` ---> System.Text.Json.JsonException: The input does not contain any JSON tokens. Expected the input to start with a valid JSON token, when isFinalBlock is true. Path: $ | LineNumber: 0 | BytePositionInLine: 0. ---> System.Text.Json.JsonReaderException: The input does not contain any JSON tokens. Expected the input to start with a valid JSON token, when isFinalBlock is true. LineNumber: 0 | BytePositionInLine: 0. at System.Text.Json.ThrowHelper.ThrowJsonReaderException(Utf8JsonReader& json, ExceptionResource resource, Byte nextByte, ReadOnlySpan`1 bytes) at System.Text.Json.Utf8JsonReader.Read() at System.Text.Json.Serialization.JsonConverter`1.ReadCore(Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state) --- End of inner exception stack trace --- at System.Text.Json.ThrowHelper.ReThrowWithPath(ReadStack& state, JsonReaderException ex) at System.Text.Json.Serialization.JsonConverter`1.ReadCore(Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state) at System.Text.Json.JsonSerializer.ReadFromSpan[TValue](ReadOnlySpan`1 utf8Json, JsonTypeInfo jsonTypeInfo, Nullable`1 actualByteCount) at System.Text.Json.JsonSerializer.Deserialize[TValue](ReadOnlySpan`1 utf8Json, JsonSerializerOptions options) at Tinkoff.Trading.OpenApi.Network.Connection`1.HandleResponseAsync[TOut](HttpResponseMessage response) --- End of inner exception stack trace --- at Tinkoff.Trading.OpenApi.Network.Connection`1.HandleResponseAsync[TOut](HttpResponseMessage response) at Tinkoff.Trading.OpenApi.Network.Connection`1.SendGetRequestAsync[TPayload](String path) at Tinkoff.Trading.OpenApi.Network.Context.PortfolioAsync(String brokerAccountId) at Program.
$(String[] args) in D:\main\trading\TradingAnalysis\TestCSharpDataDownload\TinkoffAPITest\Program.cs:line 9 at Program.
(String[] args) ```

Версия 1.7.5

Где и какой response мы получаем:

image

WhiteBlackGoose commented 2 years ago

Временный фикс - токен полного доступа, см.