Skip to content
This repository has been archived by the owner on Feb 24, 2022. It is now read-only.

Commit

Permalink
Merge branch 'release/1.3.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
nazarovsa committed Nov 14, 2019
2 parents 7ff85f2 + 7980aa0 commit c4d4e0d
Show file tree
Hide file tree
Showing 39 changed files with 361 additions and 169 deletions.
6 changes: 3 additions & 3 deletions Insight.Tinkoff.Invest.Tests/Base/TestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ public class TestBase
public TestBase()
{
Token = TestConfigurationManager.GetToken();
RestConfiguration = new TinkoffRestServiceConfiguration
RestConfiguration = new RestConfiguration
{
AccessToken = Token
};
}

protected string Token { get; }

protected TinkoffRestServiceConfiguration RestConfiguration { get; }
protected RestConfiguration RestConfiguration { get; }

protected void ValidateRestResponse(ResponseBase response)
{
Expand All @@ -35,7 +35,7 @@ private static class TestConfigurationManager

public static string GetToken()
{
return _config.Value["Token"]?.ToString();
return _config.Value["AccessToken"]?.ToString();
}
}
}
Expand Down
5 changes: 4 additions & 1 deletion Insight.Tinkoff.Invest.Tests/OperationsTest.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using Insight.Tinkoff.Invest.Domain;
Expand All @@ -23,9 +24,11 @@ public async Task Should_get_operations()
{
var filter = new OperationsFilter
{
From = DateTime.Now - TimeSpan.FromDays(30),
To = DateTime.Now,
// Accenture
Figi = "BBG000D9D830",
Interval = OperationInterval.Day
Interval = OperationInterval.Month
};

var response = await _operationService.Get(filter, CancellationToken.None);
Expand Down
6 changes: 3 additions & 3 deletions Insight.Tinkoff.Invest.Tests/OrderTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public async Task Should_get_orders()
}

