Skip to content

Commit

Permalink
Merge pull request #52 from CurrencyCloud/sdknet-31_conversion_date_p…
Browse files Browse the repository at this point in the history
…reference_parameter

Adds conversion date preference parameter to conversion/create and ra…
  • Loading branch information
jonathancouchman authored May 21, 2020
2 parents 07ccb42 + 2f33520 commit f44b230
Show file tree
Hide file tree
Showing 6 changed files with 160 additions and 4 deletions.
25 changes: 25 additions & 0 deletions Source/CurrencyCloud.Tests/ConversionsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -335,5 +335,30 @@ public async Task FindProfitAndLosses()
}
Assert.AreEqual(profitAndLosses.ConversionProfitAndLosses.Count, profitAndLosses.Pagination.TotalEntries);
}

/// <summary>
/// Successfully creates a conversion with conversion date preference.
/// </summary>
[Test]
public async Task CreateWithConversionDatePreference()
{
player.Play("CreateWithConversionDatePreference");

var conversion = new Conversion(
"EUR",
"GBP",
"buy",
1000.00m,
true
);
conversion.ConversionDatePreference = "earliest";

var created = await client.CreateConversionAsync(conversion);

Assert.That(created, Is.Not.Null);
Assert.AreEqual(805.90, created.ClientSellAmount);
Assert.AreEqual(DateTime.Parse("2020-05-19T00:00:00+00:00"), created.ConversionDate);

}
}
}
56 changes: 56 additions & 0 deletions Source/CurrencyCloud.Tests/Mock/Http/Recordings/Conversions.json
Original file line number Diff line number Diff line change
Expand Up @@ -1424,5 +1424,61 @@
}
}
]
},
{
"name": "CreateWithConversionDatePreference",
"requests": [
{
"request": {
"method": "POST",
"path": "/v2/conversions/create",
"body": "?buy_currency=EUR&sell_currency=GBP&fixed_side=buy&amount=1000&term_agreement=true&conversion_date_preference=earliest",
"headers": {
"X-Auth-Token": "034d23d24490718e8766853e14d480b7",
"User-Agent": "CurrencyCloudSDK/2.0 .NET/5.4.1"
}
},
"response": {
"status": 200,
"headers": {
"Date": "Mon, 01 Jan 2018 12:34:56 GMT",
"Content-Type": "application/json;charset=utf-8",
"X-Request-Id": "2910007469756093752"
},
"body": {
"id": "d56d7553-19ab-4cde-b44b-79cac86989cb",
"settlement_date": "2020-05-19T13:30:00+00:00",
"conversion_date": "2020-05-19T00:00:00+00:00",
"short_reference": "20200519-XYLXJL",
"creator_contact_id": "42a6af4a-65b8-4721-43d9-7f395da2551e",
"account_id": "3f22044f-ae21-42a1-bc4f-cd0370b008a5",
"currency_pair": "EURGBP",
"status": "awaiting_funds",
"buy_currency": "EUR",
"sell_currency": "GBP",
"client_buy_amount": "1000.00",
"client_sell_amount": "805.90",
"fixed_side": "buy",
"core_rate": "0.8059",
"partner_rate": "",
"partner_status": "funds_arrived",
"partner_buy_amount": "0.00",
"partner_sell_amount": "0.00",
"client_rate": "0.8059",
"deposit_required": false,
"deposit_amount": "0.00",
"deposit_currency": "",
"deposit_status": "not_required",
"deposit_required_at": "",
"payment_ids": [],
"unallocated_funds": "1000.00",
"unique_request_id": null,
"created_at": "2020-05-19T12:31:43+00:00",
"updated_at": "2020-05-19T12:31:43+00:00",
"mid_market_rate": "0.8058"
}
}
}
]
}
]
40 changes: 40 additions & 0 deletions Source/CurrencyCloud.Tests/Mock/Http/Recordings/Rates.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,46 @@
}
]
},
{
"name": "GetWithConversionDatePreference",
"requests": [
{
"request": {
"method": "GET",
"path": "/v2/rates/detailed",
"query": "?buy_currency=GBP&sell_currency=USD&fixed_side=buy&amount=10000&conversion_date_preference=optimize_liquidity",
"headers": {
"X-Auth-Token": "034d23d24490718e8766853e14d480b7",
"User-Agent": "CurrencyCloudSDK/2.0 .NET/5.4.1"
}
},
"response": {
"status": 200,
"headers": {
"Date": "Mon, 01 Jan 2018 12:34:56 GMT",
"Content-Type": "application/json;charset=utf-8",
"X-Request-Id": "2910007472633409851"
},
"body": {
"settlement_cut_off_time": "2020-05-21T14:00:00Z",
"currency_pair": "GBPUSD",
"client_buy_currency": "GBP",
"client_sell_currency": "USD",
"client_buy_amount": "10000.00",
"client_sell_amount": "14081.00",
"fixed_side": "buy",
"client_rate": "1.4081",
"partner_rate": null,
"core_rate": "1.4081",
"deposit_required": false,
"deposit_amount": "0.0",
"deposit_currency": "USD",
"mid_market_rate": "1.4080"
}
}
}
]
},
{
"name": "Find",
"requests": [
Expand Down
22 changes: 21 additions & 1 deletion Source/CurrencyCloud.Tests/RatesTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using NUnit.Framework;
using System;
using NUnit.Framework;
using CurrencyCloud.Entity;
using CurrencyCloud.Tests.Mock.Data;
using CurrencyCloud.Tests.Mock.Http;
Expand Down Expand Up @@ -47,6 +48,25 @@ public void Get()
});
}

