rybit 0.1.2 → 0.2.1

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: a466b6a116e153db499f7755b86ccab85e332eb733543a8322e9b29ae6ab3e7a
4
- data.tar.gz: d8736683b11f35ad9f75e398ae86a5e86f978b5bcb5cdfe2f956820fc0d75db0
3
+ metadata.gz: cc4083d79b517c8ed92e4809351eeb8a0965b315c669fc454cab1f1693096ae3
4
+ data.tar.gz: db0430828dca5d58b3087a4193504b8d471b83549e73df1a40eea7dce75447b2
5
5
  SHA512:
6
- metadata.gz: 99ec0473683f089ea92434def111ad54788db11ff4af8ff751428341e43d20d68b1735bc492615c6b3541ee7fb90b07de6de3e350db3c7bd21917e1079018a21
7
- data.tar.gz: 14c57e0c679dddf4e7896b9fe6ba88409a4705e5d7dd5df9bb06e0aca30ae62781df8600563c3dc3f4941d77f6e443551fb665baffa6812b3228c2474ca39143
6
+ metadata.gz: 87b03ef42627e893f300e2c0695620a334a74c149cac2915a912c9fcad4e9f3b444cc4fac1017af5b3ef94f8e5c0d335f7cbe90b5bb3ebf6984e421fcac69946
7
+ data.tar.gz: ccf4d654a8e3a0cf4ca6865585467a9fc3faa8808d7f581ded6e67d4e7e46239ed0d836b09af14ff64453f3e3d9353324f07f4e55fe79de7f0076c1199871f12
data/.rubocop.yml CHANGED
@@ -12,3 +12,15 @@ Layout/LineLength:
12
12
 
13
13
  Style/Documentation:
14
14
  Enabled: false
15
+
16
+ Metrics/MethodLength:
17
+ Max: 15
18
+ Exclude:
19
+ - 'lib/rybit/client.rb'
20
+
21
+ Metrics/AbcSize:
22
+ Exclude:
23
+ - 'lib/rybit/client.rb'
24
+
25
+ Naming/AccessorMethodName:
26
+ Enabled: false
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Rybit
2
2
 
3
- Bybit API client
3
+ Bybit Ruby API client
4
4
 
5
5
  ## Installation
6
6
 
@@ -12,13 +12,28 @@ gem 'rybit' # in your Gemfile
12
12
 
13
13
  ```ruby
14
14
  client = Rybit::Client.new(
15
- key: '<your API KEY>',
16
- secret: '<your SECRET KEY>'
15
+ api_key: '<your API KEY>',
16
+ secret_key: '<your SECRET KEY>',
17
+ # testnet: <boolean> (default false)
17
18
  )
18
19
 
19
- client.get_wallet_balance
20
+ client.get_wallet_balance(accountType: 'CONTRACT')
21
+
22
+ client.create_order(
23
+ category: 'linear',
24
+ symbol: 'BTCUSDT',
25
+ side: 'Buy',
26
+ positionIdx: 0,
27
+ orderType: 'Limit',
28
+ qty: '0.001',
29
+ price: '10000',
30
+ timeInForce: 'GTC',
31
+ orderLinkId: SecureRandom.uuid
32
+ )
20
33
  ```
21
34
 
35
+ NOTE: **tesnet** credentials are created separately on https://testnet.bybit.com/app/user/api-management
36
+
22
37
  ## Development
23
38
 
24
39
  * `bin/setup` to install dependencies
data/lib/rybit/client.rb CHANGED
@@ -1,13 +1,45 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'dry-initializer'
4
-
5
3
  module Rybit
6
4
  class Client
7
- extend Dry::Initializer
5
+ include HTTParty
6
+ include Requests::Account
7
+ include Requests::Trade
8
+
9
+ attr_accessor :api_key, :secret_key, :testnet, :base_url, :recv_window
10
+
11
+ # debug_output $stdout
12
+
13
+ def initialize(api_key:, secret_key:, testnet: false, recv_window: '5000')
14
+ @api_key = api_key
15
+ @secret_key = secret_key
16
+ @testnet = testnet
17
+ @recv_window = recv_window
18
+ @base_url = "https://#{testnet ? 'api-testnet' : 'api'}.bybit.com"
19
+ end
20
+
21
+ def request(method, endpoint, payload = {})
22
+ full_url = base_url + endpoint
23
+ timestamp = DateTime.now.strftime('%Q')
24
+ payload = method == :post ? payload.to_json : HTTParty::HashConversions.to_params(payload)
25
+ headers = {
26
+ 'X-BAPI-API-KEY' => api_key,
27
+ 'X-BAPI-TIMESTAMP' => timestamp,
28
+ 'X-BAPI-RECV-WINDOW' => recv_window,
29
+ 'X-BAPI-SIGN' => signature(payload, timestamp),
30
+ 'Content-Type' => ('application/json' if method == :post)
31
+ }.compact
32
+
33
+ wrapper = method == :post ? :body : :query
34
+ response = self.class.send(method, full_url, wrapper => payload, headers: headers)
35
+ response.body
36
+ end
37
+
38
+ private
8
39
 
9
- option :endpoint, default: -> { 'https://api.bybit.com' }
10
- option :key
11
- option :secret
40
+ def signature(payload, timestamp)
41
+ param_str = timestamp + api_key + recv_window + payload
42
+ OpenSSL::HMAC.hexdigest('sha256', secret_key, param_str)
43
+ end
12
44
  end
13
45
  end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rybit
4
+ module Requests
5
+ module Account
6
+ def get_wallet_balance(payload)
7
+ request(:get, '/v5/account/wallet-balance', payload)
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rybit
4
+ module Requests
5
+ module Trade
6
+ def create_order(options)
7
+ request(:post, '/v5/order/create', options)
8
+ end
9
+
10
+ def get_open_orders(options)
11
+ request(:get, '/v5/order/realtime', options) # category: 'spot'
12
+ end
13
+ end
14
+ end
15
+ end
data/lib/rybit/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Rybit
4
- VERSION = '0.1.2'
4
+ VERSION = '0.2.1'
5
5
  end
data/lib/rybit.rb CHANGED
@@ -1,4 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'date'
4
+ require 'openssl'
5
+ require 'securerandom'
6
+
7
+ require 'httparty'
8
+
3
9
  require_relative 'rybit/version'
10
+ require_relative 'rybit/requests/account'
11
+ require_relative 'rybit/requests/trade'
4
12
  require_relative 'rybit/client'
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rybit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.1
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-06 00:00:00.000000000 Z
11
+ date: 2023-12-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: dry-initializer
14
+ name: httparty
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 3.1.1
19
+ version: 0.21.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 3.1.1
26
+ version: 0.21.0
27
27
  description: Bybit API connector
28
28
  email:
29
29
  - georgy.yuriev@gmail.com
@@ -37,6 +37,8 @@ files:
37
37
  - Rakefile
38
38
  - lib/rybit.rb
39
39
  - lib/rybit/client.rb
40
+ - lib/rybit/requests/account.rb
41
+ - lib/rybit/requests/trade.rb
40
42
  - lib/rybit/version.rb
41
43
  - sig/rybit.rbs
42
44
  homepage: https://rubygems.org/gems/rybit