bitbns 0.0.1.pre.alpha → 0.0.1.pre.beta
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/bitbns/client.rb +16 -2
- data/lib/bitbns/requests/base.rb +2 -0
- data/lib/bitbns/requests/fetch_markets.rb +1 -0
- data/lib/bitbns/requests/fetch_orderbook.rb +14 -0
- data/lib/bitbns/requests/fetch_tickers.rb +14 -0
- data/lib/bitbns/requests/list_open_limit_orders.rb +21 -0
- data/lib/bitbns/requests/request.rb +6 -2
- data/lib/bitbns/responses/base.rb +4 -0
- data/lib/bitbns/responses/fetch_orderbook.rb +14 -0
- data/lib/bitbns/responses/fetch_tickers.rb +13 -0
- data/lib/bitbns/utils/payload.rb +19 -0
- data/lib/bitbns/utils/signature.rb +13 -0
- data/lib/bitbns/utils/symbols.rb +5 -0
- metadata +25 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4a7945bb13b36f729af8e5b62409e7c5fb80d3efe0ef90920b9d700d38851ca0
|
4
|
+
data.tar.gz: 4fef680b272409df37f137a73862bf2f35a9c4a514ef0a63912f7576a8ced7a5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fa61ba93de2e53b4662cbbf6492096d2c7196b315ce55c42cc5871c228e407da44848ca6c73321daf0d2ffd311bf9ae202447456e840bdf9ba515506f6453c55
|
7
|
+
data.tar.gz: df953480c3cccf35287d9e703ab7fb1b71611f8a958f7edf27784d78dfa6376a84d0513a54b08a164d50ba1ee1a8ec1f60be0692e2184f59774d6dc1af3a34ae
|
data/lib/bitbns/client.rb
CHANGED
@@ -2,6 +2,8 @@
|
|
2
2
|
|
3
3
|
require_relative "./requests/base.rb"
|
4
4
|
require_relative "./responses/base.rb"
|
5
|
+
require_relative "./utils/signature.rb"
|
6
|
+
require_relative "./utils/payload.rb"
|
5
7
|
|
6
8
|
module BitBns
|
7
9
|
class Client
|
@@ -20,16 +22,28 @@ module BitBns
|
|
20
22
|
request_spec.verb,
|
21
23
|
request_spec.url,
|
22
24
|
request_spec.params,
|
23
|
-
request_spec.headers
|
24
25
|
]
|
25
26
|
|
26
27
|
response = Faraday.new.send(*request_txn_modifiers) do |req|
|
27
|
-
req.
|
28
|
+
req.headers = generate_headers(request_spec) if request_spec.attach_headers?
|
29
|
+
req.body = request_spec.body
|
28
30
|
end
|
29
31
|
|
30
32
|
request_spec.response_parser.new(response)
|
31
33
|
end
|
32
34
|
|
35
|
+
private
|
36
|
+
|
37
|
+
def generate_headers(request)
|
38
|
+
payload = BitBns::Utils::Payload.new(request).generate!
|
39
|
+
signature = BitBns::Utils::Signature.new(payload, @api_secret_key).generate!
|
40
|
+
{
|
41
|
+
"X-BITBNS-APIKEY" => @api_key,
|
42
|
+
"X-BITBNS-PAYLOAD" => payload,
|
43
|
+
"X-BITBNS-SIGNATURE" => signature
|
44
|
+
}
|
45
|
+
end
|
46
|
+
|
33
47
|
def parse_request_name(name)
|
34
48
|
"#{REQ_NAMESPACE}::#{name.split("_").map(&:capitalize).join}"
|
35
49
|
end
|
data/lib/bitbns/requests/base.rb
CHANGED
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module BitBns
|
4
|
+
module Requests
|
5
|
+
class FetchMarkets < BitBns::Requests::Request
|
6
|
+
def initialize(opts)
|
7
|
+
@url = "#{PUB_BASE_URL}/order/fetchOrderbook/"
|
8
|
+
@params = { symbol: opts.fetch(:symbol, "BTCUSDT") }
|
9
|
+
@headers = {}
|
10
|
+
@verb = :get
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module BitBns
|
4
|
+
module Requests
|
5
|
+
class FetchTickers < BitBns::Requests::Request
|
6
|
+
def initialize(opts)
|
7
|
+
@url = "#{PUB_BASE_URL}/order/fetchTickers/"
|
8
|
+
@params = {}
|
9
|
+
@headers = {}
|
10
|
+
@verb = :get
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module BitBns
|
4
|
+
module Requests
|
5
|
+
class ListOpenLimitOrders < BitBns::Requests::Request
|
6
|
+
def initialize(opts)
|
7
|
+
@url = "#{API_BASE_URL}/getordersnew"
|
8
|
+
@params = {}
|
9
|
+
@body = { symbol: opts.fetch(:symbol, "BTC_USDT"), side: request_side(opts), page: opts.fetch(:page, 0) }
|
10
|
+
@attach_headers = true
|
11
|
+
@verb = :post
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def request_side(opts)
|
17
|
+
opts[:usdt] ? "usdtListOpenBracketOrders" : "listOpenBracketOrders"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -1,10 +1,14 @@
|
|
1
1
|
module BitBns
|
2
2
|
module Requests
|
3
3
|
class Request
|
4
|
-
attr_accessor :
|
5
|
-
API_BASE_URL = "https://api.bitbns.com/api/trade/
|
4
|
+
attr_accessor :verb, :params, :body, :url
|
5
|
+
API_BASE_URL = "https://api.bitbns.com/api/trade/v2"
|
6
6
|
PUB_BASE_URL = "https://bitbns.com"
|
7
7
|
|
8
|
+
def attach_headers?
|
9
|
+
@attach_headers
|
10
|
+
end
|
11
|
+
|
8
12
|
def response_parser
|
9
13
|
Kernel.const_get("BitBns::Responses::#{self.class.to_s.split("::").last}")
|
10
14
|
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
|
2
|
+
module BitBns
|
3
|
+
module Responses
|
4
|
+
class FetchMarkets < BitBns::Responses::Response
|
5
|
+
attr_reader :body, :headers, :raw
|
6
|
+
|
7
|
+
def initialize(response)
|
8
|
+
@raw = response
|
9
|
+
@body = JSON.parse(response.body)
|
10
|
+
@headers = response.headers
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module BitBns
|
2
|
+
module Responses
|
3
|
+
class FetchTickers < BitBns::Responses::Response
|
4
|
+
attr_reader :body, :headers, :raw
|
5
|
+
|
6
|
+
def initialize(response)
|
7
|
+
@raw = response
|
8
|
+
@body = JSON.parse(response.body)
|
9
|
+
@headers = response.headers
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'base64'
|
2
|
+
|
3
|
+
module BitBns::Utils
|
4
|
+
class Payload
|
5
|
+
def initialize(request)
|
6
|
+
@request = request
|
7
|
+
end
|
8
|
+
|
9
|
+
def generate!
|
10
|
+
Base64.encode64({timeStamp_nonce: generate_timestamp, body: @request.body.to_json}.to_json)
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def generate_timestamp
|
16
|
+
String(Integer(Time.now.to_f.round(3) * 1000))
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'openssl'
|
2
|
+
|
3
|
+
module BitBns::Utils
|
4
|
+
class Signature
|
5
|
+
def initialize(payload, secret)
|
6
|
+
@generated_signature = OpenSSL::HMAC.digest(OpenSSL::Digest.new('sha512'), secret, payload)
|
7
|
+
end
|
8
|
+
|
9
|
+
def generate!
|
10
|
+
@generated_signature
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bitbns
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.1.pre.
|
4
|
+
version: 0.0.1.pre.beta
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sreedev Kodichath
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-01-
|
12
|
-
dependencies:
|
11
|
+
date: 2022-01-05 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: faraday
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.8.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.8.0
|
13
27
|
description: A Ruby Wrapper around BitBns Crypto Trading APIs
|
14
28
|
email: sreedevpadmakumar@gmail.com
|
15
29
|
executables: []
|
@@ -20,10 +34,18 @@ files:
|
|
20
34
|
- lib/bitbns/client.rb
|
21
35
|
- lib/bitbns/requests/base.rb
|
22
36
|
- lib/bitbns/requests/fetch_markets.rb
|
37
|
+
- lib/bitbns/requests/fetch_orderbook.rb
|
38
|
+
- lib/bitbns/requests/fetch_tickers.rb
|
39
|
+
- lib/bitbns/requests/list_open_limit_orders.rb
|
23
40
|
- lib/bitbns/requests/request.rb
|
24
41
|
- lib/bitbns/responses/base.rb
|
25
42
|
- lib/bitbns/responses/fetch_markets.rb
|
43
|
+
- lib/bitbns/responses/fetch_orderbook.rb
|
44
|
+
- lib/bitbns/responses/fetch_tickers.rb
|
26
45
|
- lib/bitbns/responses/response.rb
|
46
|
+
- lib/bitbns/utils/payload.rb
|
47
|
+
- lib/bitbns/utils/signature.rb
|
48
|
+
- lib/bitbns/utils/symbols.rb
|
27
49
|
homepage: https:/bitbns.com
|
28
50
|
licenses:
|
29
51
|
- MIT
|