Skip to content

Commit

Permalink
Added FuturesApi.Trading.PlaceMultipleOrdersAsync, PlaceMultipleStopO…
Browse files Browse the repository at this point in the history
…rdersAsync, CancelOrdersAsync and CancelStopOrdersAsync batch endpoints
  • Loading branch information
JKorf committed Aug 19, 2024
1 parent 9d6493f commit b9e07c4
Show file tree
Hide file tree
Showing 5 changed files with 389 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System;
using CryptoExchange.Net;
using CoinEx.Net.Interfaces.Clients.FuturesApi;
using System.Collections.Generic;

namespace CoinEx.Net.Clients.FuturesApi
{
Expand Down Expand Up @@ -82,6 +83,36 @@ public async Task<WebCallResult<CoinExStopId>> PlaceStopOrderAsync(
return await _baseClient.ExecuteAsync<CoinExStopId>(_baseClient.GetUri("v2/futures/stop-order"), HttpMethod.Post, ct, parameters, true).ConfigureAwait(false);
}

/// <inheritdoc />
public async Task<WebCallResult<IEnumerable<CoinExBatchResult<CoinExFuturesOrder>>>> PlaceMultipleOrdersAsync(
IEnumerable<CoinExFuturesPlaceOrderRequest> requests,
CancellationToken ct = default)
{
foreach (var order in requests)
order.ClientOrderId ??= ExchangeHelpers.AppendRandomString("x-" + _baseClient._brokerId + "-", 32);

var parameters = new ParameterCollection()
{
{ "orders", requests }
};
return await _baseClient.ExecuteAsync<IEnumerable<CoinExBatchResult<CoinExFuturesOrder>>>(_baseClient.GetUri("v2/futures/batch-order"), HttpMethod.Post, ct, parameters, true).ConfigureAwait(false);
}

/// <inheritdoc />
public async Task<WebCallResult<IEnumerable<CoinExBatchResult<CoinExStopId>>>> PlaceMultipleStopOrdersAsync(
IEnumerable<CoinExFuturesPlaceStopOrderRequest> requests,
CancellationToken ct = default)
{
foreach (var order in requests)
order.ClientOrderId ??= ExchangeHelpers.AppendRandomString("x-" + _baseClient._brokerId + "-", 32);

var parameters = new ParameterCollection()
{
{ "orders", requests }
};
return await _baseClient.ExecuteAsync<IEnumerable<CoinExBatchResult<CoinExStopId>>>(_baseClient.GetUri("v2/futures/batch-stop-order"), HttpMethod.Post, ct, parameters, true).ConfigureAwait(false);
}

/// <inheritdoc />
public async Task<WebCallResult<CoinExFuturesOrder>> GetOrderAsync(string symbol, long orderId, CancellationToken ct = default)
{
Expand Down Expand Up @@ -245,7 +276,30 @@ public async Task<WebCallResult<CoinExStopOrder>> CancelStopOrderByClientOrderId
};
parameters.AddEnum("market_type", AccountType.Futures);
return await _baseClient.ExecuteAsync<CoinExStopOrder>(_baseClient.GetUri("v2/futures/cancel-stop-order-by-client-id"), HttpMethod.Post, ct, parameters, true).ConfigureAwait(false);

}

/// <inheritdoc />
public async Task<WebCallResult<IEnumerable<CoinExBatchResult<CoinExFuturesOrder>>>> CancelOrdersAsync(string symbol, IEnumerable<long> orderIds, CancellationToken ct = default)
{
var parameters = new ParameterCollection()
{
{ "market", symbol },
{ "order_ids", orderIds }
};
parameters.AddEnum("market_type", AccountType.Futures);
return await _baseClient.ExecuteAsync<IEnumerable<CoinExBatchResult<CoinExFuturesOrder>>>(_baseClient.GetUri("v2/futures/cancel-batch-order"), HttpMethod.Post, ct, parameters, true).ConfigureAwait(false);
}

/// <inheritdoc />
public async Task<WebCallResult<IEnumerable<CoinExBatchResult<CoinExStopOrder>>>> CancelStopOrdersAsync(string symbol, IEnumerable<long> orderIds, CancellationToken ct = default)
{
var parameters = new ParameterCollection()
{
{ "market", symbol },
{ "stop_ids", orderIds }
};
parameters.AddEnum("market_type", AccountType.Futures);
return await _baseClient.ExecuteAsync<IEnumerable<CoinExBatchResult<CoinExStopOrder>>>(_baseClient.GetUri("v2/futures/cancel-batch-stop-order"), HttpMethod.Post, ct, parameters, true).ConfigureAwait(false);
}

/// <inheritdoc />
Expand Down
160 changes: 160 additions & 0 deletions CoinEx.Net/CoinEx.Net.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Threading.Tasks;
using CoinEx.Net.Objects.Models.V2;
using System;
using System.Collections.Generic;

