Skip to content
This repository has been archived by the owner on Feb 23, 2022. It is now read-only.

Chore/freeze base url #45

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 6 additions & 3 deletions lib/binance/client/rest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,21 @@
module Binance
module Client
class REST
BASE_URL = 'https://api.binance.com'.freeze

def initialize(api_key: '', secret_key: '',
adapter: Faraday.default_adapter)
adapter: Faraday.default_adapter,
api_url: '')
@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[:withdraw_sapi] = withdraw_sapi_client api_key, secret_key, adapter
@clients[:public_withdraw] = public_withdraw_client adapter
@api_url = api_url
end

BASE_URL = @api_url.freeze

METHODS.each do |method|
define_method(method[:name]) do |options = {}|
response = @clients[method[:client]].send(method[:action]) do |req|
Expand Down
13 changes: 12 additions & 1 deletion lib/binance/client/rest/clients.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,17 @@ def withdraw_client(api_key, secret_key, adapter)
conn.adapter adapter
end
end

def withdraw_sapi_client(api_key, secret_key, adapter)
Faraday.new(url: "#{BASE_URL}/sapi") 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
end
end
end
end
4 changes: 3 additions & 1 deletion lib/binance/client/rest/endpoints.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,15 @@ class REST

# Withdraw API Endpoints
withdraw: 'v3/withdraw.html',
withdraw_sapi: 'v1/capital/withdraw/apply',
deposit_history: 'v3/depositHistory.html',
withdraw_history: 'v3/withdrawHistory.html',
deposit_address: 'v3/depositAddress.html',
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',
all_coin_info: 'v1/capital/config/getall'
}.freeze
end
end
Expand Down
8 changes: 7 additions & 1 deletion lib/binance/client/rest/methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ class REST
# #withdraw!
{ name: :withdraw!, client: :withdraw,
action: :post, endpoint: :withdraw },
# #withdraw_sapi!
{ name: :withdraw_sapi!, client: :withdraw_sapi,
action: :post, endpoint: :withdraw_sapi },
# #deposit_history
{ name: :deposit_history, client: :withdraw,
action: :get, endpoint: :deposit_history },
Expand All @@ -99,7 +102,10 @@ class REST
action: :get, endpoint: :withdraw_fee },
# dust_log
{ name: :dust_log, client: :withdraw,
action: :get, endpoint: :dust_log }
action: :get, endpoint: :dust_log },
# all_coin_info
{ name: :all_coin_info, client: :withdraw_sapi,
action: :get, endpoint: :all_coin_info }
].freeze
end
end
Expand Down