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

Error OnGetRecentTradesAsync() parsing json from token #454

Closed
ferib opened this issue Sep 28, 2019 · 3 comments · Fixed by #513
Closed

Error OnGetRecentTradesAsync() parsing json from token #454

ferib opened this issue Sep 28, 2019 · 3 comments · Fixed by #513

Comments

@ferib
Copy link
Contributor

ferib commented Sep 28, 2019

Json parsing error on ExchangeKuCoinAPI.cs#219
After fixing the KC- headers its now giving a correct result in "token".
But the "token" result is not handler correctly.

@GonzoKK
Copy link

GonzoKK commented Jan 20, 2020

I took a stab at this. Both OnGetRecentTradesAsync and OnGetHistoricalTradesAsync seem to be working now.

image

Download link for ExchangeKuCoinAPI.cs
http://k00.fr/pi9jssl8

protected override async Task<IEnumerable<ExchangeTrade>> OnGetRecentTradesAsync(string marketSymbol, int? limit = null)
{
	//limit is always 100
    List<ExchangeTrade> trades = new List<ExchangeTrade>();
	string url = "/market/histories?symbol=" + marketSymbol ; 
	JToken obj = await MakeJsonRequestAsync<JToken>(url);
	if(obj.HasValues) { //
		foreach(JToken trade in obj) {    
			trades.Add(trade.ParseTrade("size", "price", "side", "time", TimestampType.UnixNanoseconds, idKey: "sequence"));
			//trades.Add(trade.ParseTrade("size", "price", "side", "time", TimestampType.UnixMilliseconds, idKey: "tradeId"));
		}
	}
    return trades.AsEnumerable().Reverse(); //descending - ie from newest to oldest trades
}

protected override async Task OnGetHistoricalTradesAsync(Func<IEnumerable<ExchangeTrade>, bool> callback, string marketSymbol, DateTime? startDate = null, DateTime? endDate = null, int? limit = null)
{
    List<ExchangeTrade> trades = new List<ExchangeTrade>();
    JToken token = await MakeJsonRequestAsync<JToken>("/market/histories?symbol=" + marketSymbol + (startDate == null ? string.Empty : "&since=" + startDate.Value.UnixTimestampFromDateTimeMilliseconds()));
    foreach (JObject trade in token)
    {
        trades.Add(trade.ParseTrade("size", "price", "side", "time", TimestampType.UnixNanoseconds, idKey: "sequence"));
		//trades.Add(trade.ParseTrade("size", "price", "side", "time", TimestampType.UnixMilliseconds, idKey: "tradeId"));
    }
    var rc = callback?.Invoke(trades);
}

@GonzoKK
Copy link

GonzoKK commented Jan 20, 2020

FYI - UnixMilliseconds throws an .ArgumentOutOfRangeException

image

@ferib
Copy link
Contributor Author

ferib commented Jan 20, 2020

@GonzoKK awesome fix there, open a PR and hopefully your fix will be added in the next NuGet version

vslee added a commit to vslee/ExchangeSharp that referenced this issue Jan 23, 2020
- changed endpoint for GetRecentTradesAsync()
- changed TS parsing to UnixNanoseconds for both
- DRY both methods
- fixes DigitalRuby#454
vslee added a commit that referenced this issue Jan 23, 2020
- changed endpoint for GetRecentTradesAsync()
- changed TS parsing to UnixNanoseconds for both
- DRY both methods
- fixes #454
szmcdull pushed a commit to szmcdull/ExchangeSharp that referenced this issue Mar 5, 2020
…gitalRuby#513)

- changed endpoint for GetRecentTradesAsync()
- changed TS parsing to UnixNanoseconds for both
- DRY both methods
- fixes DigitalRuby#454
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants