Class: Hyperliquid::Cloid
- Inherits:
-
Object
- Object
- Hyperliquid::Cloid
- Defined in:
- lib/hyperliquid/cloid.rb
Overview
Client Order ID: 128-bit hex string prefixed with “0x” (34 chars total).
Instance Attribute Summary collapse
-
#raw ⇒ Object
readonly
Returns the value of attribute raw.
Class Method Summary collapse
-
.from_int(n) ⇒ Object
Create from integer.
-
.from_str(s) ⇒ Object
Create from hex string.
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #hash ⇒ Object
-
#initialize(raw) ⇒ Cloid
constructor
A new instance of Cloid.
- #inspect ⇒ Object
-
#to_raw ⇒ Object
Return the raw hex string for wire format.
- #to_s ⇒ Object
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
#raw ⇒ Object (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 |
#hash ⇒ Object
36 37 38 |
# File 'lib/hyperliquid/cloid.rb', line 36 def hash @raw.hash end |
#inspect ⇒ Object
44 45 46 |
# File 'lib/hyperliquid/cloid.rb', line 44 def inspect "#<Hyperliquid::Cloid #{@raw}>" end |
#to_raw ⇒ Object
Return the raw hex string for wire format.
27 28 29 |
# File 'lib/hyperliquid/cloid.rb', line 27 def to_raw @raw end |
#to_s ⇒ Object
40 41 42 |
# File 'lib/hyperliquid/cloid.rb', line 40 def to_s @raw end |