craysiii / binance

API Wrapper for the Binance cryptocurrency exchange written in Ruby.
MIT License
97 stars 79 forks source link

Add Binance::Client::REST::HTTP2 #15

Closed kke closed 6 years ago

kke commented 6 years ago

Still quite untested and mostly proof of concept / work in progress.

Adds net-http2 dependency and brings an alternative Binance::Client::REST::HTTP2 client for you to play with.

This can be used like:

rest = Binance::Client::REST::HTTP2.new(api_key: 'xxx', secret_key: 'xyz')
request = rest.klines(symbol: 'XRPBTC', interval: '5m', limit: 10)
request2 = rest.klines(symbol: 'APPCBTC', interval: '5m', limit: 10)

request.on(:body_chunk) do |chunk|
  puts 'xrp: %s' % chunk
end

request2.on(:body_chunk) do |chunk|
  puts 'appc: %s' % chunk
end

rest.call_async(request)
rest.call_async(request2)

or in not-so-async manner:

rest = Binance::Client::REST::HTTP2.new(api_key: 'xxx', secret_key: 'xyz')
puts 'xrp: %p' % rest.call(rest.klines(symbol: 'XRPBTC', interval: '5m', limit: 10))

I haven't done any real benchmarking, but it SEEMS to react quite a lot faster than the regular Binance::Client::REST does (especially after the first request)

kke commented 6 years ago

Might have been a waste of time. The public endpoints are working and responding 4x faster, but the signed ones do not, perhaps binance can't read the api key header or then I'm just sending it wrong.

I suppose reusing connections on http1 can bring the same kind of speed boost. Need to try.

craysiii commented 6 years ago

I will take the commits you pushed to this PR and try to work with them in 1.0.