Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OnGetOpenOrderDetailsAsync() uses new functionality in /v2/private/order #567

Merged
merged 1 commit into from
Dec 21, 2020
Merged
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
50 changes: 29 additions & 21 deletions src/ExchangeSharp/API/Exchanges/Bybit/ExchangeBybitAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -620,10 +620,15 @@ public async Task<IEnumerable<ExchangePosition>> GetCurrentPositionsAsync()
return positions;
}

protected override async Task<IEnumerable<ExchangeOrderResult>> OnGetOpenOrderDetailsAsync(string marketSymbol = null)
private async Task<IEnumerable<ExchangeOrderResult>> DoGetOrderDetailsAsync(string orderId, string marketSymbol = null)
{
var extraParams = new Dictionary<string, object>();
extraParams["order_status"] = "Created,New,PartiallyFilled";

if (orderId != null)
{
extraParams["order_id"] = orderId;
}

if (!string.IsNullOrWhiteSpace(marketSymbol))
{
extraParams["symbol"] = marketSymbol;
Expand All @@ -632,41 +637,44 @@ protected override async Task<IEnumerable<ExchangeOrderResult>> OnGetOpenOrderDe
{
throw new Exception("marketSymbol is required");
}

var queryString = await GetAuthenticatedQueryString(extraParams);
JToken token = GetResult(await DoMakeJsonRequestAsync<JToken>($"/v2/private/order/list?" + queryString, BaseUrl, null, "GET"), out var retCode, out var retMessage);
JToken token = GetResult(await DoMakeJsonRequestAsync<JToken>($"/v2/private/order?" + queryString, BaseUrl, null, "GET"), out var retCode, out var retMessage);

List<ExchangeOrderResult> orders = new List<ExchangeOrderResult>();
foreach (JToken order in token["data"])
if (orderId == null)
{
orders.Add(ParseOrder(order, retCode, retMessage));
foreach (JToken order in token)
{
orders.Add(ParseOrder(order, retCode, retMessage));
}
}
else
{
orders.Add(ParseOrder(token, retCode, retMessage));
}

return orders;
}

//Note, Bybit is not recommending the use of "/v2/private/order/list" now that "/v2/private/order" is capable of returning multiple results
protected override async Task<IEnumerable<ExchangeOrderResult>> OnGetOpenOrderDetailsAsync(string marketSymbol = null)
{
var orders = await DoGetOrderDetailsAsync(null, marketSymbol);
return orders;
}

protected override async Task<ExchangeOrderResult> OnGetOrderDetailsAsync(string orderId, string marketSymbol = null)
{
var extraParams = new Dictionary<string, object>();
extraParams["order_id"] = orderId;
if (!string.IsNullOrWhiteSpace(marketSymbol))
var orders = await DoGetOrderDetailsAsync(orderId, marketSymbol);
if (orders.Count() > 0)
{
extraParams["symbol"] = marketSymbol;
return orders.First();
}
else
{
throw new Exception("marketSymbol is required");
return null;
}

var queryString = await GetAuthenticatedQueryString(extraParams);
JToken token = GetResult(await DoMakeJsonRequestAsync<JToken>($"/v2/private/order?" + queryString, BaseUrl, null, "GET"), out var retCode, out var retMessage);

List<ExchangeOrderResult> orders = new List<ExchangeOrderResult>();
foreach (JToken order in token)
{
orders.Add(ParseOrder(order, retCode, retMessage));
}

return orders[0];
}

protected override async Task OnCancelOrderAsync(string orderId, string marketSymbol = null)
Expand Down