Class: Hyperliquid::SDK

Inherits:
Object
  • Object
show all
Defined in:
lib/hyperliquid.rb

Overview

Main SDK class

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(testnet: false, timeout: Constants::DEFAULT_TIMEOUT, retry_enabled: false, private_key: nil, expires_after: nil) ⇒ SDK

Initialize the SDK

Parameters:

  • testnet (Boolean) (defaults to: false)

    Whether to use testnet (default: false for mainnet)

  • timeout (Integer) (defaults to: Constants::DEFAULT_TIMEOUT)

    Request timeout in seconds

  • retry_enabled (Boolean) (defaults to: false)

    Whether to enable retry logic (default: false)

  • private_key (String, nil) (defaults to: nil)

    Ethereum private key for exchange operations (optional)

  • expires_after (Integer, nil) (defaults to: nil)

    Global order expiration timestamp in ms (optional)



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/hyperliquid.rb', line 46

def initialize(testnet: false, timeout: Constants::DEFAULT_TIMEOUT, retry_enabled: false,
               private_key: nil, expires_after: nil)
  base_url = testnet ? Constants::TESTNET_API_URL : Constants::MAINNET_API_URL
  client = Client.new(base_url: base_url, timeout: timeout, retry_enabled: retry_enabled)

  @info = Info.new(client)
  @testnet = testnet
  @exchange = nil
  @ws = WS::Client.new(testnet: testnet)

  return unless private_key

  signer = Signing::Signer.new(private_key: private_key, testnet: testnet)
  @exchange = Exchange.new(
    client: client,
    signer: signer,
    info: @info,
    testnet: testnet,
    expires_after: expires_after
  )
end

Instance Attribute Details

#exchangeObject (readonly)

Returns the value of attribute exchange.



38
39
40
# File 'lib/hyperliquid.rb', line 38

def exchange
  @exchange
end

#infoObject (readonly)

Returns the value of attribute info.



38
39
40
# File 'lib/hyperliquid.rb', line 38

def info
  @info
end

#wsObject (readonly)

Returns the value of attribute ws.



38
39
40
# File 'lib/hyperliquid.rb', line 38

def ws
  @ws
end

Instance Method Details

#base_urlString

Get the base API URL being used

Returns:

  • (String)

    The base API URL



76
77
78
# File 'lib/hyperliquid.rb', line 76

def base_url
  @testnet ? Constants::TESTNET_API_URL : Constants::MAINNET_API_URL
end

#testnet?Boolean

Check if using testnet

Returns:

  • (Boolean)

    True if using testnet, false if mainnet



70
71
72
# File 'lib/hyperliquid.rb', line 70

def testnet?
  @testnet
end