namespace CoinEx.Net.Interfaces.Clients.FuturesApi
{
Expand Down Expand Up @@ -66,6 +67,28 @@ Task<WebCallResult<CoinExStopId>> PlaceStopOrderAsync(
SelfTradePreventionMode? stpMode = null,
CancellationToken ct = default);

/// <summary>
/// Place multiple orders in a single call
/// <para><a href="https://docs.coinex.com/api/v2/futures/order/http/put-multi-order" /></para>
/// </summary>
/// <param name="requests">Orders to place</param>
/// <param name="ct">Cancelation Token</param>
/// <returns></returns>
Task<WebCallResult<IEnumerable<CoinExBatchResult<CoinExFuturesOrder>>>> PlaceMultipleOrdersAsync(
IEnumerable<CoinExFuturesPlaceOrderRequest> requests,
CancellationToken ct = default);

/// <summary>
/// Place multiple stop orders in a single call
/// <para><a href="https://docs.coinex.com/api/v2/futures/order/http/put-multi-stop-order" /></para>
/// </summary>
/// <param name="requests">Stop orders to place</param>
/// <param name="ct">Cancelation Token</param>
/// <returns></returns>
Task<WebCallResult<IEnumerable<CoinExBatchResult<CoinExStopId>>>> PlaceMultipleStopOrdersAsync(
IEnumerable<CoinExFuturesPlaceStopOrderRequest> requests,
CancellationToken ct = default);

/// <summary>
/// Get an order by id
/// <para><a href="https://docs.coinex.com/api/v2/futures/order/http/get-order-status" /></para>
Expand Down Expand Up @@ -215,6 +238,25 @@ Task<WebCallResult<CoinExStopId>> EditStopOrderAsync(
/// <returns></returns>
Task<WebCallResult<CoinExStopOrder>> CancelStopOrderByClientOrderIdAsync(string symbol, string clientStopOrderId, CancellationToken ct = default);

/// <summary>
/// Cancel multiple orders
/// <para><a href="https://docs.coinex.com/api/v2/futures/order/http/cancel-batch-order" /></para>
/// </summary>
/// <param name="symbol">Symbol, for example `ETHUSDT`</param>
/// <param name="orderIds">Ids of orders to cancel</param>
/// <param name="ct">Cancelation Token</param>
/// <returns></returns>
Task<WebCallResult<IEnumerable<CoinExBatchResult<CoinExFuturesOrder>>>> CancelOrdersAsync(string symbol, IEnumerable<long> orderIds, CancellationToken ct = default);

/// <summary>
/// Cancel multiple stop orders
/// <para><a href="https://docs.coinex.com/api/v2/futures/order/http/cancel-batch-stop-order" /></para>
/// </summary>
/// <param name="symbol">Symbol, for example `ETHUSDT`</param>
/// <param name="orderIds">Ids of stop orders to cancel</param>
/// <param name="ct">Cancelation Token</param>
/// <returns></returns>
Task<WebCallResult<IEnumerable<CoinExBatchResult<CoinExStopOrder>>>> CancelStopOrdersAsync(string symbol, IEnumerable<long> orderIds, CancellationToken ct = default);

/// <summary>
/// Get trade list
Expand Down
61 changes: 61 additions & 0 deletions CoinEx.Net/Objects/Models/V2/CoinExFuturesPlaceOrderRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using CoinEx.Net.Enums;
using CryptoExchange.Net.Converters.SystemTextJson;
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.Json.Serialization;

namespace CoinEx.Net.Objects.Models.V2
{
/// <summary>
/// Place order request
/// </summary>
public record CoinExFuturesPlaceOrderRequest
{
/// <summary>
/// The symbol, for example `ETHUSDT`
/// </summary>
[JsonPropertyName("market")]
public string Symbol { get; set; } = string.Empty;
/// <summary>
/// The account type
/// </summary>
[JsonPropertyName("market_type")]
public AccountType AccountType { get; set; }
/// <summary>
/// The side
/// </summary>
[JsonPropertyName("side")]
public OrderSide Side { get; set; }
/// <summary>
/// The order type
/// </summary>
[JsonPropertyName("type")]
public OrderTypeV2 OrderType { get; set; }
/// <summary>
/// The quantity
/// </summary>
[JsonPropertyName("amount"), JsonConverter(typeof(CryptoExchange.Net.Converters.SystemTextJson.DecimalStringWriterConverter))]
public decimal Quantity { get; set; }
/// <summary>
/// The limit price
/// </summary>
[JsonPropertyName("price"), JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault), JsonConverter(typeof(CryptoExchange.Net.Converters.SystemTextJson.DecimalStringWriterConverter))]
public decimal? Price { get; set; }
/// <summary>
/// The client order id
/// </summary>
[JsonPropertyName("client_id"), JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
public string? ClientOrderId { get; set; }
/// <summary>
/// Whether to hide the order
/// </summary>
[JsonPropertyName("is_hide"), JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
public bool? Hide { get; set; }
/// <summary>
/// Self trade prevention mode
/// </summary>
[JsonPropertyName("stp_mode"), JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
public SelfTradePreventionMode? StpMode { get; set; }
}
}
Loading

0 comments on commit b9e07c4

Please sign in to comment.