Skip to content

Commit d84650d

Browse files
authored
AmendOrderAsync method in Kraken API (#879)
* Implemented AmendOrderAsync method in Kraken API * Missed including AmendOrderAsync in ExchangeAPI.cs
1 parent bb4fb26 commit d84650d

File tree

3 files changed

+59
-0
lines changed

3 files changed

+59
-0
lines changed

src/ExchangeSharp/API/Exchanges/Kraken/ExchangeKrakenAPI.cs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -964,6 +964,47 @@ await GetNoncePayloadAsync(),
964964
return balances;
965965
}
966966

967+
protected override async Task<ExchangeOrderResult> OnAmendOrderAsync(
968+
ExchangeOrderRequest order
969+
)
970+
{
971+
IEnumerable<ExchangeMarket> markets = await OnGetMarketSymbolsMetadataAsync();
972+
ExchangeMarket market = markets
973+
.Where(m => m.MarketSymbol == order.MarketSymbol)
974+
.First<ExchangeMarket>();
975+
976+
object nonce = await GenerateNonceAsync();
977+
Dictionary<string, object> payload = new Dictionary<string, object>(
978+
StringComparer.OrdinalIgnoreCase
979+
)
980+
{
981+
{ "cl_ord_id", order.ClientOrderId },
982+
{ "order_qty", order.RoundAmount().ToStringInvariant() },
983+
{ "limit_price", order.Price },
984+
{ "post_only", order.IsPostOnly },
985+
{ "nonce", nonce }
986+
};
987+
988+
JToken token = await MakeJsonRequestAsync<JToken>("/0/private/AmendOrder", null, payload, "POST");
989+
ExchangeOrderResult result = new ExchangeOrderResult
990+
{
991+
OrderDate = CryptoUtility.UtcNow,
992+
Result = ExchangeAPIOrderResult.Open
993+
};
994+
if (token["txid"] is JArray array)
995+
{
996+
result.OrderId = array[0].ToStringInvariant();
997+
}
998+
if (token["descr"] is JObject descrArray)
999+
{
1000+
result = ExtendResultsWithOrderDescr(
1001+
result,
1002+
descrArray["order"].ToStringInvariant()
1003+
);
1004+
}
1005+
return result;
1006+
}
1007+
9671008
protected override async Task<ExchangeOrderResult> OnPlaceOrderAsync(
9681009
ExchangeOrderRequest order
9691010
)

src/ExchangeSharp/API/Exchanges/_Base/ExchangeAPI.cs

100644100755
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,10 @@ protected virtual Task<Dictionary<string, decimal>> OnGetAmountsAvailableToTrade
259259
ExchangeOrderRequest order
260260
) => throw new NotImplementedException();
261261

262+
protected virtual Task<ExchangeOrderResult> OnAmendOrderAsync(
263+
ExchangeOrderRequest order
264+
) => throw new NotImplementedException();
265+
262266
protected virtual Task<ExchangeOrderResult[]> OnPlaceOrdersAsync(
263267
params ExchangeOrderRequest[] order
264268
) => throw new NotImplementedException();
@@ -1307,6 +1311,13 @@ public virtual async Task<ExchangeOrderResult> PlaceOrderAsync(ExchangeOrderRequ
13071311
return await OnPlaceOrderAsync(order);
13081312
}
13091313

1314+
public virtual async Task<ExchangeOrderResult> AmendOrderAsync(ExchangeOrderRequest order)
1315+
{
1316+
await new SynchronizationContextRemover();
1317+
order.MarketSymbol = NormalizeMarketSymbol(order.MarketSymbol);
1318+
return await OnAmendOrderAsync(order);
1319+
}
1320+
13101321
/// <summary>
13111322
/// Place bulk orders
13121323
/// </summary>

src/ExchangeSharp/API/Exchanges/_Base/IExchangeAPI.cs

100644100755
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,13 @@ Task<Dictionary<string, decimal>> GetMarginAmountsAvailableToTradeAsync(
217217
/// <returns>Order result and message string if any</returns>
218218
Task<ExchangeOrderResult> PlaceOrderAsync(ExchangeOrderRequest order);
219219

220+
/// <summary>
221+
/// Amend an order
222+
/// </summary>
223+
/// <param name="order">Amend request</param>
224+
/// <returns>Amend result and message string if any</returns>
225+
Task<ExchangeOrderResult> AmendOrderAsync(ExchangeOrderRequest order);
226+
220227
/// <summary>
221228
/// Place bulk orders
222229
/// </summary>

0 commit comments

Comments
 (0)