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)



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/hyperliquid.rb', line 47

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
  explorer_base_url = testnet ? Constants::TESTNET_RPC_URL : Constants::MAINNET_RPC_URL
  client = Client.new(
    base_url: base_url,
    timeout: timeout,
    retry_enabled: retry_enabled,
    explorer_base_url: explorer_base_url
  )

  @info = Info.new(client)
  @testnet = testnet
  @exchange = nil
  explorer_ws_url = testnet ? Constants::TESTNET_EXPLORER_WS_URL : Constants::MAINNET_EXPLORER_WS_URL
  @ws = WS::Client.new(testnet: testnet, explorer_ws_url: explorer_ws_url)

  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.



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

def exchange
  @exchange
end

#infoObject (readonly)

Returns the value of attribute info.



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

def info
  @info
end

#wsObject (readonly)

Returns the value of attribute ws.



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

def ws
  @ws
end

Instance Method Details

#base_urlString

Get the base API URL being used

Returns:

  • (String)

    The base API URL



84
85
86
# File 'lib/hyperliquid.rb', line 84

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



78
79
80
# File 'lib/hyperliquid.rb', line 78

def testnet?
  @testnet
end