Skip to content

Small fixes to BTSE #547

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

Merged
merged 2 commits into from
Jun 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
33 changes: 25 additions & 8 deletions src/ExchangeSharp/API/Exchanges/BTSE/ExchangeBTSEAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ protected override async Task OnCancelOrderAsync(string orderId, string? marketS
{"orderID", orderId}
});

await MakeJsonRequestAsync<JToken>(url.ToStringInvariant().Replace(BaseUrl, ""),
await MakeJsonRequestAsync<JToken>($"/api/v3.1/order{url.Query}",
requestMethod: "DELETE", payload: payload);
}

Expand Down Expand Up @@ -116,8 +116,7 @@ protected override async Task<IEnumerable<ExchangeOrderResult>> OnGetOpenOrderDe
{"symbol", marketSymbol}
});


var result = await MakeJsonRequestAsync<JToken>(url.ToStringInvariant().Replace(BaseUrl, ""),
var result = await MakeJsonRequestAsync<JToken>("/api/v3.1/user/open_orders"+url.Query,
requestMethod: "GET", payload: payload);

return Extract2(result, token => new ExchangeOrderResult()
Expand All @@ -128,10 +127,29 @@ protected override async Task<IEnumerable<ExchangeOrderResult>> OnGetOpenOrderDe
IsBuy = token["side"].Value<string>() == "BUY",
Price = token["price"].Value<decimal>(),
MarketSymbol = token["symbol"].Value<string>(),
OrderDate = token["timestamp"].ConvertInvariant<long>().UnixTimeStampToDateTimeMilliseconds()
OrderDate = token["timestamp"].ConvertInvariant<long>().UnixTimeStampToDateTimeMilliseconds(),
ClientOrderId = token["clOrderID"].Value<string>(),
Result = FromOrderState(token["orderState"].Value<string>())
});
}

private ExchangeAPIOrderResult FromOrderState(string s)
{
switch (s)
{
case "STATUS_ACTIVE":
return ExchangeAPIOrderResult.Pending;
case "ORDER_CANCELLED":
return ExchangeAPIOrderResult.Canceled;
case "ORDER_FULLY_TRANSACTED":
return ExchangeAPIOrderResult.Filled;
case "ORDER_PARTIALLY_TRANSACTED":
return ExchangeAPIOrderResult.FilledPartially;
default:
return ExchangeAPIOrderResult.Unknown;
}
}

protected override async Task<ExchangeOrderResult> OnPlaceOrderAsync(ExchangeOrderRequest request)
{var payload = await GetNoncePayloadAsync();

Expand All @@ -146,21 +164,21 @@ protected override async Task<ExchangeOrderResult> OnPlaceOrderAsync(ExchangeOrd

dict.Add("size", request.Amount);
dict.Add("side", request.IsBuy ? "BUY" : "SELL");
dict.Add("price", request.Price);
dict.Add("symbol", request.MarketSymbol);

switch (request.OrderType )
{
case OrderType.Limit:
dict.Add("txType", "LIMIT");
dict.Add("type", "LIMIT");
dict.Add("price", request.Price);
break;
case OrderType.Market:

dict.Add("type", "MARKET");
break;
case OrderType.Stop:
dict.Add("stopPrice", request.StopPrice);
dict.Add("price", request.Price);
dict.Add("txType", "STOP");
break;
}
Expand Down Expand Up @@ -246,7 +264,6 @@ protected override async Task ProcessRequestAsync(IHttpWebRequest request, Dicti
var nonce = payload["nonce"].ToString();
payload.Remove("nonce");


var json = JsonConvert.SerializeObject(body ?? payload);
if (json == "{}")
{
Expand All @@ -260,7 +277,7 @@ protected override async Task ProcessRequestAsync(IHttpWebRequest request, Dicti
}

var hexSha384 = CryptoUtility.SHA384Sign(
$"{request.RequestUri.PathAndQuery.Replace("/spot", string.Empty)}{nonce}{json}",
$"{request.RequestUri.AbsolutePath.Replace("/spot", string.Empty)}{nonce}{json}",
passphrase);
request.AddHeader("btse-sign", hexSha384);
request.AddHeader("btse-nonce", nonce);
Expand Down