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

[Bitstamp] Populate order status #645

Merged
merged 3 commits into from
Sep 14, 2021
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
38 changes: 33 additions & 5 deletions src/ExchangeSharp/API/Exchanges/Bitstamp/ExchangeBitstampAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -244,11 +244,24 @@ protected override async Task<ExchangeOrderResult> OnGetOrderDetailsAsync(string
payload["id"] = orderId;
JObject result = await MakeJsonRequestAsync<JObject>(url, null, payload, "POST");

// status can be 'In Queue', 'Open' or 'Finished'
JArray transactions = result["transactions"] as JArray;
var transactions = result["transactions"] as JArray;
var anyTransaction = transactions.Any();

// status can be 'Canceled', 'Open' or 'Finished'
var statusCode = result.Value<string>("status");
var status = GetOrderResultFromStatus(statusCode, anyTransaction);

// empty transaction array means that order is InQueue or Open and AmountFilled == 0
// return empty order in this case. no any additional info available at this point
if (!transactions.Any()) { return new ExchangeOrderResult() { OrderId = orderId }; }
if (!anyTransaction)
{
return new ExchangeOrderResult
{
OrderId = orderId,
Result = status,
ResultCode = statusCode
};
}
JObject first = transactions.First() as JObject;
List<string> excludeStrings = new List<string>() { "tid", "price", "fee", "datetime", "type", "btc", "usd", "eur" };

Expand Down Expand Up @@ -291,7 +304,9 @@ protected override async Task<ExchangeOrderResult> OnGetOrderDetailsAsync(string
MarketSymbol = _symbol,
AveragePrice = spentQuoteCurrency / amountFilled,
Price = price,
};
Result = status,
ResultCode = statusCode
};
}

protected override async Task<IEnumerable<ExchangeOrderResult>> OnGetOpenOrderDetailsAsync(string marketSymbol = null)
Expand Down Expand Up @@ -322,7 +337,20 @@ protected override async Task<IEnumerable<ExchangeOrderResult>> OnGetOpenOrderDe
return orders;
}

public class BitstampTransaction
private ExchangeAPIOrderResult GetOrderResultFromStatus(string status, bool anyTransactions)
{
switch (status?.ToLower())
{
case "finished": return ExchangeAPIOrderResult.Filled;
case "open": return anyTransactions
? ExchangeAPIOrderResult.FilledPartially
: ExchangeAPIOrderResult.Pending;
case "canceled": return ExchangeAPIOrderResult.Canceled;
default: return ExchangeAPIOrderResult.Unknown;
}
}

public class BitstampTransaction
{
public BitstampTransaction(string id, DateTime dateTime, int type, string symbol, decimal fees, string orderId, decimal quantity, decimal price, bool isBuy)
{
Expand Down