[Fact]
public async Task Should_post_limit_order()
public async Task Should_place_limit_order()
{
var balanceSetResponse = await _sandboxService.SetCurrencyBalance(new SandboxSetCurrencyBalanceRequest
{
Expand All @@ -39,14 +39,14 @@ public async Task Should_post_limit_order()

ValidateRestResponse(balanceSetResponse);

var request = new LimitOrderRequest
var request = new PlaceLimitOrderRequest
{
Lots = 1,
Operation = OperationType.Buy,
Price = 180
};

var response = await _orderService.PostLimitOrder("BBG000D9D830", request, CancellationToken.None);
var response = await _orderService.PlaceLimitOrder("BBG000D9D830", request, CancellationToken.None);

ValidateRestResponse(response);
Assert.NotNull(response.Order);
Expand Down
30 changes: 20 additions & 10 deletions Insight.Tinkoff.Invest.Tests/StreamServiceTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
using System.Threading.Tasks;
using Insight.Tinkoff.Invest.Domain;
using Insight.Tinkoff.Invest.Dto.Messages;
using Insight.Tinkoff.Invest.Dto.Payloads;
using Insight.Tinkoff.Invest.Infrastructure.Configurations;
using Insight.Tinkoff.Invest.Infrastructure.Extensions;
using Insight.Tinkoff.Invest.Services;
using Insight.Tinkoff.Invest.Tests.Base;
using Newtonsoft.Json;
using Xunit;
using Xunit.Abstractions;

Expand All @@ -20,9 +22,9 @@ public sealed class StreamServiceTest : TestBase
public StreamServiceTest(ITestOutputHelper testOutputHelper)
{
_testOutputHelper = testOutputHelper;
_streamService = new StreamMarketService(new StreamMarketServiceConfiguration
_streamService = new StreamMarketService(new StreamConfiguration
{
Token = Token
AccessToken = Token
});
}

Expand All @@ -34,24 +36,32 @@ public async Task Should_receive_messages_from_as_observable()
.Do(x =>
{
Assert.NotNull(x);
Assert.Equal("orderbook", x.Event, StringComparer.OrdinalIgnoreCase);
switch (x)
{
case OrderBookMessage m:
Assert.Equal("orderbook", x.Event, StringComparer.OrdinalIgnoreCase);
_testOutputHelper.WriteLine(
$"[{DateTime.Now:HH:mm:ss.fff}]: type: {m.Event}, figi: {m.Payload.Figi}");
$"[{DateTime.Now:HH:mm:ss.fff}]: {JsonConvert.SerializeObject(m)}\n");
break;
case InstrumentInfoMessage m:
Assert.Equal("instrument_info", x.Event, StringComparer.OrdinalIgnoreCase);
_testOutputHelper.WriteLine(
$"[{DateTime.Now:HH:mm:ss.fff}]: {JsonConvert.SerializeObject(m)}\n");
break;
case CandleMessage m:
Assert.Equal("candle", x.Event, StringComparer.OrdinalIgnoreCase);
_testOutputHelper.WriteLine(
$"[{DateTime.Now:HH:mm:ss.fff}]: {JsonConvert.SerializeObject(m)}\n");
break;
default:
throw new ArgumentException(nameof(x));
}
}, ex => { throw ex; })
.Subscribe();

await _streamService.Send(new SubscribeOrderBookMessage
{
Figi = "BBG000D9D830",
Depth = 5
});

await _streamService.Send(new SubscribeOrderBookMessage("BBG000D9D830", 5));
await _streamService.Send(new SubscribeInstrumentInfoMessage("BBG000D9D830"));
await _streamService.Send(new SubscribeCandleMessage("BBG000D9D830", CandleInterval.Minute));

await Task.Delay(5 * 1000);
}
Expand Down
2 changes: 1 addition & 1 deletion Insight.Tinkoff.Invest.Tests/appsettings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"Token": ""
"AccessToken": ""
}
2 changes: 1 addition & 1 deletion Insight.Tinkoff.Invest/Domain/Services/IOrderService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ public interface IOrderService

Task<OrdersResponse> Get(CancellationToken cancellationToken = default);

Task<LimitOrderResponse> PostLimitOrder(string figi, LimitOrderRequest request, CancellationToken cancellationToken = default);
Task<LimitOrderResponse> PlaceLimitOrder(string figi, PlaceLimitOrderRequest request, CancellationToken cancellationToken = default);
}
}
17 changes: 16 additions & 1 deletion Insight.Tinkoff.Invest/Dto/Operations/ExtendedOperationType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,26 @@ namespace Insight.Tinkoff.Invest.Dto
[JsonConverter(typeof(StringEnumConverter))]
public enum ExtendedOperationType
{
BuyCard,
Buy,
Sell,
BrokerCommission,
ExchangeCommission,
ServiceCommission,
MarginCommission
MarginCommission,
OtherCommission,
PayIn,
PayOut,
Tax,
TaxLucre,
TaxDividend,
TaxCoupon,
TaxBack,
Repayment,
PartRepayment,
Coupon,
Dividend,
SecurityIn,
SecurityOut
}
}
11 changes: 2 additions & 9 deletions Insight.Tinkoff.Invest/Dto/Orders/Order.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,8 @@ public sealed class Order

public string Figi { get; set; }

/// <summary>
/// operation type
/// </summary>
[JsonProperty("operation")]
public OperationType OperationType { get; set; }

/// <summary>
/// OrderStatus
/// </summary>
public OperationType Operation { get; set; }

public OrderStatus Status { get; set; }

