Class: Hyperliquid::Cloid

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

Overview

Client Order ID: 128-bit hex string prefixed with “0x” (34 chars total).

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw) ⇒ Cloid

Returns a new instance of Cloid.



8
9
10
11
12
13
14
# File 'lib/hyperliquid/cloid.rb', line 8

def initialize(raw)
  unless raw.is_a?(String) && raw.match?(/\A0x[0-9a-f]{32}\z/)
    raise ArgumentError, "Cloid must be 0x + 32 hex chars, got: #{raw.inspect}"
  end

  @raw = raw
end

Instance Attribute Details

#rawObject (readonly)

Returns the value of attribute raw.



6
7
8
# File 'lib/hyperliquid/cloid.rb', line 6

def raw
  @raw
end

Class Method Details

.from_int(n) ⇒ Object

Create from integer.



17
18
19
# File 'lib/hyperliquid/cloid.rb', line 17

def self.from_int(n)
  new(format("0x%032x", n))
end

.from_str(s) ⇒ Object

Create from hex string.



22
23
24
# File 'lib/hyperliquid/cloid.rb', line 22

def self.from_str(s)
  new(s.downcase)
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



31
32
33
# File 'lib/hyperliquid/cloid.rb', line 31

def ==(other)
  other.is_a?(Cloid) && @raw == other.raw
end

#hashObject



36
37
38
# File 'lib/hyperliquid/cloid.rb', line 36

def hash
  @raw.hash
end

#inspectObject



44
45
46
# File 'lib/hyperliquid/cloid.rb', line 44

def inspect
  "#<Hyperliquid::Cloid #{@raw}>"
end

#to_rawObject

Return the raw hex string for wire format.



27
28
29
# File 'lib/hyperliquid/cloid.rb', line 27

def to_raw
  @raw
end

#to_sObject



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

def to_s
  @raw
end