bingx 0.1.0 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3c5f9f5e5d95dfd8b6999867b03fbd057b93da5c56ed6913f72edd86969add04
4
- data.tar.gz: 57b431f53642b71e7286db794a01a24d35e25df15624fcc1569e5a40ffa2a7a1
3
+ metadata.gz: 378b4b73c5b70f16d39d8976ac1d4705d610e1d0ffb6eaa57dc118cedf781b2e
4
+ data.tar.gz: 83083f8b07415306daafbacb1b8c808332b0f6b367908cfd42a391a1974915bd
5
5
  SHA512:
6
- metadata.gz: 66a80adb26d1d7e6bf0367aef9b77417ce87324c3a307e1d1839a0d271749ae4867c49ecaa8ec18da361c895e827f912098dc50cc7c50fae1f31d99b33163f67
7
- data.tar.gz: d481de18a642c57d04d6b21e2ce187818a06cd6ff789f466bfb2d469796904c7900517bc28b197360f4d01ac8eaad88a0f70f3d83fc13ead06f0572e453a84a9
6
+ metadata.gz: 3be52016430bb2b913f5b5875af3cc1d32b8b92846e1da8d9a6e6067a30c798421cdd9e94fabff22c3b170aee2cf783d2c9fe1aab6653754754806f16be03934
7
+ data.tar.gz: cfa2f02647825ae9cebb3b3da396c96a84484cf0e6c4ffb4aee9b8083c92c18acaf9f3d559b682cadd5963aec6b6cbcf44a03a9071d233fdb5f4c22a86c3337d
data/README.md CHANGED
@@ -15,6 +15,16 @@ client = Bingx::Client.new(
15
15
  api_key: '<your API KEY>',
16
16
  secret_key: '<your SECRET KEY>'
17
17
  )
18
+
19
+ client.get_user_balance
20
+
21
+ client.trade_order_test(
22
+ symbol: 'ETH-USDT',
23
+ side: 'BUY',
24
+ positionSide: 'LONG',
25
+ type: 'MARKET',
26
+ quantity: 5
27
+ )
18
28
  ```
19
29
 
20
30
  ## Development
@@ -0,0 +1,64 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bingx
4
+ class Client
5
+ include HTTParty
6
+ include Requests::Account
7
+ include Requests::Trade
8
+
9
+ attr_accessor :api_key, :secret_key, :base_url
10
+
11
+ base_uri 'https://open-api.bingx.com'
12
+ debug_output $stdout
13
+
14
+ def initialize(api_key:, secret_key:)
15
+ @api_key = api_key
16
+ @secret_key = secret_key
17
+ @base_url = 'https://open-api.bingx.com'
18
+ end
19
+
20
+ def request(method, endpoint, payload = {})
21
+ public_send(method, endpoint, payload)
22
+ end
23
+
24
+ def get(endpoint, payload = {})
25
+ headers = { 'X-BX-APIKEY': api_key }
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)
32
+ response.body
33
+ end
34
+
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)}")
40
+
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
51
+ end
52
+ # rubocop:enable Metrics/AbcSize
53
+
54
+ private
55
+
56
+ def signature(payload)
57
+ OpenSSL::HMAC.hexdigest('sha256', secret_key, payload)
58
+ end
59
+
60
+ def parse_params(params)
61
+ params.keys.sort.map { |x| "#{x}=#{params[x]}" }.join('&')
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bingx
4
+ module Requests
5
+ module Account
6
+ def get_user_balance
7
+ request(:get, '/openApi/swap/v2/user/balance')
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bingx
4
+ module Requests
5
+ module Trade
6
+ def trade_order_test(payload)
7
+ request(:post, '/openApi/swap/v2/trade/order/test', payload)
8
+ end
9
+ end
10
+ end
11
+ end
data/lib/bingx/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Bingx
4
- VERSION = '0.1.0'
4
+ VERSION = '0.1.2'
5
5
  end
data/lib/bingx.rb CHANGED
@@ -1,8 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative 'bingx/version'
3
+ require 'httparty'
4
4
 
5
- module Bingx
6
- class Error < StandardError; end
7
- # Your code goes here...
8
- end
5
+ require_relative 'bingx/version'
6
+ require_relative 'bingx/requests/account'
7
+ require_relative 'bingx/requests/trade'
8
+ require_relative 'bingx/client'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bingx
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Georgy Yuriev
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-12-07 00:00:00.000000000 Z
11
+ date: 2023-12-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -37,6 +37,9 @@ files:
37
37
  - README.md
38
38
  - Rakefile
39
39
  - lib/bingx.rb
40
+ - lib/bingx/client.rb
41
+ - lib/bingx/requests/account.rb
42
+ - lib/bingx/requests/trade.rb
40
43
  - lib/bingx/version.rb
41
44
  - sig/bingx.rbs
42
45
  homepage: https://rubygems.org/gems/bingx