From 500795bd5aa35c2b8a42c0db06778a18bdcc6270 Mon Sep 17 00:00:00 2001 From: Strahinja Date: Tue, 13 Apr 2021 12:42:11 +0200 Subject: [PATCH 1/9] add withdraw sapi --- lib/binance/client/rest/clients.rb | 13 ++++++++++++- lib/binance/client/rest/endpoints.rb | 1 + lib/binance/client/rest/methods.rb | 3 +++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/binance/client/rest/clients.rb b/lib/binance/client/rest/clients.rb index 7831998..e428300 100644 --- a/lib/binance/client/rest/clients.rb +++ b/lib/binance/client/rest/clients.rb @@ -48,6 +48,17 @@ def withdraw_client(api_key, secret_key, adapter) conn.adapter adapter end end + + def withdraw_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 \ No newline at end of file +end diff --git a/lib/binance/client/rest/endpoints.rb b/lib/binance/client/rest/endpoints.rb index 7595e89..44dc611 100644 --- a/lib/binance/client/rest/endpoints.rb +++ b/lib/binance/client/rest/endpoints.rb @@ -26,6 +26,7 @@ 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', diff --git a/lib/binance/client/rest/methods.rb b/lib/binance/client/rest/methods.rb index 6ff72ed..9a4c3ea 100644 --- a/lib/binance/client/rest/methods.rb +++ b/lib/binance/client/rest/methods.rb @@ -79,6 +79,9 @@ class REST # #withdraw! { name: :withdraw!, client: :withdraw, action: :post, endpoint: :withdraw }, + # #withdraw_sapi! + { name: :withdraw_sapi!, client: :withdraw_sapi_client, + action: :post, endpoint: :withdraw_sapi }, # #deposit_history { name: :deposit_history, client: :withdraw, action: :get, endpoint: :deposit_history }, From f7f369fab63f2799fb964f60e6c3221dc78f2b68 Mon Sep 17 00:00:00 2001 From: djuks Date: Tue, 13 Apr 2021 12:49:22 +0200 Subject: [PATCH 2/9] change name of withdraw_sapi_client --- lib/binance/client/rest/clients.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/binance/client/rest/clients.rb b/lib/binance/client/rest/clients.rb index e428300..1c20737 100644 --- a/lib/binance/client/rest/clients.rb +++ b/lib/binance/client/rest/clients.rb @@ -49,7 +49,7 @@ def withdraw_client(api_key, secret_key, adapter) end end - def withdraw_client(api_key, secret_key, adapter) + 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$/ From 75a0ac8b2631ecb63b251e0ab70f6e2b62cf84a5 Mon Sep 17 00:00:00 2001 From: djuks Date: Tue, 13 Apr 2021 13:41:26 +0200 Subject: [PATCH 3/9] initialize withdraw_sapi client --- lib/binance/client/rest.rb | 1 + lib/binance/client/rest/methods.rb | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/binance/client/rest.rb b/lib/binance/client/rest.rb index e3a9a59..caf9705 100644 --- a/lib/binance/client/rest.rb +++ b/lib/binance/client/rest.rb @@ -18,6 +18,7 @@ def initialize(api_key: '', secret_key: '', @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 end diff --git a/lib/binance/client/rest/methods.rb b/lib/binance/client/rest/methods.rb index 9a4c3ea..8c7aed3 100644 --- a/lib/binance/client/rest/methods.rb +++ b/lib/binance/client/rest/methods.rb @@ -80,7 +80,7 @@ class REST { name: :withdraw!, client: :withdraw, action: :post, endpoint: :withdraw }, # #withdraw_sapi! - { name: :withdraw_sapi!, client: :withdraw_sapi_client, + { name: :withdraw_sapi!, client: :withdraw_sapi, action: :post, endpoint: :withdraw_sapi }, # #deposit_history { name: :deposit_history, client: :withdraw, From c7ea6c351e1d3075286f151536a38d68799e53e3 Mon Sep 17 00:00:00 2001 From: djuks Date: Tue, 13 Apr 2021 14:00:51 +0200 Subject: [PATCH 4/9] add all_coin_info --- lib/binance/client/rest/endpoints.rb | 3 ++- lib/binance/client/rest/methods.rb | 5 ++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/binance/client/rest/endpoints.rb b/lib/binance/client/rest/endpoints.rb index 44dc611..93d57d7 100644 --- a/lib/binance/client/rest/endpoints.rb +++ b/lib/binance/client/rest/endpoints.rb @@ -33,7 +33,8 @@ 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', + all_coin_info: 'v1/capital/config/getall' }.freeze end end diff --git a/lib/binance/client/rest/methods.rb b/lib/binance/client/rest/methods.rb index 8c7aed3..fae5f27 100644 --- a/lib/binance/client/rest/methods.rb +++ b/lib/binance/client/rest/methods.rb @@ -102,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 From 34ad1f95e192aa48ecf4331710e746e5ef7a5698 Mon Sep 17 00:00:00 2001 From: djuks Date: Sat, 29 May 2021 02:24:50 +0200 Subject: [PATCH 5/9] fix base_url --- lib/binance/client/rest.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/binance/client/rest.rb b/lib/binance/client/rest.rb index caf9705..8281ee5 100644 --- a/lib/binance/client/rest.rb +++ b/lib/binance/client/rest.rb @@ -9,7 +9,7 @@ module Binance module Client class REST - BASE_URL = 'https://api.binance.com'.freeze + BASE_URL = Rails.env.test? ? 'https://testnet.binance.vision/api'.freeze : 'https://api.binance.com'.freeze def initialize(api_key: '', secret_key: '', adapter: Faraday.default_adapter) From 176d341b2fc1bd2c306d459fd737828f15ec39db Mon Sep 17 00:00:00 2001 From: djuks Date: Mon, 31 May 2021 10:01:55 +0200 Subject: [PATCH 6/9] fix base url --- lib/binance/client/rest.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/binance/client/rest.rb b/lib/binance/client/rest.rb index 8281ee5..0d8abb9 100644 --- a/lib/binance/client/rest.rb +++ b/lib/binance/client/rest.rb @@ -9,7 +9,7 @@ module Binance module Client class REST - BASE_URL = Rails.env.test? ? 'https://testnet.binance.vision/api'.freeze : 'https://api.binance.com'.freeze + BASE_URL = Rails.env.test? ? 'https://testnet.binance.vision'.freeze : 'https://api.binance.com'.freeze def initialize(api_key: '', secret_key: '', adapter: Faraday.default_adapter) From 55048a64412bc5bafa9fd1291e73efa981dd5093 Mon Sep 17 00:00:00 2001 From: djuks Date: Mon, 7 Jun 2021 10:33:12 +0200 Subject: [PATCH 7/9] set test base_url for test and dev env --- lib/binance/client/rest.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/binance/client/rest.rb b/lib/binance/client/rest.rb index 0d8abb9..95c691c 100644 --- a/lib/binance/client/rest.rb +++ b/lib/binance/client/rest.rb @@ -9,7 +9,7 @@ module Binance module Client class REST - BASE_URL = Rails.env.test? ? 'https://testnet.binance.vision'.freeze : 'https://api.binance.com'.freeze + BASE_URL = Rails.env.test? || Rails.env.development? ? 'https://testnet.binance.vision'.freeze : 'https://api.binance.com'.freeze def initialize(api_key: '', secret_key: '', adapter: Faraday.default_adapter) From 5c1a4d88286fd13d310c12d291005679c077b4db Mon Sep 17 00:00:00 2001 From: djuks Date: Mon, 7 Jun 2021 11:22:57 +0200 Subject: [PATCH 8/9] use api_url from init method --- lib/binance/client/rest.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/binance/client/rest.rb b/lib/binance/client/rest.rb index 95c691c..54ac98a 100644 --- a/lib/binance/client/rest.rb +++ b/lib/binance/client/rest.rb @@ -9,10 +9,9 @@ module Binance module Client class REST - BASE_URL = Rails.env.test? || Rails.env.development? ? 'https://testnet.binance.vision'.freeze : '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 @@ -20,8 +19,11 @@ def initialize(api_key: '', secret_key: '', @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 + METHODS.each do |method| define_method(method[:name]) do |options = {}| response = @clients[method[:client]].send(method[:action]) do |req| From 3d4c86090ddcca22ede78b0e57f4e6da3f44463b Mon Sep 17 00:00:00 2001 From: djuks Date: Mon, 7 Jun 2021 11:35:53 +0200 Subject: [PATCH 9/9] freeze base_url --- lib/binance/client/rest.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/binance/client/rest.rb b/lib/binance/client/rest.rb index 54ac98a..169baf0 100644 --- a/lib/binance/client/rest.rb +++ b/lib/binance/client/rest.rb @@ -22,7 +22,7 @@ def initialize(api_key: '', secret_key: '', @api_url = api_url end - BASE_URL = @api_url + BASE_URL = @api_url.freeze METHODS.each do |method| define_method(method[:name]) do |options = {}|