binance 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/binance.rb +3 -0
- data/lib/binance/client/rest.rb +29 -0
- data/lib/binance/client/rest/account_api.rb +81 -0
- data/lib/binance/client/rest/public_api.rb +76 -0
- data/lib/binance/client/rest/sign_request_middleware.rb +18 -0
- data/lib/binance/client/rest/timestamp_request_middleware.rb +19 -0
- data/lib/binance/client/rest/withdraw_api.rb +58 -0
- data/lib/binance/version.rb +4 -0
- metadata +124 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 6c9c3f87cba107fc0bf7411e028402d76e4f47c5
|
4
|
+
data.tar.gz: 7faf41955b58450717a7082ac8ffcde28543d136
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d92e022effb61629296909c52326c1cc36d0a9e35dd2d25aabbbc0645a7e5538693b4362b86a50c0b4e36eebfa3387df4e8042a4a65238635c453220d0d6b88e
|
7
|
+
data.tar.gz: b4628f4362d888e49f79ed07fedef15fd269576eb1a4d1e5fed65c38eabf33b6827730b97218dc72a98195dc0b6ae9913e0babaa228b6cf69561fa776a4bec31
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'binance'
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require 'irb'
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/lib/binance.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
|
2
|
+
require 'faraday'
|
3
|
+
require_relative 'rest/public_api'
|
4
|
+
require_relative 'rest/account_api'
|
5
|
+
require_relative 'rest/withdraw_api'
|
6
|
+
|
7
|
+
module Binance
|
8
|
+
module Client
|
9
|
+
# Provides low level methods for Binance APIs via their REST interface
|
10
|
+
class REST
|
11
|
+
BASE_URL = 'https://www.binance.com'.freeze
|
12
|
+
|
13
|
+
include REST::Public_API
|
14
|
+
include REST::Account_API
|
15
|
+
include REST::Withdraw_API
|
16
|
+
|
17
|
+
def initialize(api_key: '', secret_key: '')
|
18
|
+
@api_key = api_key
|
19
|
+
@secret_key = secret_key
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.add_query_param(query, key, value)
|
23
|
+
query = query.to_s
|
24
|
+
query << '&' unless query.empty?
|
25
|
+
query << "#{Faraday::Utils.escape key}=#{Faraday::Utils.escape value}"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
|
2
|
+
require 'faraday'
|
3
|
+
require 'faraday_middleware'
|
4
|
+
require_relative 'sign_request_middleware'
|
5
|
+
require_relative 'timestamp_request_middleware'
|
6
|
+
|
7
|
+
module Binance
|
8
|
+
module Client
|
9
|
+
class REST
|
10
|
+
# API endpoints that require a timestamp and signature
|
11
|
+
module Account_API
|
12
|
+
def account_api
|
13
|
+
Faraday.new(url: "#{BASE_URL}/api/v3") do |conn|
|
14
|
+
conn.request :json
|
15
|
+
conn.response :json, content_type: /\bjson$/
|
16
|
+
conn.headers['X-MBX-APIKEY'] = @api_key
|
17
|
+
conn.use TimestampRequestMiddleware
|
18
|
+
conn.use SignRequestMiddleware, @secret_key
|
19
|
+
conn.adapter Faraday.default_adapter
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def create_order(options)
|
24
|
+
response = account_api.post do |req|
|
25
|
+
req.url 'order'
|
26
|
+
req.params.merge! options
|
27
|
+
end
|
28
|
+
response.body
|
29
|
+
end
|
30
|
+
|
31
|
+
def query_order(options)
|
32
|
+
response = account_api.get do |req|
|
33
|
+
req.url 'order'
|
34
|
+
req.params.merge! options
|
35
|
+
end
|
36
|
+
response.body
|
37
|
+
end
|
38
|
+
|
39
|
+
def cancel_order(options)
|
40
|
+
response = account_api.delete do |req|
|
41
|
+
req.url 'order'
|
42
|
+
req.params.merge! options
|
43
|
+
end
|
44
|
+
response.body
|
45
|
+
end
|
46
|
+
|
47
|
+
def open_orders(options)
|
48
|
+
response = account_api.get do |req|
|
49
|
+
req.url 'openOrders'
|
50
|
+
req.params.merge! options
|
51
|
+
end
|
52
|
+
response.body
|
53
|
+
end
|
54
|
+
|
55
|
+
def all_orders(options)
|
56
|
+
response = account_api.get do |req|
|
57
|
+
req.url 'allOrders'
|
58
|
+
req.params.merge! options
|
59
|
+
end
|
60
|
+
response.body
|
61
|
+
end
|
62
|
+
|
63
|
+
def account_info(options = {})
|
64
|
+
response = account_api.get do |req|
|
65
|
+
req.url 'account'
|
66
|
+
req.params.merge! options
|
67
|
+
end
|
68
|
+
response.body
|
69
|
+
end
|
70
|
+
|
71
|
+
def account_trade_list(options)
|
72
|
+
response = account_api.get do |req|
|
73
|
+
req.url 'myTrades'
|
74
|
+
req.params.merge! options
|
75
|
+
end
|
76
|
+
response.body
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
|
2
|
+
require 'faraday'
|
3
|
+
require 'faraday_middleware'
|
4
|
+
|
5
|
+
module Binance
|
6
|
+
module Client
|
7
|
+
class REST
|
8
|
+
# API endpoints that don't require any type of authentication
|
9
|
+
module Public_API
|
10
|
+
def public_api
|
11
|
+
Faraday.new(url: "#{BASE_URL}/api/v1") do |conn|
|
12
|
+
conn.request :json
|
13
|
+
conn.response :json, content_type: /\bjson$/
|
14
|
+
conn.adapter Faraday.default_adapter
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def ping
|
19
|
+
public_api.get('ping').body
|
20
|
+
end
|
21
|
+
|
22
|
+
def time
|
23
|
+
public_api.get('time').body
|
24
|
+
end
|
25
|
+
|
26
|
+
def exchange_info
|
27
|
+
public_api.get('exchangeInfo').body
|
28
|
+
end
|
29
|
+
|
30
|
+
def products
|
31
|
+
public_api.get('/exchange/public/product').body
|
32
|
+
end
|
33
|
+
|
34
|
+
def depth(options)
|
35
|
+
response = public_api.get do |req|
|
36
|
+
req.url 'depth'
|
37
|
+
req.params.merge! options
|
38
|
+
end
|
39
|
+
response.body
|
40
|
+
end
|
41
|
+
|
42
|
+
def agg_trades(options)
|
43
|
+
response = public_api.get do |req|
|
44
|
+
req.url 'aggTrades'
|
45
|
+
req.params.merge! options
|
46
|
+
end
|
47
|
+
response.body
|
48
|
+
end
|
49
|
+
|
50
|
+
def klines(options)
|
51
|
+
response = public_api.get do |req|
|
52
|
+
req.url 'klines'
|
53
|
+
req.params.merge! options
|
54
|
+
end
|
55
|
+
response.body
|
56
|
+
end
|
57
|
+
|
58
|
+
def twenty_four_hour(options)
|
59
|
+
response = public_api.get do |req|
|
60
|
+
req.url 'ticker/24hr'
|
61
|
+
req.params.merge! options
|
62
|
+
end
|
63
|
+
response.body
|
64
|
+
end
|
65
|
+
|
66
|
+
def all_prices
|
67
|
+
public_api.get('ticker/allPrices').body
|
68
|
+
end
|
69
|
+
|
70
|
+
def all_book_tickers
|
71
|
+
public_api.get('ticker/allBookTickers').body
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
|
2
|
+
module Binance
|
3
|
+
module Client
|
4
|
+
class REST
|
5
|
+
# Sign the query string using HMAC(sha-256) and appends to query string
|
6
|
+
SignRequestMiddleware = Struct.new(:app, :secret_key) do
|
7
|
+
def call(env)
|
8
|
+
value = OpenSSL::HMAC.hexdigest(
|
9
|
+
OpenSSL::Digest.new('sha256'), secret_key, env.url.query
|
10
|
+
)
|
11
|
+
env.url.query = REST.add_query_param(env.url.query, 'signature', value)
|
12
|
+
|
13
|
+
app.call env
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
|
2
|
+
require 'date'
|
3
|
+
|
4
|
+
module Binance
|
5
|
+
module Client
|
6
|
+
class REST
|
7
|
+
# Generate a timestamp in milliseconds and append to query string
|
8
|
+
TimestampRequestMiddleware = Struct.new(:app) do
|
9
|
+
def call(env)
|
10
|
+
env.url.query = REST.add_query_param(
|
11
|
+
env.url.query, 'timestamp', DateTime.now.strftime('%Q')
|
12
|
+
)
|
13
|
+
|
14
|
+
app.call env
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
|
2
|
+
require 'faraday'
|
3
|
+
require 'faraday_middleware'
|
4
|
+
require_relative 'sign_request_middleware'
|
5
|
+
require_relative 'timestamp_request_middleware'
|
6
|
+
|
7
|
+
module Binance
|
8
|
+
module Client
|
9
|
+
class REST
|
10
|
+
# API endpoints with require a timestamp and signature,
|
11
|
+
# as well as requiring url_encoded parameters
|
12
|
+
module Withdraw_API
|
13
|
+
def withdraw_api
|
14
|
+
Faraday.new(url: "#{BASE_URL}/wapi/v3") do |conn|
|
15
|
+
conn.request :url_encoded
|
16
|
+
conn.response :json, content_type: /\bjson$/
|
17
|
+
conn.headers['X-MBX-APIKEY'] = @api_key
|
18
|
+
conn.use TimestampRequestMiddleware
|
19
|
+
conn.use SignRequestMiddleware, @secret_key
|
20
|
+
conn.adapter Faraday.default_adapter
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def withdraw(options)
|
25
|
+
response = withdraw_api.post do |req|
|
26
|
+
req.url 'withdraw.html'
|
27
|
+
req.params.merge! options
|
28
|
+
end
|
29
|
+
response.body
|
30
|
+
end
|
31
|
+
|
32
|
+
def deposit_history(options = {})
|
33
|
+
response = withdraw_api.get do |req|
|
34
|
+
req.url 'depositHistory.html'
|
35
|
+
req.params.merge! options
|
36
|
+
end
|
37
|
+
response.body
|
38
|
+
end
|
39
|
+
|
40
|
+
def withdraw_history(options = {})
|
41
|
+
response = withdraw_api.get do |req|
|
42
|
+
req.url 'withdrawHistory.html'
|
43
|
+
req.params.merge! options
|
44
|
+
end
|
45
|
+
response.body
|
46
|
+
end
|
47
|
+
|
48
|
+
def deposit_address(options)
|
49
|
+
response = withdraw_api.get do |req|
|
50
|
+
req.url 'depositAddress.html'
|
51
|
+
req.params.merge! options
|
52
|
+
end
|
53
|
+
response.body
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
metadata
ADDED
@@ -0,0 +1,124 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: binance
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Charles Ray Shisler III
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-11-27 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.15'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.15'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: faraday
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.12.2
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.12.2
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: faraday_middleware
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 0.12.2
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 0.12.2
|
83
|
+
description:
|
84
|
+
email:
|
85
|
+
- charles@cray.io
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- bin/console
|
91
|
+
- bin/setup
|
92
|
+
- lib/binance.rb
|
93
|
+
- lib/binance/client/rest.rb
|
94
|
+
- lib/binance/client/rest/account_api.rb
|
95
|
+
- lib/binance/client/rest/public_api.rb
|
96
|
+
- lib/binance/client/rest/sign_request_middleware.rb
|
97
|
+
- lib/binance/client/rest/timestamp_request_middleware.rb
|
98
|
+
- lib/binance/client/rest/withdraw_api.rb
|
99
|
+
- lib/binance/version.rb
|
100
|
+
homepage: https://github.com/craysiii/binance
|
101
|
+
licenses:
|
102
|
+
- MIT
|
103
|
+
metadata: {}
|
104
|
+
post_install_message:
|
105
|
+
rdoc_options: []
|
106
|
+
require_paths:
|
107
|
+
- lib
|
108
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
109
|
+
requirements:
|
110
|
+
- - ">="
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: '0'
|
113
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
requirements: []
|
119
|
+
rubyforge_project:
|
120
|
+
rubygems_version: 2.5.2
|
121
|
+
signing_key:
|
122
|
+
specification_version: 4
|
123
|
+
summary: API Wrapper for the Binance cryptocurrency exchange.
|
124
|
+
test_files: []
|