Skip to content

Commit 3aff3e6

Browse files
authored
Fixes for Bittrex and Kraken after testing live orders. (#597)
* Use AltMarketSymbol to hanlde Kraken WebSocket symbol difference and Gemini lower case symbol names. Pass isWebsocket flag in console app. * Allow HttpStatusCode.Created response as a successful request. Bittrex API returns HttpStatusCode.Created when placing an order. * Limit maxCount to Bittrex's only supported values of 1, 25, and 500. When submitting a limit order, add required timeInForce property. * Round Kraken order limit price to thier 'pair_decimals' precision.
1 parent 99f79f4 commit 3aff3e6

File tree

3 files changed

+26
-4
lines changed

3 files changed

+26
-4
lines changed

src/ExchangeSharp/API/Common/APIRequestMaker.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ public async Task<string> MakeRequestAsync(string url, string? baseUrl = null, D
216216
using (StreamReader responseStreamReader = new StreamReader(responseStream))
217217
responseString = responseStreamReader.ReadToEnd();
218218

219-
if (response.StatusCode != HttpStatusCode.OK)
219+
if (response.StatusCode != HttpStatusCode.OK && response.StatusCode != HttpStatusCode.Created)
220220
{
221221
// 404 maybe return empty responseString
222222
if (string.IsNullOrWhiteSpace(responseString))

src/ExchangeSharp/API/Exchanges/Bittrex/ExchangeBittrexAPI.cs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,25 @@ protected override async Task<IEnumerable<KeyValuePair<string, ExchangeTicker>>>
252252
#region OrderBooks
253253
protected override async Task<ExchangeOrderBook> OnGetOrderBookAsync(string marketSymbol, int maxCount = 25)
254254
{
255-
JToken token = await MakeJsonRequestAsync<JToken>("/markets/" + marketSymbol + "/orderbook" + marketSymbol + "&depth=" + maxCount);
255+
// Bittrex API allowed values are [1, 25, 500], default is 25.
256+
if (maxCount > 100)
257+
{
258+
maxCount = 500;
259+
}
260+
else if (maxCount > 25 && maxCount <= 100) // ExchangeSharp default.
261+
{
262+
maxCount = 25;
263+
}
264+
else if (maxCount > 1 && maxCount <= 25)
265+
{
266+
maxCount = 25;
267+
}
268+
else
269+
{
270+
maxCount = 1;
271+
}
272+
273+
JToken token = await MakeJsonRequestAsync<JToken>("/markets/" + marketSymbol + "/orderbook" + "?depth=" + maxCount);
256274
return ExchangeAPIExtensions.ParseOrderBookFromJTokenDictionaries(token, "ask", "bid", "rate", "quantity", maxCount: maxCount);
257275
}
258276

@@ -370,7 +388,7 @@ protected override async Task<ExchangeOrderResult> OnPlaceOrderAsync(ExchangeOrd
370388
if (order.OrderType == ExchangeSharp.OrderType.Limit)
371389
{
372390
orderParams.Add("limit", orderPrice);
373-
//orderParams.Add("timeInForce", "GOOD_TIL_CANCELLED");
391+
orderParams.Add("timeInForce", "GOOD_TIL_CANCELLED");
374392
}
375393

376394
foreach (KeyValuePair<string, object> kv in order.ExtraParameters)

src/ExchangeSharp/API/Exchanges/Kraken/ExchangeKrakenAPI.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -749,13 +749,17 @@ protected override async Task<Dictionary<string, decimal>> OnGetAmountsAvailable
749749

750750
protected override async Task<ExchangeOrderResult> OnPlaceOrderAsync(ExchangeOrderRequest order)
751751
{
752+
IEnumerable<ExchangeMarket> markets = await OnGetMarketSymbolsMetadataAsync();
753+
ExchangeMarket market = markets.Where(m => m.MarketSymbol == order.MarketSymbol).First<ExchangeMarket>();
754+
752755
object nonce = await GenerateNonceAsync();
753756
Dictionary<string, object> payload = new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase)
754757
{ { "pair", order.MarketSymbol }, { "type", (order.IsBuy ? "buy" : "sell") }, { "ordertype", order.OrderType.ToString().ToLowerInvariant() }, { "volume", order.RoundAmount().ToStringInvariant() }, { "trading_agreement", "agree" }, { "nonce", nonce }
755758
};
756759
if (order.OrderType != OrderType.Market)
757760
{
758-
payload.Add("price", order.Price.ToStringInvariant());
761+
int precision = BitConverter.GetBytes(Decimal.GetBits((decimal)market.PriceStepSize)[3])[2];
762+
payload.Add("price", Math.Round(order.Price, precision).ToStringInvariant());
759763
}
760764
order.ExtraParameters.CopyTo(payload);
761765

0 commit comments

Comments
 (0)