rybit 0.1.0 → 0.2.0

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: 0fc85e85a619ae945a47cb7114f12250a91a9c1824e14c3dcee4706e308ada53
4
- data.tar.gz: 94f3eba79d350c0739d1995e1f573742a8445467f6f5eca4e798089d78ba91f6
3
+ metadata.gz: e58b9f138d48e8e767c7f7291ba42f3d41effaad9fc8ba1640a4495566fa59f4
4
+ data.tar.gz: fd489d8bb2f31c4cf2c354bb81088ec9db5bd7892443c7f4f552cc68612e1339
5
5
  SHA512:
6
- metadata.gz: 68691792f90a58b045d2a0efff437fa73b41b9af9496a62df4883b9f4dfff0eeba4f06cb6676ec839d2cabcc40c983a0a6ad2c5c3f50bf297d95673d77b7ca8a
7
- data.tar.gz: c51e5487f518d1c2c71bf9cc904771f1ecac2d1a4184ab8259e209a51981a55baf35452212aa0897a7fefb8cbb50dc91b88bbb03d243a0ffa3d6fb7c0b0419be
6
+ metadata.gz: 809a6e76ec645996c3858a1f543e88351e7e14ea863b47ba7fe594f2302fba729a233ee643c9f2cae04f15f2f44ecc3e72258ae279210988df73b239d9a3bb40
7
+ data.tar.gz: a686640c5886b00aaef736fda878e7933d118b2d32d82920e663ce97ed3e69c4d534da021eb39a5984bade847ee5ecffa9f8dba3b5111125e90d6665195f2aa8
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
@@ -4,23 +4,48 @@ Bybit API client
4
4
 
5
5
  ## Installation
6
6
 
7
- Install the gem and add to the application's Gemfile by executing:
8
-
9
- $ bundle add UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
10
-
11
- If bundler is not being used to manage dependencies, install the gem by executing:
12
-
13
- $ gem install UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
7
+ ```ruby
8
+ gem 'rybit' # in your Gemfile
9
+ ```
14
10
 
15
11
  ## Usage
16
12
 
17
- TODO: Write usage instructions here
13
+ ```ruby
14
+ client = Rybit::Client.new(
15
+ api_key: '<your API KEY>',
16
+ secret_key: '<your SECRET KEY>',
17
+ # testnet: <boolean> (default false)
18
+ )
19
+
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
+ )
33
+ ```
34
+
35
+ NOTE: tesnet credentials are created separately on https://testnet.bybit.com/app/user/api-management
18
36
 
19
37
  ## Development
20
38
 
21
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
39
+ * `bin/setup` to install dependencies
40
+ * `rake spec` to run the tests
41
+ * `bin/console` for an interactive prompt
42
+ ---
43
+ * `bundle exec rake install` to install this gem onto your local machine
44
+
45
+ ## Release
22
46
 
23
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
47
+ 1. Update the version number in `version.rb`
48
+ 2. Run `bundle exec rake release`
24
49
 
25
50
  ## Contributing
26
51
 
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rybit
4
+ class Client
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
39
+
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
44
+ end
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.0'
4
+ VERSION = '0.2.0'
5
5
  end
data/lib/rybit.rb CHANGED
@@ -1,11 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative 'rybit/version'
3
+ require 'date'
4
+ require 'openssl'
5
+ require 'securerandom'
4
6
 
5
- module Rybit
6
- class Error < StandardError; end
7
+ require 'httparty'
7
8
 
8
- def self.hi
9
- 'hello world'
10
- end
11
- end
9
+ require_relative 'rybit/version'
10
+ require_relative 'rybit/requests/account'
11
+ require_relative 'rybit/requests/trade'
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.0
4
+ version: 0.2.0
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
@@ -36,10 +36,14 @@ files:
36
36
  - README.md
37
37
  - Rakefile
38
38
  - lib/rybit.rb
39
+ - lib/rybit/client.rb
40
+ - lib/rybit/requests/account.rb
41
+ - lib/rybit/requests/trade.rb
39
42
  - lib/rybit/version.rb
40
43
  - sig/rybit.rbs
41
44
  homepage: https://rubygems.org/gems/rybit
42
- licenses: []
45
+ licenses:
46
+ - MIT
43
47
  metadata:
44
48
  homepage_uri: https://rubygems.org/gems/rybit
45
49
  source_code_uri: https://github.com/light-flight/rybit