Skip to content
This repository was archived by the owner on Feb 23, 2022. It is now read-only.
Open
Show file tree
Hide file tree
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
13 changes: 7 additions & 6 deletions lib/binance/client/rest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@ class REST
BASE_URL = 'https://api.binance.com'.freeze

def initialize(api_key: '', secret_key: '',
adapter: Faraday.default_adapter)
adapter: Faraday.default_adapter, proxy: nil)
@clients = {}
@clients[:public] = public_client adapter
@clients[:verified] = verified_client api_key, adapter
@clients[:signed] = signed_client api_key, secret_key, adapter
@clients[:withdraw] = withdraw_client api_key, secret_key, adapter
@clients[:public_withdraw] = public_withdraw_client adapter
@clients[:public] = public_client adapter, proxy
@clients[:verified] = verified_client api_key, adapter, proxy
@clients[:signed] = signed_client api_key, secret_key, adapter, proxy
@clients[:withdraw] = withdraw_client api_key, secret_key, adapter, proxy
@clients[:public_withdraw] = public_withdraw_client adapter, proxy
@clients[:margin] = margin_client api_key, secret_key, adapter, proxy
end

METHODS.each do |method|
Expand Down
33 changes: 22 additions & 11 deletions lib/binance/client/rest/clients.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,24 @@
module Binance
module Client
class REST
def public_client(adapter)
Faraday.new(url: "#{BASE_URL}/api") do |conn|
def public_client(adapter, proxy)
Faraday.new(url: "#{BASE_URL}/api", proxy: proxy) do |conn|
conn.request :json
conn.response :json, content_type: /\bjson$/
conn.adapter adapter
end
end

def verified_client(api_key, adapter)
Faraday.new(url: "#{BASE_URL}/api") do |conn|
def verified_client(api_key, adapter, proxy)
Faraday.new(url: "#{BASE_URL}/api", proxy: proxy) do |conn|
conn.response :json, content_type: /\bjson$/
conn.headers['X-MBX-APIKEY'] = api_key
conn.adapter adapter
end
end

def signed_client(api_key, secret_key, adapter)
Faraday.new(url: "#{BASE_URL}/api") do |conn|
def signed_client(api_key, secret_key, adapter, proxy)
Faraday.new(url: "#{BASE_URL}/api", proxy: proxy) do |conn|
conn.request :json
conn.response :json, content_type: /\bjson$/
conn.headers['X-MBX-APIKEY'] = api_key
Expand All @@ -30,16 +30,27 @@ def signed_client(api_key, secret_key, adapter)
end
end

def public_withdraw_client(adapter)
Faraday.new(url: "#{BASE_URL}/wapi") do |conn|
def public_withdraw_client(adapter, proxy)
Faraday.new(url: "#{BASE_URL}/wapi", proxy: proxy) do |conn|
conn.request :json
conn.response :json, content_type: /\bjson$/
conn.adapter adapter
end
end

def withdraw_client(api_key, secret_key, adapter)
Faraday.new(url: "#{BASE_URL}/wapi") do |conn|
def withdraw_client(api_key, secret_key, adapter, proxy)
Faraday.new(url: "#{BASE_URL}/wapi", proxy: proxy) do |conn|
conn.request :url_encoded
conn.response :json, content_type: /\bjson$/
conn.headers['X-MBX-APIKEY'] = api_key
conn.use TimestampRequestMiddleware
conn.use SignRequestMiddleware, secret_key
conn.adapter adapter
end
end

def margin_client(api_key, secret_key, adapter, proxy)
Faraday.new(url: "#{BASE_URL}/sapi", proxy: proxy) do |conn|
conn.request :url_encoded
conn.response :json, content_type: /\bjson$/
conn.headers['X-MBX-APIKEY'] = api_key
Expand All @@ -50,4 +61,4 @@ def withdraw_client(api_key, secret_key, adapter)
end
end
end
end
end
6 changes: 5 additions & 1 deletion lib/binance/client/rest/endpoints.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ class REST
account_status: 'v3/accountStatus.html',
system_status: 'v3/systemStatus.html',
withdraw_fee: 'v3/withdrawFee.html',
dust_log: 'v3/userAssetDribbletLog.html'
dust_log: 'v3/userAssetDribbletLog.html',
asset_detail: 'v3/assetDetail.html',

# Margin API Endpoints
get_all: 'v1/capital/config/getall'
}.freeze
end
end
Expand Down
9 changes: 8 additions & 1 deletion lib/binance/client/rest/methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,14 @@ class REST
action: :get, endpoint: :withdraw_fee },
# dust_log
{ name: :dust_log, client: :withdraw,
action: :get, endpoint: :dust_log }
action: :get, endpoint: :dust_log },
# asset_detail
{ name: :asset_detail, client: :withdraw,
action: :get, endpoint: :asset_detail },
#get_all
{ name: :get_all, client: :margin,
action: :get, endpoint: :get_all
}
].freeze
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/binance/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Binance
VERSION = '1.2.0'.freeze
VERSION = '1.4.0'.freeze
end