Skip to main content

Module runtime

Module runtime 

Source

Re-exports§

pub use crate::precise::Precise;
pub use crate::exchange_errors::*;

Modules§

Math

Constants§

DECIMAL_PLACES
NO_PADDING
PAD_WITH_ZERO
ROUND
ROUND_DOWN
ROUND_UP
SIGNIFICANT_DIGITS
TICK_SIZE
TRUNCATE

Traits§

IsTruthy
is_true(x) — polymorphic truthy check. The transpiler emits is_true(&X) where X may be a Value, a bool, or the result of any other predicate (is_equal, in_op, …). This trait lets all of them work without manual conversion at the call site.

Functions§

add
add_element_to_object
append_to_array
append_to_object_array
obj[key].push(v) — append to an array field of a dict in place. The transpiled dict['bids'].push(x) otherwise lowers to append_to_array(&mut get_value(&dict, &key), x), whose get_value yields a COW clone, so the push is lost (paradex’s order-book inserts). Mutate the field through the dict instead.
call_typed
catch_typed
Bridge an async exchange call’s panic-based error convention onto Rust’s Result. The transpiled bodies use panic!("[Kind] message") (mirroring the TS throw new <Kind>(message) pattern); the typed-wrapper layer wraps every delegate call in this helper so its public surface is idiomatic Rust (Result<T, ExchangeError>) rather than panicking. Synchronous sibling of call_typed: runs a closure that may signal an error the transpiled way (panic!("[Kind] message")) and converts that into a typed Result. Used by the typed wrappers’ non-async accessors.
coerce_value_to_mut⚠
Forge a &mut Value from a &Value. Used by the transpiler to emit nested-key writes (this.options['k1'][k2] = v in TS) inside &self parser methods like bitstamp.parseCurrency that accumulate state into self.options. The naive &mut self.options.clone() mutably borrows a temporary — the write never reaches self.options, silently breaking the parser.
concat_arrays
contains
contains(haystack, needle) — substring check for Value::Str, element check for Value::Array. Used by the transpiled tests for string.includes(...) / array.includes(...) (the regex transpiler rewrites both into this free function).
crc32
crc32(string, signed) — IEEE CRC-32. With signed = true the u32 is reinterpreted as a signed 32-bit integer.
date_now
Date.now() — current Unix time in milliseconds.
decode_mexc_push_data
Decode mexc’s PushDataV3ApiWrapper protobuf frame into the same shape protobufjs’ .toJSON() produces, so the ported handlers read it unchanged. Wires the public order-book (depth), book-ticker, deals and kline bodies.
deep_merge_dict
Recursively deep-extend base with over (CCXT deepExtend semantics): nested dicts are merged key-by-key rather than wholesale-replaced, and over’s leaves win on conflict. Used by generated init() to merge a pro Core’s describe().options over the parent REST Core’s — e.g. mexc’s options.timeframes is a flat {1m: Min1} in the pro block but a nested {spot, swap} in REST; a shallow merge dropped one, breaking watchOHLCV’s interval lookup. Deep-merge yields the union both forms rely on.
divide
ecdsa
ecdsa(message, secret, curve, preHash) — secp256k1 ECDSA signature with public-key recovery. Returns {r, s, v} (hex r/s, integer recovery id). message is a hex digest (already hashed) unless preHash names a hash algorithm to apply first.
eddsa
eddsa(request, secret, curve) — Ed25519 signature, mirroring ts/src/base/functions/crypto.ts. request is the message (already-bytes Value::Arr as produced by encode(...), or a hex/utf8 string); secret is either a 32-byte raw seed string or a base64/PEM PKCS#8 key (seed at DER offset 16). Returns the standard-base64 signature. Fails loudly (NotSupported panic) rather than returning an empty/invalid signature.
encode
encode(s) — UTF-8 bytes of a string as a byte-array Value.
ends_with
ends_with(haystack, suffix) — true if Value haystack ends with suffix.
get_arg
get_arg(args, index, default) — used by transpiled methods that accept params = [] variadic optional arguments.
get_array_length
get_value
get_value_mut
hash
Free-function hash(data, algo, digest) — used by transpiled crypto code that imports hash from base/functions/crypto.js.
hmac
Free-function hmac(data, secret, algo, digest).
in_op
is_array
is_bool
is_equal
is_function
is_greater_than
is_greater_than_or_equal
is_instance
Mirrors TS e instanceof <ClassName>: panic payloads in the transpiled tests are Value::Str(format!("[{kind}] {message}")) (see ExchangeError’s Display impl), so the class name is whatever sits between the first pair of square brackets. Matches the expected-error-class names that broker-id and static-request tests pass as Value::Str("InvalidProxySettings").
is_less_than
is_less_than_or_equal
is_number
is_object
is_true
join
join(array, separator) — joins array elements into a string.
json_parse
json_stringify
jwt
jwt(request, secret, algorithm, isRsa, opts) — JSON Web Token. HS256 (HMAC) or RS256 (RSA), signing header.payload.
math_ceil
math_floor
math_round
mod_val
multiply
negate
object_keys
object_values
pad_end
pad_start
pad_start(s, len, pad) / pad_end — left/right pad strings.
panic_msg_to_error
Parse a transpiled error payload ("[Kind] message") into a typed ExchangeError. Falls back to the generic ExchangeError kind when the payload doesn’t carry a leading [Kind] marker.
panic_to_value
Convert a catch_unwind panic payload into the Value::Str shape that transpiled catch (e) blocks expect. The transpiled code uses this from the catch arm emitted by rewriteTryCatchAsync — kept in the ccxt crate (rather than the test crate) so exchange files that catch downstream panics (e.g. pacifica try { approveBuilderCode } catch { disable_builder_fee }) can use it without a test-crate dep.
parse_float
parse_float(value) — best-effort to float.
parse_int
parse_int(value) — best-effort to integer.
println_val
promise_all
Async equivalent of Promise.all — awaits all futures and collects results. Currently a stub: takes a Value::Array and returns it unchanged.
quote_json_numbers
Wraps every JSON object number VALUE in quotes, replicating CCXT’s onJsonResponse transform responseBody.replace(/":([+.0-9eE-]+)([,}])/g, '":"$1"$2') used when quoteJsonNumbers is on (the default). This preserves big integer ids and high-precision decimals as strings through parsing, matching how the unified parsers (safeString/safeNumber/Precise) expect to read them. Only object values (a number right after ": and right before , or }) are quoted — array elements are left alone, mirroring the upstream regex. Byte-oriented so multi-byte UTF-8 in the surrounding text is preserved.
remove
repeat
repeat(s, n) — repeat string n times.
replace_all_str
replace_all_str(s, old, new) — replace every occurrence (TS String.replaceAll).
replace_str
replace_str(s, old, new) — string replacement, alias for string_replace.
rsa
rsa(message, key, hash) — RSA PKCS#1 v1.5 signature (SHA-256), returned base64-encoded. key is a PKCS#1 PEM private key.
shift
Array.prototype.shift() — removes and returns the first element. Called as a free function from transpiled WS code (shift(stored)). Returns Value::Null if the array is empty or the target isn’t an array.
split
split(s, delim) — string split returning Value::Array of Value::Str.
starts_with
starts_with(haystack, prefix) — true if Value haystack starts with prefix.
string_replace
string_replace(s, old, new) — string replacement.
stringify_param
subtract
to_fixed
to_fixed(x, digits) — JS Number.prototype.toFixed: format a number with a fixed number of decimal places, returned as a string.
to_string_val
Generic .toString() for Value.
totp
totp(secret) — RFC 6238 time-based one-time password (HMAC-SHA1, 30s step, 6 digits), mirroring ts/src/base/functions/totp.ts. The secret is a base32 string (spaces allowed, as in “4TDV WOGO”). Returns Value::Null for a non-string secret.
trim
trim(s) — string trim.