craysiii / binance

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

Added support to Futures-API #33

Closed lucribas closed 4 years ago

lucribas commented 4 years ago

Hello Charles Craysiii,

First I would like to thank you and the contributors for the excellent work of the code in the repository.

Following a small contribution to support Futures-API: https://binance-docs.github.io/apidocs/futures/en/

The changes I made are working correctly. Just not sure if it would be possible to do it in a simpler way.

Could you review if them are in accordance with your good practices?

Thanks!

lucribas commented 4 years ago

I found some endpoints that no longer work. I will correct and resubmit the pull request. Sorry.

dpblnt commented 4 years ago

Hello I'm testing your branch, I'm getting this error after connecting to the user websocket: #<Faye::WebSocket::API::ErrorEvent:0xb65b04d0 @type="error", @message="Error during WebSocket handshake: Unexpected response code: 400", @bubbles=false, @cancelable=false, @current_target=#<Faye::WebSocket::Client:0xb65a5120 @url="wss://fstream.binance.com/ws/", @ready_state=0, @listeners={"message"=>[#<Proc:0xb65a42e8@/usr/local/lib/ruby/gems/2.3.0/gems/binance-1.2.0/lib/binance/client/websocket.rb:427>], "open"=>[#<Proc:0xb65a4298@/usr/local/lib/ruby/gems/2.3.0/gems/binance-1.2.0/lib/binance/client/websocket.rb:427>], "close"=>[#<Proc:0xb65a4248@/usr/local/lib/ruby/gems/2.3.0/gems/binance-1.2.0/lib/binance/client/websocket.rb:427>], "error"=>[#<Proc:0xb65a41f8@/usr/local/lib/ruby/gems/2.3.0/gems/binance-1.2.0/lib/binance/client/websocket.rb:427>]}, @driver=#<WebSocket::Driver::Client:0xb65a501c @listeners={"open"=>[#<Proc:0xb65a466c@/usr/local/lib/ruby/gems/2.3.0/gems/faye-websocket-0.10.7/lib/faye/websocket/api.rb:44>], "message"=>[#<Proc:0xb65a461c@/usr/local/lib/ruby/gems/2.3.0/gems/faye-websocket-0.10.7/lib/faye/websocket/api.rb:45>], "close"=>[#<Proc:0xb65a45cc@/usr/local/lib/ruby/gems/2.3.0/gems/faye-websocket-0.10.7/lib/faye/websocket/api.rb:46>], "error"=>[#<Proc:0xb65a457c@/usr/local/lib/ruby/gems/2.3.0/gems/faye-websocket-0.10.7/lib/faye/websocket/api.rb:48>]}, @socket=#<Faye::WebSocket::Client:0xb65a5120 ...>, @reader=#<WebSocket::Driver::StreamReader:0xb65a4fa4 @buffer="", @offset=0>, @options={:max_length=>nil, :protocols=>nil, :masking=>true}, @max_length=67108863, @headers={"connection"=>"close", "content-type"=>"text/plain", "content-length"=>"40"}, @queue=[], @ready_state=3, @extensions=#<WebSocket::Extensions:0xb65a4edc @rsv3=nil, @rsv2=nil, @rsv1=nil, @by_name={}, @in_order=[], @sessions=[], @index={}>, @stage=0, @masking=true, @protocols=[], @require_masking=nil, @ping_callbacks={}, @message=nil, @frame=nil, @key="AbDvVE1lS+Temfhsuu0jNQ==", @accept="3XA6ThrkpGlIlgAOI35CSLdNYlA=", @http=#<WebSocket::HTTP::Response:0xb65a4d88 @buffer=[79, 110, 101, 32, 111, 114, 32, 109, 111, 114, 101, 32, 115, 116, 114, 101, 97, 109, 32, 110, 97, 109, 101, 115, 32, 97, 114, 101, 32, 110, 111, 116, 32, 118, 97, 108, 105, 100, 58, 32], @env={"rack.input"=>#<StringIO:0xb65b07f0>}, @headers={"connection"=>"close", "content-type"=>"text/plain", "content-length"=>"40"}, @stage=2, @code=400>, @pathname="/ws/", @status=400>, @ping=nil, @ping_id=0, @buffered_amount=0, @stream=#<Faye::WebSocket::Client::Connection::EM_CONNECTION_CLASS:0xb65a4374 @signature=4, @parent=#<Faye::WebSocket::Client:0xb65a5120 ...>>, @proxy=nil, @ping_timer=nil, @close_timer=nil, @close_params=nil, @onerror=nil, @onclose=nil, @onmessage=nil, @onopen=nil, @secure=true, @origin_tls={}, @socket_tls={}, @event_buffers={}>, @target=#<Faye::WebSocket::Client:0xb65a5120 @url="wss://fstream.binance.com/ws/", @ready_state=0, @listeners={"message"=>[#<Proc:0xb65a42e8@/usr/local/lib/ruby/gems/2.3.0/gems/binance-1.2.0/lib/binance/client/websocket.rb:427>], "open"=>[#<Proc:0xb65a4298@/usr/local/lib/ruby/gems/2.3.0/gems/binance-1.2.0/lib/binance/client/websocket.rb:427>], "close"=>[#<Proc:0xb65a4248@/usr/local/lib/ruby/gems/2.3.0/gems/binance-1.2.0/lib/binance/client/websocket.rb:427>], "error"=>[#<Proc:0xb65a41f8@/usr/local/lib/ruby/gems/2.3.0/gems/binance-1.2.0/lib/binance/client/websocket.rb:427>]}, @driver=#<WebSocket::Driver::Client:0xb65a501c @listeners={"open"=>[#<Proc:0xb65a466c@/usr/local/lib/ruby/gems/2.3.0/gems/faye-websocket-0.10.7/lib/faye/websocket/api.rb:44>], "message"=>[#<Proc:0xb65a461c@/usr/local/lib/ruby/gems/2.3.0/gems/faye-websocket-0.10.7/lib/faye/websocket/api.rb:45>], "close"=>[#<Proc:0xb65a45cc@/usr/local/lib/ruby/gems/2.3.0/gems/faye-websocket-0.10.7/lib/faye/websocket/api.rb:46>], "error"=>[#<Proc:0xb65a457c@/usr/local/lib/ruby/gems/2.3.0/gems/faye-websocket-0.10.7/lib/faye/websocket/api.rb:48>]}, @socket=#<Faye::WebSocket::Client:0xb65a5120 ...>, @reader=#<WebSocket::Driver::StreamReader:0xb65a4fa4 @buffer="", @offset=0>, @options={:max_length=>nil, :protocols=>nil, :masking=>true}, @max_length=67108863, @headers={"connection"=>"close", "content-type"=>"text/plain", "content-length"=>"40"}, @queue=[], @ready_state=3, @extensions=#<WebSocket::Extensions:0xb65a4edc @rsv3=nil, @rsv2=nil, @rsv1=nil, @by_name={}, @in_order=[], @sessions=[], @index={}>, @stage=0, @masking=true, @protocols=[], @require_masking=nil, @ping_callbacks={}, @message=nil, @frame=nil, @key="AbDvVE1lS+Temfhsuu0jNQ==", @accept="3XA6ThrkpGlIlgAOI35CSLdNYlA=", @http=#<WebSocket::HTTP::Response:0xb65a4d88 @buffer=[79, 110, 101, 32, 111, 114, 32, 109, 111, 114, 101, 32, 115, 116, 114, 101, 97, 109, 32, 110, 97, 109, 101, 115, 32, 97, 114, 101, 32, 110, 111, 116, 32, 118, 97, 108, 105, 100, 58, 32], @env={"rack.input"=>#<StringIO:0xb65b07f0>}, @headers={"connection"=>"close", "content-type"=>"text/plain", "content-length"=>"40"}, @stage=2, @code=400>, @pathname="/ws/", @status=400>, @ping=nil, @ping_id=0, @buffered_amount=0, @stream=#<Faye::WebSocket::Client::Connection::EM_CONNECTION_CLASS:0xb65a4374 @signature=4, @parent=#<Faye::WebSocket::Client:0xb65a5120 ...>>, @proxy=nil, @ping_timer=nil, @close_timer=nil, @close_params=nil, @onerror=nil, @onclose=nil, @onmessage=nil, @onopen=nil, @secure=true, @origin_tls={}, @socket_tls={}, @event_buffers={}>, @event_phase=2> Do you have any clue what might I have done wrong? Thanks

dpblnt commented 4 years ago

Found it, this way it works: listen_key = client.listenKey["listenKey"]