public int RequestedLots { get; set; }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace Insight.Tinkoff.Invest.Dto
{
public sealed class LimitOrderRequest
public sealed class PlaceLimitOrderRequest
{
public int Lots { get; set; }

Expand Down
5 changes: 2 additions & 3 deletions Insight.Tinkoff.Invest/Dto/Orders/PlacedLimitOrder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
namespace Insight.Tinkoff.Invest.Dto
{
public sealed class PlacedLimitOrder
{
{
public string OrderId { get; set; }

[JsonProperty("operation")]
public OperationType OperationType { get; set; }
public OperationType Operation { get; set; }

public OrderStatus Status { get; set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ namespace Insight.Tinkoff.Invest.Dto.Responses
{
public sealed class LimitOrderResponse : ResponseBase
{
[JsonProperty]
public PlacedLimitOrder Order { get; }

[JsonConstructor]
public LimitOrderResponse([JsonProperty("payload")] PlacedLimitOrder limitOrder)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ namespace Insight.Tinkoff.Invest.Dto.Responses
{
public sealed class OrdersResponse : ResponseBase
{
[JsonProperty]
public IReadOnlyCollection<Order> Orders { get; }

[JsonConstructor]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ namespace Insight.Tinkoff.Invest.Dto.Responses
{
public sealed class CurrenciesResponse : ResponseBase
{
[JsonProperty]
public IReadOnlyCollection<CurrencyPosition> Currencies { get; }

[JsonConstructor]
public CurrenciesResponse([JsonProperty("payload")] CurrenciesResponsePayload payload)
public CurrenciesResponse(CurrenciesResponsePayload payload)
{
Currencies = payload.Currencies;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ namespace Insight.Tinkoff.Invest.Dto.Responses
{
public sealed class PortfolioResponse : ResponseBase
{
[JsonProperty]
public IReadOnlyCollection<PortfolioPosition> Positions { get; }

[JsonConstructor]
public PortfolioResponse([JsonProperty("payload")] PortfolioResponsePayload payload)
public PortfolioResponse(PortfolioResponsePayload payload)
{
Positions = payload.Positions;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using Insight.Tinkoff.Invest.Dto.Payloads;

namespace Insight.Tinkoff.Invest.Dto.Messages
Expand All @@ -6,9 +7,18 @@ public sealed class SubscribeCandleMessage : IWsMessage
{
public string Event => EventType.SubscribeCandle;

public string Figi { get; set; }
public SubscribeCandleMessage(string figi, CandleInterval interval)
{
if (string.IsNullOrWhiteSpace(figi))
throw new ArgumentNullException(nameof(figi));

Figi = figi;
Interval = interval;
}

public string Figi { get; private set; }

public CandleInterval Interval { get; set; }
public CandleInterval Interval { get; private set; }

public override int GetHashCode()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,14 @@ public sealed class SubscribeInstrumentInfoMessage : IWsMessage

public string Figi { get; set; }


public SubscribeInstrumentInfoMessage(string figi)
{
if (string.IsNullOrWhiteSpace(figi))
throw new ArgumentNullException(nameof(figi));

Figi = figi;
}

public override int GetHashCode()
{
return (Figi != null ? Figi.GetHashCode() : 0);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using System;

namespace Insight.Tinkoff.Invest.Dto.Messages
{
public sealed class SubscribeOrderBookMessage : IWsMessage
Expand All @@ -7,6 +9,15 @@ public sealed class SubscribeOrderBookMessage : IWsMessage
public string Figi { get; set; }

public int Depth { get; set; }

public SubscribeOrderBookMessage(string figi, int depth)
{
if (string.IsNullOrWhiteSpace(figi))
throw new ArgumentNullException(nameof(figi));

Figi = figi;
Depth = depth;
}

public override int GetHashCode()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using Insight.Tinkoff.Invest.Dto.Payloads;

namespace Insight.Tinkoff.Invest.Dto.Messages
Expand All @@ -6,8 +7,17 @@ public sealed class UnsubscribeCandleMessage : IWsMessage
{
public string Event => EventType.UnubscribeCandle;

public string Figi { get; set; }
public UnsubscribeCandleMessage(string figi, CandleInterval interval)
{
if (string.IsNullOrWhiteSpace(figi))
throw new ArgumentNullException(nameof(figi));

Figi = figi;
Interval = Interval;
}

public string Figi { get; private set; }

public CandleInterval Interval { get; set; }
public CandleInterval Interval { get; private set; }
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
using System;

namespace Insight.Tinkoff.Invest.Dto.Messages
{
public sealed class UnsubscribeInstrumentInfo : IWsMessage
{
public string Event => EventType.UnubscribeInstrumentInfo;

public string Figi { get; set; }

public UnsubscribeInstrumentInfo(string figi)
{
if (string.IsNullOrWhiteSpace(figi))
throw new ArgumentNullException(nameof(figi));

Figi = figi;
}
}
}
Loading

0 comments on commit c4d4e0d

Please sign in to comment.