Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions src/ExchangeSharp/API/Exchanges/Kraken/ExchangeKrakenAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -964,6 +964,47 @@ await GetNoncePayloadAsync(),
return balances;
}

protected override async Task<ExchangeOrderResult> OnAmendOrderAsync(
ExchangeOrderRequest order
)
{
IEnumerable<ExchangeMarket> markets = await OnGetMarketSymbolsMetadataAsync();
ExchangeMarket market = markets
.Where(m => m.MarketSymbol == order.MarketSymbol)
.First<ExchangeMarket>();

object nonce = await GenerateNonceAsync();
Dictionary<string, object> payload = new Dictionary<string, object>(
StringComparer.OrdinalIgnoreCase
)
{
{ "cl_ord_id", order.ClientOrderId },
{ "order_qty", order.RoundAmount().ToStringInvariant() },
{ "limit_price", order.Price },
{ "post_only", order.IsPostOnly },
{ "nonce", nonce }
};

JToken token = await MakeJsonRequestAsync<JToken>("/0/private/AmendOrder", null, payload, "POST");
ExchangeOrderResult result = new ExchangeOrderResult
{
OrderDate = CryptoUtility.UtcNow,
Result = ExchangeAPIOrderResult.Open
};
if (token["txid"] is JArray array)
{
result.OrderId = array[0].ToStringInvariant();
}
if (token["descr"] is JObject descrArray)
{
result = ExtendResultsWithOrderDescr(
result,
descrArray["order"].ToStringInvariant()
);
}
return result;
}

protected override async Task<ExchangeOrderResult> OnPlaceOrderAsync(
ExchangeOrderRequest order
)
Expand Down
11 changes: 11 additions & 0 deletions src/ExchangeSharp/API/Exchanges/_Base/ExchangeAPI.cs
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,10 @@ protected virtual Task<Dictionary<string, decimal>> OnGetAmountsAvailableToTrade
ExchangeOrderRequest order
) => throw new NotImplementedException();

protected virtual Task<ExchangeOrderResult> OnAmendOrderAsync(
ExchangeOrderRequest order
) => throw new NotImplementedException();

protected virtual Task<ExchangeOrderResult[]> OnPlaceOrdersAsync(
params ExchangeOrderRequest[] order
) => throw new NotImplementedException();
Expand Down Expand Up @@ -1307,6 +1311,13 @@ public virtual async Task<ExchangeOrderResult> PlaceOrderAsync(ExchangeOrderRequ
return await OnPlaceOrderAsync(order);
}

public virtual async Task<ExchangeOrderResult> AmendOrderAsync(ExchangeOrderRequest order)
{
await new SynchronizationContextRemover();
order.MarketSymbol = NormalizeMarketSymbol(order.MarketSymbol);
return await OnAmendOrderAsync(order);
}

/// <summary>
/// Place bulk orders
/// </summary>
Expand Down
7 changes: 7 additions & 0 deletions src/ExchangeSharp/API/Exchanges/_Base/IExchangeAPI.cs
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,13 @@ Task<Dictionary<string, decimal>> GetMarginAmountsAvailableToTradeAsync(
/// <returns>Order result and message string if any</returns>
Task<ExchangeOrderResult> PlaceOrderAsync(ExchangeOrderRequest order);

/// <summary>
/// Amend an order
/// </summary>
/// <param name="order">Amend request</param>
/// <returns>Amend result and message string if any</returns>
Task<ExchangeOrderResult> AmendOrderAsync(ExchangeOrderRequest order);

/// <summary>
/// Place bulk orders
/// </summary>
Expand Down
Loading