diff --git a/GDAXSharp.Specs/JsonFixtures/Services/Orders/OrderResponseFixture.cs b/GDAXSharp.Specs/JsonFixtures/Services/Orders/OrderResponseFixture.cs index 42f35e96..f1faa4b2 100644 --- a/GDAXSharp.Specs/JsonFixtures/Services/Orders/OrderResponseFixture.cs +++ b/GDAXSharp.Specs/JsonFixtures/Services/Orders/OrderResponseFixture.cs @@ -76,7 +76,31 @@ public static string CreateStopOrder() return json; } - public static string CreateLimitOrderMany(OrderStatus orderStatus = OrderStatus.Pending) + public static string CreateStopLimitOrder() + { + var json = @" +{ + ""id"": ""d0c5340b-6d6c-49d9-b567-48c4bfca13d2"", + ""price"": ""0.10000000"", + ""size"": ""0.01000000"", + ""product_id"": ""BTC-USD"", + ""side"": ""buy"", + ""stp"": ""dc"", + ""type"": ""limit"", + ""time_in_force"": ""GTC"", + ""post_only"": false, + ""created_at"": ""2016-12-08T24:00:00Z"", + ""fill_fees"": ""0.0000000000000000"", + ""filled_size"": ""0.00000000"", + ""executed_value"": ""0.0000000000000000"", + ""status"": ""pending"", + ""settled"": false +}"; + + return json; + } + + public static string CreateLimitOrderMany(OrderStatus orderStatus = OrderStatus.Pending) { var json = $@" [ diff --git a/GDAXSharp.Specs/Services/Orders/OrdersServiceSpecs.cs b/GDAXSharp.Specs/Services/Orders/OrdersServiceSpecs.cs index 93991f69..795533c7 100644 --- a/GDAXSharp.Specs/Services/Orders/OrdersServiceSpecs.cs +++ b/GDAXSharp.Specs/Services/Orders/OrdersServiceSpecs.cs @@ -118,6 +118,35 @@ class when_placing_a_stop_order }; } + class when_placing_a_stop_limit_order + { + Establish context = () => + The().WhenToldTo(p => p.ReadAsStringAsync(Param.IsAny())) + .Return(Task.FromResult(OrderResponseFixture.CreateStopLimitOrder())); + + Because of = () => + order_response_result = Subject.PlaceStopLimitOrderAsync(OrderSide.Buy, ProductType.BtcUsd, .01M, .1M, .1M, false).Result; + + It should_have_correct_order_information = () => + { + order_response_result.Id.ShouldEqual(new Guid("d0c5340b-6d6c-49d9-b567-48c4bfca13d2")); + order_response_result.Price.ShouldEqual(0.10000000M); + order_response_result.Size.ShouldEqual(0.01000000M); + order_response_result.ProductId.ShouldEqual(ProductType.BtcUsd); + order_response_result.Side.ShouldEqual(OrderSide.Buy); + order_response_result.Stp.ShouldEqual("dc"); + order_response_result.OrderType.ShouldEqual(OrderType.Limit); + order_response_result.TimeInForce.ShouldEqual(TimeInForce.Gtc); + order_response_result.PostOnly.ShouldBeFalse(); + order_response_result.CreatedAt.ShouldEqual(new DateTime(2016, 12, 9)); + order_response_result.FillFees.ShouldEqual(0.0000000000000000M); + order_response_result.FilledSize.ShouldEqual(0.00000000M); + order_response_result.ExecutedValue.ShouldEqual(0.0000000000000000M); + order_response_result.Status.ShouldEqual(OrderStatus.Pending); + order_response_result.Settled.ShouldBeFalse(); + }; + } + class when_cancelling_all_orders { Establish context = () => diff --git a/GDAXSharp/GDAXSharp.csproj b/GDAXSharp/GDAXSharp.csproj index 1b5870f7..eb8cd745 100644 --- a/GDAXSharp/GDAXSharp.csproj +++ b/GDAXSharp/GDAXSharp.csproj @@ -89,6 +89,7 @@ + diff --git a/GDAXSharp/Services/Orders/Models/Order.cs b/GDAXSharp/Services/Orders/Models/Order.cs index 1fb11c07..6fbf8476 100644 --- a/GDAXSharp/Services/Orders/Models/Order.cs +++ b/GDAXSharp/Services/Orders/Models/Order.cs @@ -17,6 +17,13 @@ public class Order public decimal Price { get; set; } + [JsonProperty("stop")] + [JsonConverter(typeof(StringEnumConverter))] + public StopType StopType { get; set; } + + [JsonProperty("stop_price")] + public decimal StopPrice { get; set; } + [JsonProperty("type")] [JsonConverter(typeof(StringEnumConverter))] public OrderType OrderType { get; set; } diff --git a/GDAXSharp/Services/Orders/OrdersService.cs b/GDAXSharp/Services/Orders/OrdersService.cs index e1be032e..f396fc8f 100644 --- a/GDAXSharp/Services/Orders/OrdersService.cs +++ b/GDAXSharp/Services/Orders/OrdersService.cs @@ -89,6 +89,33 @@ public async Task PlaceLimitOrderAsync( return await PlaceOrderAsync(order); } + public async Task PlaceStopLimitOrderAsync( + OrderSide side, + ProductType productId, + decimal size, + decimal stopPrice, + decimal limitPrice, + bool postOnly = true, + Guid? clientOid = null) + { + var order = new Order + { + Side = side, + ProductId = productId, + OrderType = OrderType.Limit, + Price = limitPrice, + Size = size, + StopType = side == OrderSide.Buy + ? StopType.Entry + : StopType.Loss, + StopPrice = stopPrice, + ClientOid = clientOid, + PostOnly = postOnly, + }; + + return await PlaceOrderAsync(order); + } + public async Task PlaceStopOrderAsync( OrderSide side, ProductType productId, diff --git a/GDAXSharp/Services/Orders/Types/StopType.cs b/GDAXSharp/Services/Orders/Types/StopType.cs new file mode 100644 index 00000000..b96592cc --- /dev/null +++ b/GDAXSharp/Services/Orders/Types/StopType.cs @@ -0,0 +1,12 @@ +using System.Runtime.Serialization; + +namespace GDAXSharp.Services.Orders.Types +{ + public enum StopType + { + [EnumMember(Value = "loss")] + Loss, + [EnumMember(Value = "entry")] + Entry + } +}