bingx 0.1.1 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +10 -0
- data/lib/bingx/client.rb +37 -14
- data/lib/bingx/requests/trade.rb +11 -0
- data/lib/bingx/version.rb +1 -1
- data/lib/bingx.rb +1 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3817375dafbdc5f610a643ceacb933807edfe0ab9555d30613e467c1ee92b117
|
4
|
+
data.tar.gz: 973df1d29c56485501e4982a85277af19b140e3c1044666071db28fd25d50241
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dd6d110851049c5833eb0fa8cdb985533bc8701631a4862a8fa9be39eb50151d369459ca27add7b8184358707cf640b4d9f882641984487b523b80b65d6bf900
|
7
|
+
data.tar.gz: b8fa2d2443c3583e3fc7bd6869021f83d71193bd922383a8d50ab561d23cd7859ee881cd30bbc9d1bb536b48c7d2baadb1cc3d6404ca77a7626334bf67da0b47
|
data/README.md
CHANGED
@@ -16,7 +16,17 @@ client = Bingx::Client.new(
|
|
16
16
|
secret_key: '<your SECRET KEY>'
|
17
17
|
)
|
18
18
|
|
19
|
+
client.request(:get, '/openApi/swap/v2/quote/trades', symbol: 'BTC-USDT')
|
20
|
+
|
19
21
|
client.get_user_balance
|
22
|
+
|
23
|
+
client.trade_order_test(
|
24
|
+
symbol: 'ETH-USDT',
|
25
|
+
side: 'BUY',
|
26
|
+
positionSide: 'LONG',
|
27
|
+
type: 'MARKET',
|
28
|
+
quantity: 5
|
29
|
+
)
|
20
30
|
```
|
21
31
|
|
22
32
|
## Development
|
data/lib/bingx/client.rb
CHANGED
@@ -4,38 +4,61 @@ module Bingx
|
|
4
4
|
class Client
|
5
5
|
include HTTParty
|
6
6
|
include Requests::Account
|
7
|
+
include Requests::Trade
|
7
8
|
|
8
|
-
attr_accessor :api_key, :secret_key, :
|
9
|
+
attr_accessor :api_key, :secret_key, :base_url
|
9
10
|
|
10
11
|
base_uri 'https://open-api.bingx.com'
|
11
|
-
debug_output $stdout
|
12
|
+
# debug_output $stdout
|
12
13
|
|
13
|
-
def initialize(api_key:, secret_key
|
14
|
+
def initialize(api_key:, secret_key:)
|
14
15
|
@api_key = api_key
|
15
16
|
@secret_key = secret_key
|
16
|
-
@
|
17
|
+
@base_url = 'https://open-api.bingx.com'
|
17
18
|
end
|
18
19
|
|
19
20
|
def request(method, endpoint, payload = {})
|
21
|
+
public_send(method, endpoint, payload)
|
22
|
+
end
|
23
|
+
|
24
|
+
def get(endpoint, payload = {})
|
20
25
|
headers = { 'X-BX-APIKEY': api_key }
|
21
|
-
|
22
|
-
|
26
|
+
|
27
|
+
payload.merge!(timestamp: DateTime.now.strftime('%Q'))
|
28
|
+
payload = HTTParty::HashConversions.to_params(payload)
|
29
|
+
payload += "&signature=#{signature(payload)}"
|
30
|
+
|
31
|
+
response = self.class.get(endpoint, query: payload, headers: headers)
|
23
32
|
response.body
|
24
33
|
end
|
25
34
|
|
26
|
-
|
35
|
+
# rubocop:disable Metrics/AbcSize
|
36
|
+
def post(endpoint, payload = {})
|
37
|
+
payload.merge!(timestamp: DateTime.now.strftime('%Q'))
|
38
|
+
params = parse_params(payload)
|
39
|
+
full_url = URI("#{base_url}#{endpoint}?#{params}&signature=#{signature(params)}")
|
27
40
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
)
|
33
|
-
|
34
|
-
|
41
|
+
https = Net::HTTP.new(full_url.host, full_url.port)
|
42
|
+
# https.set_debug_output($stdout)
|
43
|
+
https.use_ssl = true
|
44
|
+
|
45
|
+
request = Net::HTTP::Post.new(full_url)
|
46
|
+
request['X-BX-APIKEY'] = api_key
|
47
|
+
request['Content-Type'] = 'application/json'
|
48
|
+
|
49
|
+
response = https.request(request)
|
50
|
+
puts response.read_body
|
35
51
|
end
|
52
|
+
# rubocop:enable Metrics/AbcSize
|
53
|
+
|
54
|
+
private
|
36
55
|
|
37
56
|
def signature(payload)
|
38
57
|
OpenSSL::HMAC.hexdigest('sha256', secret_key, payload)
|
39
58
|
end
|
59
|
+
|
60
|
+
def parse_params(params)
|
61
|
+
params.keys.sort.map { |x| "#{x}=#{params[x]}" }.join('&')
|
62
|
+
end
|
40
63
|
end
|
41
64
|
end
|
data/lib/bingx/version.rb
CHANGED
data/lib/bingx.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bingx
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Georgy Yuriev
|
@@ -39,6 +39,7 @@ files:
|
|
39
39
|
- lib/bingx.rb
|
40
40
|
- lib/bingx/client.rb
|
41
41
|
- lib/bingx/requests/account.rb
|
42
|
+
- lib/bingx/requests/trade.rb
|
42
43
|
- lib/bingx/version.rb
|
43
44
|
- sig/bingx.rbs
|
44
45
|
homepage: https://rubygems.org/gems/bingx
|