Class: Rybit::Client
- Inherits:
-
Object
- Object
- Rybit::Client
- Includes:
- HTTParty, Requests::Account, Requests::Trade
- Defined in:
- lib/rybit/client.rb
Instance Attribute Summary collapse
-
#api_key ⇒ Object
Returns the value of attribute api_key.
-
#base_url ⇒ Object
Returns the value of attribute base_url.
-
#recv_window ⇒ Object
Returns the value of attribute recv_window.
-
#secret_key ⇒ Object
Returns the value of attribute secret_key.
-
#testnet ⇒ Object
Returns the value of attribute testnet.
Instance Method Summary collapse
-
#initialize(api_key:, secret_key:, testnet: false, recv_window: '5000') ⇒ Client
constructor
debug_output $stdout.
- #request(method, endpoint, payload = {}) ⇒ Object
Methods included from Requests::Trade
#create_order, #get_open_orders
Methods included from Requests::Account
Constructor Details
#initialize(api_key:, secret_key:, testnet: false, recv_window: '5000') ⇒ Client
debug_output $stdout
13 14 15 16 17 18 19 |
# File 'lib/rybit/client.rb', line 13 def initialize(api_key:, secret_key:, testnet: false, recv_window: '5000') @api_key = api_key @secret_key = secret_key @testnet = testnet @recv_window = recv_window @base_url = "https://#{testnet ? 'api-testnet' : 'api'}.bybit.com" end |
Instance Attribute Details
#api_key ⇒ Object
Returns the value of attribute api_key.
9 10 11 |
# File 'lib/rybit/client.rb', line 9 def api_key @api_key end |
#base_url ⇒ Object
Returns the value of attribute base_url.
9 10 11 |
# File 'lib/rybit/client.rb', line 9 def base_url @base_url end |
#recv_window ⇒ Object
Returns the value of attribute recv_window.
9 10 11 |
# File 'lib/rybit/client.rb', line 9 def recv_window @recv_window end |
#secret_key ⇒ Object
Returns the value of attribute secret_key.
9 10 11 |
# File 'lib/rybit/client.rb', line 9 def secret_key @secret_key end |
#testnet ⇒ Object
Returns the value of attribute testnet.
9 10 11 |
# File 'lib/rybit/client.rb', line 9 def testnet @testnet end |
Instance Method Details
#request(method, endpoint, payload = {}) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/rybit/client.rb', line 21 def request(method, endpoint, payload = {}) full_url = base_url + endpoint = DateTime.now.strftime('%Q') payload = method == :post ? payload.to_json : HTTParty::HashConversions.to_params(payload) headers = { 'X-BAPI-API-KEY' => api_key, 'X-BAPI-TIMESTAMP' => , 'X-BAPI-RECV-WINDOW' => recv_window, 'X-BAPI-SIGN' => signature(payload, ), 'Content-Type' => ('application/json' if method == :post) }.compact wrapper = method == :post ? :body : :query response = self.class.send(method, full_url, wrapper => payload, headers: headers) response.body end |