rybit 0.1.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +12 -0
- data/README.md +18 -3
- data/lib/rybit/client.rb +38 -6
- data/lib/rybit/requests/account.rb +11 -0
- data/lib/rybit/requests/trade.rb +15 -0
- data/lib/rybit/version.rb +1 -1
- data/lib/rybit.rb +8 -0
- metadata +7 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e58b9f138d48e8e767c7f7291ba42f3d41effaad9fc8ba1640a4495566fa59f4
|
4
|
+
data.tar.gz: fd489d8bb2f31c4cf2c354bb81088ec9db5bd7892443c7f4f552cc68612e1339
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
@@ -12,13 +12,28 @@ gem 'rybit' # in your Gemfile
|
|
12
12
|
|
13
13
|
```ruby
|
14
14
|
client = Rybit::Client.new(
|
15
|
-
|
16
|
-
|
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
|
-
|
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
|
-
|
10
|
-
|
11
|
-
|
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,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
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.
|
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-
|
11
|
+
date: 2023-12-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: httparty
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
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:
|
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
|