/// <summary>
/// Successfully gets a rate.
/// </summary>
[Test]
public void GetWithConversionDatePreference()
{
player.Play("GetWithConversionDatePreference");

Assert.DoesNotThrowAsync(async () =>
{
var request = new DetailedRates("GBP", "USD", "buy", 10000);
request.ConversionDatePreference = "optimize_liquidity";
var gotten = await client.GetRateAsync(request);
Assert.That(gotten, Is.Not.Null);
Assert.AreEqual(14081.0, gotten.ClientSellAmount);
Assert.AreEqual(DateTime.Parse("2020-05-21T14:00:00"), gotten.SettlementCutOffTime);
});
}

/// <summary>
/// Successfully finds a rate.
/// </summary>
Expand Down
12 changes: 10 additions & 2 deletions Source/CurrencyCloud/Entity/Conversion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,12 @@ public Conversion() { }
[Param]
public string Reason { get; set; }

///<summary>
/// The preferred strategy to follow to calculate the conversion date
///</summary>
[Param]
public string ConversionDatePreference { get; set; }

public string ToJSON()
{
var obj = new[]
Expand Down Expand Up @@ -175,7 +181,8 @@ public string ToJSON()
UniqueRequestId,
CreatedAt,
UpdatedAt,
MidMarketRate
MidMarketRate,
ConversionDatePreference
}
};
return JsonConvert.SerializeObject(obj);
Expand Down Expand Up @@ -221,7 +228,8 @@ public override bool Equals(object obj)
UpdatedAt == conversion.UpdatedAt &&
UniqueRequestId == conversion.UniqueRequestId &&
UnallocatedFunds == conversion.UnallocatedFunds &&
Reason == conversion.Reason;
Reason == conversion.Reason &&
ConversionDatePreference == conversion.ConversionDatePreference;
}

public override int GetHashCode()
Expand Down
9 changes: 8 additions & 1 deletion Source/CurrencyCloud/Entity/DetailedRates.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ public DetailedRates(string buyCurrency, string sellCurrency, string fixedSide,
[Param]
public DateTime? ConversionDate { get; set; }

///<summary>
/// The preferred strategy to follow to calculate the conversion date
///</summary>
[Param]
public string ConversionDatePreference { get; set; }

public string ToJSON()
{
var obj = new[]
Expand All @@ -55,7 +61,8 @@ public string ToJSON()
SellCurrency,
FixedSide,
Amount,
ConversionDate
ConversionDate,
ConversionDatePreference
}
};
return JsonConvert.SerializeObject(obj);
Expand Down

0 comments on commit f44b230

Please sign in to comment.