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

Fixes for Bittrex and Kraken after testing live orders. #597

Merged
merged 5 commits into from
Jun 11, 2021
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
2 changes: 1 addition & 1 deletion src/ExchangeSharp/API/Common/APIRequestMaker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ public async Task<string> MakeRequestAsync(string url, string? baseUrl = null, D
using (StreamReader responseStreamReader = new StreamReader(responseStream))
responseString = responseStreamReader.ReadToEnd();

if (response.StatusCode != HttpStatusCode.OK)
if (response.StatusCode != HttpStatusCode.OK && response.StatusCode != HttpStatusCode.Created)
{
// 404 maybe return empty responseString
if (string.IsNullOrWhiteSpace(responseString))
Expand Down
22 changes: 20 additions & 2 deletions src/ExchangeSharp/API/Exchanges/Bittrex/ExchangeBittrexAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,25 @@ protected override async Task<IEnumerable<KeyValuePair<string, ExchangeTicker>>>
#region OrderBooks
protected override async Task<ExchangeOrderBook> OnGetOrderBookAsync(string marketSymbol, int maxCount = 25)
{
JToken token = await MakeJsonRequestAsync<JToken>("/markets/" + marketSymbol + "/orderbook" + marketSymbol + "&depth=" + maxCount);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This URL is invalid. Fixed below.

// Bittrex API allowed values are [1, 25, 500], default is 25.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (maxCount > 100)
{
maxCount = 500;
}
else if (maxCount > 25 && maxCount <= 100) // ExchangeSharp default.
{
maxCount = 25;
}
else if (maxCount > 1 && maxCount <= 25)
{
maxCount = 25;
}
else
{
maxCount = 1;
}

JToken token = await MakeJsonRequestAsync<JToken>("/markets/" + marketSymbol + "/orderbook" + "?depth=" + maxCount);
return ExchangeAPIExtensions.ParseOrderBookFromJTokenDictionaries(token, "ask", "bid", "rate", "quantity", maxCount: maxCount);
}

Expand Down Expand Up @@ -370,7 +388,7 @@ protected override async Task<ExchangeOrderResult> OnPlaceOrderAsync(ExchangeOrd
if (order.OrderType == ExchangeSharp.OrderType.Limit)
{
orderParams.Add("limit", orderPrice);
//orderParams.Add("timeInForce", "GOOD_TIL_CANCELLED");
orderParams.Add("timeInForce", "GOOD_TIL_CANCELLED");
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bittrex V3 API is saying this is a required parameter now for limit orders.

}

foreach (KeyValuePair<string, object> kv in order.ExtraParameters)
Expand Down
6 changes: 5 additions & 1 deletion src/ExchangeSharp/API/Exchanges/Kraken/ExchangeKrakenAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -749,13 +749,17 @@ protected override async Task<Dictionary<string, decimal>> OnGetAmountsAvailable

protected override async Task<ExchangeOrderResult> OnPlaceOrderAsync(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)
{ { "pair", order.MarketSymbol }, { "type", (order.IsBuy ? "buy" : "sell") }, { "ordertype", order.OrderType.ToString().ToLowerInvariant() }, { "volume", order.RoundAmount().ToStringInvariant() }, { "trading_agreement", "agree" }, { "nonce", nonce }
};
if (order.OrderType != OrderType.Market)
{
payload.Add("price", order.Price.ToStringInvariant());
int precision = BitConverter.GetBytes(Decimal.GetBits((decimal)market.PriceStepSize)[3])[2];
payload.Add("price", Math.Round(order.Price, precision).ToStringInvariant());
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This rounding avoids an error returned by Kraken's API that price can only have so many decimals.

}
order.ExtraParameters.CopyTo(payload);

Expand Down