// PLEASE DO NOT EDIT THIS FILE, IT IS GENERATED AND WILL BE OVERWRITTEN:
// https://github.com/ccxt/ccxt/blob/master/CONTRIBUTING.md#how-to-contribute-code
// Generated from `ts/src/base/PredictionExchange.ts` — methods below the
// "METHODS BELOW THIS LINE ARE TRANSPILED" marker. Everything
// above the marker is hand-written (src/exchange.rs / src/prediction_exchange.rs).
#![allow(unused, non_snake_case, clippy::all)]
use crate::Value;
use crate::ExchangeError;
use crate::exchange::Exchange;
use crate::exchange::ExchangeRuntime;
use crate::exchange_generated::ExchangeBase;
use crate::prediction_exchange::PredictionRuntime;
use crate::prediction_exchange::PredictionExchange;
use crate::runtime::*;
pub trait PredictionBase: crate::exchange_generated::ExchangeBase {
/// Borrow the PredictionExchange holding the prediction-tier fields.
fn pred(&self) -> &crate::prediction_exchange::PredictionExchange;
fn pred_mut(&mut self) -> &mut crate::prediction_exchange::PredictionExchange;
fn describe(&self) -> Value {
return self.deep_extend(self.super_describe(), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("has".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("prediction".to_string(), Value::Bool(true));
m.insert("approve".to_string(), Value::Bool(false));
m.insert("redeem".to_string(), Value::Bool(false));
m.insert("fetchEvent".to_string(), Value::Bool(false));
m.insert("fetchEvents".to_string(), Value::Bool(false));
m.insert("fetchOutcome".to_string(), Value::Bool(false));
m.insert("fetchSettlements".to_string(), Value::Bool(false));
m.insert("createOrder".to_string(), Value::Bool(false));
m.insert("createOrders".to_string(), Value::Bool(false));
m.insert("createLimitOrder".to_string(), Value::Bool(false));
m.insert("createMarketOrder".to_string(), Value::Bool(false));
m.insert("createMarketOrderWs".to_string(), Value::Bool(false));
m.insert("createMarketBuyOrderWithCost".to_string(), Value::Bool(false));
m.insert("cancelOrder".to_string(), Value::Bool(false));
m.insert("cancelOrders".to_string(), Value::Bool(false));
m.insert("cancelAllOrders".to_string(), Value::Bool(false));
m.insert("editOrder".to_string(), Value::Bool(false));
m.insert("fetchBalance".to_string(), Value::Bool(false));
m.insert("fetchOrder".to_string(), Value::Bool(false));
m.insert("fetchOrders".to_string(), Value::Bool(false));
m.insert("fetchOrdersByIds".to_string(), Value::Bool(false));
m.insert("fetchOrderTrades".to_string(), Value::Bool(false));
m.insert("fetchOpenOrders".to_string(), Value::Bool(false));
m.insert("fetchClosedOrders".to_string(), Value::Bool(false));
m.insert("fetchCanceledOrders".to_string(), Value::Bool(false));
m.insert("fetchMyTrades".to_string(), Value::Bool(false));
m.insert("fetchPosition".to_string(), Value::Bool(false));
m.insert("fetchPositions".to_string(), Value::Bool(false));
m.insert("fetchAccounts".to_string(), Value::Bool(false));
m.insert("fetchLedger".to_string(), Value::Bool(false));
m.insert("fetchDeposits".to_string(), Value::Bool(false));
m.insert("fetchWithdrawals".to_string(), Value::Bool(false));
m.insert("fetchMarkets".to_string(), Value::Bool(false));
m.insert("fetchCurrencies".to_string(), Value::Bool(false));
m.insert("fetchTicker".to_string(), Value::Bool(false));
m.insert("fetchTickers".to_string(), Value::Bool(false));
m.insert("fetchOrderBook".to_string(), Value::Bool(false));
m.insert("fetchL2OrderBook".to_string(), Value::Bool(false));
m.insert("fetchOHLCV".to_string(), Value::Bool(false));
m.insert("fetchTrades".to_string(), Value::Bool(false));
m.insert("fetchStatus".to_string(), Value::Bool(false));
m.insert("fetchTime".to_string(), Value::Bool(false));
m.insert("fetchOpenInterest".to_string(), Value::Bool(false));
m.insert("fetchTradingFee".to_string(), Value::Bool(false));
m.insert("watchTicker".to_string(), Value::Bool(false));
m.insert("watchTickers".to_string(), Value::Bool(false));
m.insert("watchOrderBook".to_string(), Value::Bool(false));
m.insert("watchTrades".to_string(), Value::Bool(false));
m.insert("watchOrders".to_string(), Value::Bool(false));
m.insert("watchMyTrades".to_string(), Value::Bool(false));
m.insert("watchOHLCV".to_string(), Value::Bool(false));
m.insert("watchPositions".to_string(), Value::Bool(false));
m
}));
m
})]);
Value::Null
}
fn is_prediction(&self) -> Value {
return self.safe_bool_k(self.has.clone(), "prediction", &[Value::Bool(false)]);
Value::Null
}
fn parse_search_queries(&self, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
// accepts either `query` (a single search string) or `queries` (a list of strings)
let mut singleQuery: Value = self.safe_string_k(params.clone(), "query", &[]);
if !is_equal(&singleQuery, &Value::Null) {
return Value::List(vec![singleQuery.clone()]);
}
return self.safe_list_k(params.clone(), "queries", &[Value::List(vec![])]);
Value::Null
}
fn require_event_query(&self, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
// fetchEvents must be scoped by at least one selector — an unfiltered call would page the
// entire exchange. require one of query / queries / tags / eventId / slug, or one of the
// venue-specific scope params an exchange declares in options['eventScopeParams'],
// e.g. kalshi's category / series_ticker
let mut query: Value = self.safe_string_k(params.clone(), "query", &[]);
let mut queries: Value = self.safe_list_k(params.clone(), "queries", &[Value::List(vec![])]);
let mut tags: Value = self.safe_list_k(params.clone(), "tags", &[Value::List(vec![])]);
let mut eventId: Value = self.safe_string_k(params.clone(), "eventId", &[]);
let mut slug: Value = self.safe_string_k(params.clone(), "slug", &[]);
let mut queriesLength: Value = get_array_length(&queries);
let mut tagsLength: Value = get_array_length(&tags);
if is_true(&(!is_equal(&query, &Value::Null))) || is_true(&(is_greater_than(&queriesLength, &Value::Int(0)))) || is_true(&(is_greater_than(&tagsLength, &Value::Int(0)))) || is_true(&(!is_equal(&eventId, &Value::Null))) || is_true(&(!is_equal(&slug, &Value::Null))) {
return Value::Null;
}
let mut extraScopeParams: Value = self.safe_list_k(self.options.clone(), "eventScopeParams", &[Value::List(vec![])]);
let mut extraScopeParamsLength: Value = get_array_length(&extraScopeParams);
let mut extraNames: Value = Value::Str("".to_string());
{
let mut i: Value = Value::Int(0);
let mut __for_first_180: bool = true;
while { if !__for_first_180 { i = add(&i, &Value::Int(1)); } __for_first_180 = false; is_less_than(&i, &extraScopeParamsLength) } {
let mut scopeKey: Value = get_value(&extraScopeParams, &i);
let mut scopeKey: Value = get_value(&extraScopeParams, &i);
if is_true(&Value::Bool(in_op(¶ms, &scopeKey))) {
return Value::Null;
}
extraNames = add(&add(&extraNames, &Value::Str(", ".to_string())), &scopeKey);
}
}
panic!("{}", crate::exchange_errors::arguments_required(add(&add(&add(&self.id, &Value::Str(" fetchEvents() requires at least one of query, queries, tags, eventId, slug".to_string())), &extraNames), &Value::Str(" to scope the search".to_string()))));
Value::Null
}
fn apply_event_fetch_params(&mut self, mut events: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut queries = get_arg(optional_args, 1, Value::Null);
// applies the unified fetchEvents options client-side (eventId/slug/status/searchIn/sort/limit)
// so exchanges whose API can't filter natively still support them consistently.
// every fetched event lands in the cache before filtering, so loadEvents()/event()
// serve them later without another request
self.set_events(events.clone());
let mut result: Value = events.clone();
let mut eventId: Value = self.safe_string_k(params.clone(), "eventId", &[]);
let mut slug: Value = self.safe_string_k(params.clone(), "slug", &[]);
if is_true(&(!is_equal(&eventId, &Value::Null))) || is_true(&(!is_equal(&slug, &Value::Null))) {
let mut filtered: Value = Value::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_181: bool = true;
while { if !__for_first_181 { i = add(&i, &Value::Int(1)); } __for_first_181 = false; is_less_than(&i, &get_array_length(&result)) } {
let mut event: Value = get_value(&result, &i);
let mut event: Value = get_value(&result, &i);
let mut idMatch: bool = is_true(&(!is_equal(&eventId, &Value::Null))) && is_true(&(is_equal(&self.safe_string_k(event.clone(), "id", &[]), &eventId)));
let mut slugMatch: bool = is_true(&(!is_equal(&slug, &Value::Null))) && is_true(&(is_equal(&self.safe_string_k(event.clone(), "slug", &[]), &slug)));
if is_true(&idMatch) || is_true(&slugMatch) {
append_to_array(&mut filtered, event.clone());
}
}
}
result = filtered.clone();
}
result = self.filter_events_by_status(result.clone(), &[self.safe_string_k(params.clone(), "status", &[])]);
result = self.filter_events_by_tags(result.clone(), &[self.safe_list_k(params.clone(), "tags", &[])]);
// own-line length read so the regex transpiler treats `queries` as an array (count())
// and not a string (strlen()); guard undefined since the default is undefined
let mut queriesLength: Value = Value::Int(0);
if !is_equal(&queries, &Value::Null) {
queriesLength = get_array_length(&queries);
}
if is_greater_than(&queriesLength, &Value::Int(0)) {
result = self.filter_events_by_search_in(result.clone(), queries.clone(), &[self.safe_string_k(params.clone(), "searchIn", &[])]);
}
let mut sort: Value = self.safe_string_k(params.clone(), "sort", &[]);
if !is_equal(&sort, &Value::Null) {
let mut sortKey: Value = Value::Null;
if is_equal(&sort, &Value::Str("volume".to_string())) {
sortKey = Value::Str("volume".to_string());
} else if is_equal(&sort, &Value::Str("liquidity".to_string())) {
sortKey = Value::Str("liquidity".to_string());
} else if is_equal(&sort, &Value::Str("newest".to_string())) {
sortKey = Value::Str("created".to_string());
}
if !is_equal(&sortKey, &Value::Null) {
{
let mut i: Value = Value::Int(0);
let mut __for_first_182: bool = true;
while { if !__for_first_182 { i = add(&i, &Value::Int(1)); } __for_first_182 = false; is_less_than(&i, &get_array_length(&result)) } {
{ let __be_tmp = self.safe_number(get_value(&result, &i), sortKey.clone(), &[Value::Int(0)]); add_element_to_object(get_value_mut(&mut result, &i), &sortKey, __be_tmp.clone()); };
}
}
result = self.sort_by(result.clone(), sortKey.clone(), &[Value::Bool(true), Value::Int(0)]);
}
}
let mut limit: Value = self.safe_integer_k(params.clone(), "limit", &[]);
if !is_equal(&limit, &Value::Null) {
// clamp to the result length: arraySlice(x, 0, limit) with limit > length panics in Go
// via reflect Slice, and throws in C#, unlike JS/Python which return the whole array
let mut resultLength: Value = get_array_length(&result);
let mut sliceEnd: Value = limit.clone();
if is_greater_than(&sliceEnd, &resultLength) {
sliceEnd = resultLength.clone();
}
result = self.array_slice(result.clone(), Value::Int(0), &[sliceEnd.clone()]);
}
return result;
Value::Null
}
fn filter_events_by_status(&self, mut events: Value, optional_args: &[Value]) -> Value {
let mut status = get_arg(optional_args, 0, Value::Null);
// 'active' | 'inactive' | 'closed' | 'all' — 'inactive' and 'closed' are interchangeable
if is_true(&(is_equal(&status, &Value::Null))) || is_true(&(is_equal(&status, &Value::Str("all".to_string())))) {
return events;
}
let mut wantActive: Value = Value::Bool(is_equal(&status, &Value::Str("active".to_string())));
let mut result: Value = Value::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_183: bool = true;
while { if !__for_first_183 { i = add(&i, &Value::Int(1)); } __for_first_183 = false; is_less_than(&i, &get_array_length(&events)) } {
let mut event: Value = get_value(&events, &i);
let mut event: Value = get_value(&events, &i);
let mut isActive: Value = self.safe_bool_k(event.clone(), "active", &[]);
// keep events whose status is unknown (already filtered server-side, no `active` field)
if is_true(&(is_equal(&isActive, &Value::Null))) || is_true(&(is_equal(&isActive, &wantActive))) {
append_to_array(&mut result, event.clone());
}
}
}
return result;
Value::Null
}
fn filter_events_by_search_in(&self, mut events: Value, mut queries: Value, optional_args: &[Value]) -> Value {
let mut searchIn = get_arg(optional_args, 0, Value::Null);
// keep events whose title and/or description contains one of the queries (searchIn defaults to 'both')
// own-line length read so the regex transpiler uses count() (array) not strlen() (string)
let mut queriesLength: Value = Value::Int(0);
if !is_equal(&queries, &Value::Null) {
queriesLength = get_array_length(&queries);
}
if is_true(&(is_equal(&searchIn, &Value::Null))) || is_true(&(is_equal(&queries, &Value::Null))) || is_true(&(is_equal(&queriesLength, &Value::Int(0)))) {
return events;
}
let mut checkTitle: bool = is_true(&(is_equal(&searchIn, &Value::Str("title".to_string())))) || is_true(&(is_equal(&searchIn, &Value::Str("both".to_string()))));
let mut checkDescription: bool = is_true(&(is_equal(&searchIn, &Value::Str("description".to_string())))) || is_true(&(is_equal(&searchIn, &Value::Str("both".to_string()))));
let mut result: Value = Value::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_185: bool = true;
while { if !__for_first_185 { i = add(&i, &Value::Int(1)); } __for_first_185 = false; is_less_than(&i, &get_array_length(&events)) } {
let mut event: Value = get_value(&events, &i);
let mut event: Value = get_value(&events, &i);
let mut title: Value = self.safe_string_lower(event.clone(), Value::Str("title".to_string()), &[Value::Str("".to_string())]);
let mut description: Value = self.safe_string_lower(event.clone(), Value::Str("description".to_string()), &[Value::Str("".to_string())]);
let mut matched: bool = false;
{
let mut qi: Value = Value::Int(0);
let mut __for_first_184: bool = true;
while { if !__for_first_184 { qi = add(&qi, &Value::Int(1)); } __for_first_184 = false; is_less_than(&qi, &get_array_length(&queries)) } {
let mut q: Value = to_lower(&get_value(&queries, &qi));
if is_equal(&title, &Value::Null) {
panic!("{}", crate::exchange_errors::exchange_error(add(&self.id, &Value::Str(" filterEventsBySearchIn() missing title".to_string()))));
}
if is_true(&checkTitle) && is_true(&(is_greater_than_or_equal(&get_index_of(&title, &q), &Value::Int(0)))) {
matched = true;
break;
}
if is_equal(&description, &Value::Null) {
panic!("{}", crate::exchange_errors::exchange_error(add(&self.id, &Value::Str(" filterEventsBySearchIn() missing description".to_string()))));
}
if is_true(&checkDescription) && is_true(&(is_greater_than_or_equal(&get_index_of(&description, &q), &Value::Int(0)))) {
matched = true;
break;
}
}
}
if is_true(&matched) {
append_to_array(&mut result, event.clone());
}
}
}
return result;
Value::Null
}
fn normalize_tag_key(&self, mut tag: Value) -> Value {
// reduce a tag to lowercase alphanumeric words joined by single spaces ("Fed Rates" /
// "fed-rates" / "FED_RATES" all become "fed rates") so label, slug and handle spellings
// of the same tag compare equal — venues surface tags in different forms and callers
// pass any of them. keeping the word boundary avoids cross-word false positives that
// plain concatenation would create ("us open" vs "household")
let mut lower: Value = to_lower(&tag);
let mut allowed: Value = Value::Str("abcdefghijklmnopqrstuvwxyz0123456789".to_string());
let mut chars: Value = self.string_to_chars_array(lower.clone());
let mut s: Value = Value::Str("".to_string());
let mut pendingSep: bool = false;
{
let mut i: Value = Value::Int(0);
let mut __for_first_186: bool = true;
while { if !__for_first_186 { i = add(&i, &Value::Int(1)); } __for_first_186 = false; is_less_than(&i, &get_array_length(&chars)) } {
let mut ch: Value = get_value(&chars, &i);
let mut ch: Value = get_value(&chars, &i);
if is_greater_than_or_equal(&get_index_of(&allowed, &ch), &Value::Int(0)) {
if is_true(&pendingSep) && is_true(&(!is_equal(&s, &Value::Str("".to_string())))) {
s = add(&s, &Value::Str(" ".to_string()));
}
s = add(&s, &ch);
pendingSep = false;
} else {
pendingSep = true;
}
}
}
return s;
Value::Null
}
fn filter_events_by_tags(&self, mut events: Value, optional_args: &[Value]) -> Value {
let mut tags = get_arg(optional_args, 0, Value::Null);
// keep events carrying one of the requested tags; tolerant to string tags and to
// object tags ({ slug, title, ... }) since venues differ. no-op when no tags requested
if is_true(&(is_equal(&tags, &Value::Null))) || is_true(&(is_equal(&get_array_length(&tags), &Value::Int(0)))) {
return events;
}
let mut wanted: Value = Value::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_187: bool = true;
while { if !__for_first_187 { i = add(&i, &Value::Int(1)); } __for_first_187 = false; is_less_than(&i, &get_array_length(&tags)) } {
let mut wantedKey: Value = self.normalize_tag_key(get_value(&tags, &i));
if !is_equal(&wantedKey, &Value::Str("".to_string())) {
// an empty normalized key would substring-match every tag
append_to_array(&mut wanted, wantedKey.clone());
}
}
}
let mut result: Value = Value::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_190: bool = true;
while { if !__for_first_190 { i = add(&i, &Value::Int(1)); } __for_first_190 = false; is_less_than(&i, &get_array_length(&events)) } {
let mut event: Value = get_value(&events, &i);
let mut event: Value = get_value(&events, &i);
let mut eventTags: Value = self.safe_list_k(event.clone(), "tags", &[Value::List(vec![])]);
let mut matched: bool = false;
{
let mut ti: Value = Value::Int(0);
let mut __for_first_189: bool = true;
while { if !__for_first_189 { ti = add(&ti, &Value::Int(1)); } __for_first_189 = false; is_less_than(&ti, &get_array_length(&eventTags)) } {
let mut tag: Value = get_value(&eventTags, &ti);
let mut tag: Value = get_value(&eventTags, &ti);
let mut tagLabel: Value = Value::Null;
if is_string(&tag) {
tagLabel = tag.clone();
} else {
tagLabel = self.safe_string2(tag.clone(), Value::Str("slug".to_string()), Value::Str("title".to_string()), &[]);
}
if !is_equal(&tagLabel, &Value::Null) {
let mut tagKey: Value = self.normalize_tag_key(tagLabel.clone());
{
let mut wi: Value = Value::Int(0);
let mut __for_first_188: bool = true;
while { if !__for_first_188 { wi = add(&wi, &Value::Int(1)); } __for_first_188 = false; is_less_than(&wi, &get_array_length(&wanted)) } {
if is_greater_than_or_equal(&get_index_of(&tagKey, &get_value(&wanted, &wi)), &Value::Int(0)) {
matched = true;
break;
}
}
}
}
if is_true(&matched) {
break;
}
}
}
if is_true(&matched) {
append_to_array(&mut result, event.clone());
}
}
}
return result;
Value::Null
}
fn fetch_events(&mut self, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
// async-virtual: try the derived exchange first
if let Some(__v) = self.dispatch_to_derived("fetch_events", { let mut __args: Vec<crate::Value> = Vec::new(); __args.extend_from_slice(optional_args); __args }).await {
if !matches!(__v, crate::Value::Null) { return __v; }
}
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" fetchEvents() is not supported yet".to_string()))));
Value::Null
} }
fn fetch_event(&mut self, mut id: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
// async-virtual: try the derived exchange first
if let Some(__v) = self.dispatch_to_derived("fetch_event", { let mut __args: Vec<crate::Value> = Vec::new(); __args.push(id.clone()); __args.extend_from_slice(optional_args); __args }).await {
if !matches!(__v, crate::Value::Null) { return __v; }
}
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" fetchEvent() is not supported yet".to_string()))));
Value::Null
} }
fn set_events(&mut self, mut events: Value) -> Value {
// merge (not reset) so successive scoped fetchEvents calls accumulate into the cache.
// index by the unified `event` handle too (that's the identifier every outcome's `event`
// field carries), so getEvent (handle) resolves without each exchange hand-writing it
if is_equal(&self.pred().events, &Value::Null) {
self.pred_mut().events = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
}
if is_equal(&self.pred().events_by_slug, &Value::Null) {
self.pred_mut().events_by_slug = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
}
{
let mut i: Value = Value::Int(0);
let mut __for_first_191: bool = true;
while { if !__for_first_191 { i = add(&i, &Value::Int(1)); } __for_first_191 = false; is_less_than(&i, &get_array_length(&events)) } {
let mut event: Value = get_value(&events, &i);
let mut event: Value = get_value(&events, &i);
let mut id: Value = self.safe_string_k(event.clone(), "id", &[]);
let mut slug: Value = self.safe_string_k(event.clone(), "slug", &[]);
let mut handle: Value = self.safe_string_k(event.clone(), "event", &[]);
if !is_equal(&id, &Value::Null) {
add_element_to_object(&mut self.pred_mut().events, &id, event.clone());
}
if !is_equal(&handle, &Value::Null) {
add_element_to_object(&mut self.pred_mut().events, &handle, event.clone());
}
if !is_equal(&slug, &Value::Null) {
add_element_to_object(&mut self.pred_mut().events_by_slug, &slug, event.clone());
}
}
}
return self.pred().events.clone();
Value::Null
}
fn events_list(&self) -> Value {
// the cached events as a list; empty on a cold instance (this.events is keyed by both
// id and handle, so de-duplicate by identity before returning)
if is_equal(&self.pred().events, &Value::Null) {
return Value::List(vec![]);
}
let mut result: Value = Value::List(vec![]);
let mut seen: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut keys: Value = object_keys(&self.pred().events);
{
let mut i: Value = Value::Int(0);
let mut __for_first_192: bool = true;
while { if !__for_first_192 { i = add(&i, &Value::Int(1)); } __for_first_192 = false; is_less_than(&i, &get_array_length(&keys)) } {
let mut event: Value = get_value(&self.pred().events, &get_value(&keys, &i));
let mut identity: Value = self.safe_string2(event.clone(), Value::Str("id".to_string()), Value::Str("event".to_string()), &[get_value(&keys, &i)]);
if !is_true(&(Value::Bool(in_op(&seen, &identity)))) {
add_element_to_object(&mut seen, &identity, Value::Bool(true));
append_to_array(&mut result, event.clone());
}
}
}
return result;
Value::Null
}
fn load_events_helper(&mut self, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
let mut reload = get_arg(optional_args, 0, Value::Bool(false));
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
// note: the cache-hit shortcut ignores params, so events fetched under one scope are
// returned for a later differently-scoped call. events are scoped (unlike global
// markets), so prefer fetchEvents (params) directly when you need a specific scope
if !is_true(&reload) && is_true(&(!is_equal(&self.pred().events, &Value::Null) && !is_equal(&self.pred().events, &Value::Null))) {
return self.pred().events.clone();
}
let mut events: Value = self.fetch_events(&[params.clone()]).await;
return self.set_events(events.clone());
Value::Null
} }
fn load_events(&mut self, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
let mut reload = get_arg(optional_args, 0, Value::Bool(false));
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
return self.load_events_helper(&[reload.clone(), params.clone()]).await;
Value::Null
} }
fn get_event(&self, mut eventIdOrSlug: Value) -> Value {
// cache-only event resolver (the event analogue of this.outcome) - the cache fills
// through fetchEvents; this never fetches
if is_true(&(!is_equal(&self.pred().events, &Value::Null))) && is_true(&(Value::Bool(in_op(&self.pred().events, &eventIdOrSlug)))) {
return get_value(&self.pred().events, &eventIdOrSlug);
}
if is_true(&(!is_equal(&self.pred().events_by_slug, &Value::Null))) && is_true(&(Value::Bool(in_op(&self.pred().events_by_slug, &eventIdOrSlug)))) {
return get_value(&self.pred().events_by_slug, &eventIdOrSlug);
}
panic!("{}", crate::exchange_errors::bad_symbol(add(&add(&add(&self.id, &Value::Str(" has no cached event ".to_string())), &eventIdOrSlug), &Value::Str(" - call fetchEvents ({ 'query': ... }) first".to_string()))));
Value::Null
}
fn outcome(&self, mut outcomeSymbol: Value) -> Value {
if is_equal(&outcomeSymbol, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" outcome() requires an outcomeSymbol argument".to_string()))));
}
if is_true(&(is_equal(&self.pred().outcomes, &Value::Null))) || is_true(&self.is_empty(self.pred().outcomes.clone())) {
panic!("{}", crate::exchange_errors::exchange_error(add(&self.id, &Value::Str(" outcomes not loaded - call loadOutcomes () or an outcome-addressed method first".to_string()))));
}
if is_true(&Value::Bool(in_op(&self.pred().outcomes, &outcomeSymbol))) {
return get_value(&self.pred().outcomes, &outcomeSymbol);
}
if is_true(&(!is_equal(&self.pred().outcomes_by_id, &Value::Null))) && is_true(&(Value::Bool(in_op(&self.pred().outcomes_by_id, &outcomeSymbol)))) {
return get_value(&self.pred().outcomes_by_id, &outcomeSymbol);
}
panic!("{}", crate::exchange_errors::bad_symbol(add(&add(&add(&self.id, &Value::Str(" does not have outcome ".to_string())), &outcomeSymbol), &Value::Str(" - pass a known outcome handle or outcomeId, or call fetchEvents ()/loadOutcomes () first".to_string()))));
Value::Null
}
fn has_outcome(&self, mut outcomeIdOrSymbol: Value) -> Value {
// sync cache-only membership probe — never throws and never fetches. this is the predicate
// behind loadOutcome's fast path and loadOutcomes' miss filter; safeOutcome (stub on miss)
// and outcome (throws on miss) are the accessors
if is_equal(&outcomeIdOrSymbol, &Value::Null) {
return Value::Bool(false);
}
if is_true(&(!is_equal(&self.pred().outcomes, &Value::Null))) && is_true(&(Value::Bool(in_op(&self.pred().outcomes, &outcomeIdOrSymbol)))) {
return Value::Bool(true);
}
if is_true(&(!is_equal(&self.pred().outcomes_by_id, &Value::Null))) && is_true(&(Value::Bool(in_op(&self.pred().outcomes_by_id, &outcomeIdOrSymbol)))) {
return Value::Bool(true);
}
return Value::Bool(false);
Value::Null
}
fn safe_outcome(&self, mut outcomeIdOrSymbol: Value, optional_args: &[Value]) -> Value {
let mut outcomeObj = get_arg(optional_args, 0, Value::Null);
if !is_equal(&outcomeIdOrSymbol, &Value::Null) {
if is_true(&(!is_equal(&self.pred().outcomes, &Value::Null))) && is_true(&(Value::Bool(in_op(&self.pred().outcomes, &outcomeIdOrSymbol)))) {
return get_value(&self.pred().outcomes, &outcomeIdOrSymbol);
}
if is_true(&(!is_equal(&self.pred().outcomes_by_id, &Value::Null))) && is_true(&(Value::Bool(in_op(&self.pred().outcomes_by_id, &outcomeIdOrSymbol)))) {
return get_value(&self.pred().outcomes_by_id, &outcomeIdOrSymbol);
}
}
if !is_equal(&outcomeObj, &Value::Null) {
return outcomeObj;
}
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("outcome".to_string(), outcomeIdOrSymbol.clone());
m.insert("outcomeId".to_string(), outcomeIdOrSymbol.clone());
m.insert("market".to_string(), Value::Null);
m.insert("label".to_string(), Value::Null);
m.insert("event".to_string(), Value::Null);
m.insert("info".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
m
});
Value::Null
}
fn safe_outcome_symbol(&self, mut outcomeIdOrSymbol: Value, optional_args: &[Value]) -> Value {
let mut outcomeObj = get_arg(optional_args, 0, Value::Null);
outcomeObj = self.safe_outcome(outcomeIdOrSymbol.clone(), &[outcomeObj.clone()]);
return get_value(&outcomeObj, &Value::Str("outcome".to_string()));
Value::Null
}
fn shorten_slug(&self, mut slug: Value) -> Value {
let mut replacements: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("federal-reserve".to_string(), Value::Str("fed".to_string()));
m.insert("interest-rates".to_string(), Value::Str("rates".to_string()));
m.insert("interest-rate".to_string(), Value::Str("rate".to_string()));
m.insert("basis-points".to_string(), Value::Str("bps".to_string()));
m.insert("basis-point".to_string(), Value::Str("bp".to_string()));
m.insert("executive-order".to_string(), Value::Str("eo".to_string()));
m.insert("united-states".to_string(), Value::Str("us".to_string()));
m.insert("united-kingdom".to_string(), Value::Str("uk".to_string()));
m.insert("european-union".to_string(), Value::Str("eu".to_string()));
m.insert("artificial-intelligence".to_string(), Value::Str("ai".to_string()));
m.insert("republican-party".to_string(), Value::Str("gop".to_string()));
m.insert("democratic-party".to_string(), Value::Str("dems".to_string()));
m.insert("stock-market".to_string(), Value::Str("market".to_string()));
m.insert("price-target".to_string(), Value::Str("pt".to_string()));
m.insert("market-cap".to_string(), Value::Str("mcap".to_string()));
m.insert("increase".to_string(), Value::Str("hike".to_string()));
m.insert("decrease".to_string(), Value::Str("cut".to_string()));
m.insert("higher".to_string(), Value::Str("up".to_string()));
m.insert("lower".to_string(), Value::Str("down".to_string()));
m.insert("greater".to_string(), Value::Str("gt".to_string()));
m.insert("less".to_string(), Value::Str("lt".to_string()));
m.insert("million".to_string(), Value::Str("M".to_string()));
m.insert("billion".to_string(), Value::Str("B".to_string()));
m.insert("trillion".to_string(), Value::Str("T".to_string()));
m.insert("percent".to_string(), Value::Str("pct".to_string()));
m
});
let mut stopWords: Value = Value::List(vec![Value::Str("will".to_string()), Value::Str("the".to_string()), Value::Str("a".to_string()), Value::Str("an".to_string()), Value::Str("after".to_string()), Value::Str("before".to_string()), Value::Str("in".to_string()), Value::Str("at".to_string()), Value::Str("by".to_string()), Value::Str("of".to_string()), Value::Str("there".to_string()), Value::Str("be".to_string()), Value::Str("to".to_string()), Value::Str("or".to_string()), Value::Str("and".to_string()), Value::Str("for".to_string()), Value::Str("on".to_string()), Value::Str("its".to_string()), Value::Str("that".to_string()), Value::Str("this".to_string()), Value::Str("from".to_string()), Value::Str("with".to_string()), Value::Str("as".to_string()), Value::Str("is".to_string()), Value::Str("are".to_string()), Value::Str("was".to_string()), Value::Str("were".to_string()), Value::Str("?".to_string()), Value::Str("how".to_string()), Value::Str("many".to_string()), Value::Str("who".to_string()), Value::Str("what".to_string()), Value::Str("when".to_string()), Value::Str("where".to_string()), Value::Str("which".to_string()), Value::Str("much".to_string())]);
let mut lower: Value = ternary(is_true(&(is_equal(&slug, &Value::Null))), Value::Str("".to_string()), to_lower(&slug));
let mut allowed: Value = Value::Str("abcdefghijklmnopqrstuvwxyz0123456789".to_string());
let mut chars: Value = self.string_to_chars_array(lower.clone());
let mut s: Value = Value::Str("".to_string());
let mut lastDash: bool = true; // start true to drop leading separators
{
let mut i: Value = Value::Int(0);
let mut __for_first_193: bool = true;
while { if !__for_first_193 { i = add(&i, &Value::Int(1)); } __for_first_193 = false; is_less_than(&i, &get_array_length(&chars)) } {
let mut ch: Value = get_value(&chars, &i);
let mut ch: Value = get_value(&chars, &i);
if is_greater_than_or_equal(&get_index_of(&allowed, &ch), &Value::Int(0)) {
s = add(&s, &ch);
lastDash = false;
} else if !is_true(&lastDash) {
s = add(&s, &Value::Str("-".to_string()));
lastDash = true;
}
}
}
let mut replacementKeys: Value = object_keys(&replacements);
{
let mut i: Value = Value::Int(0);
let mut __for_first_194: bool = true;
while { if !__for_first_194 { i = add(&i, &Value::Int(1)); } __for_first_194 = false; is_less_than(&i, &get_array_length(&replacementKeys)) } {
let mut replacementKey: Value = get_value(&replacementKeys, &i);
let mut replacementKey: Value = get_value(&replacementKeys, &i);
let mut replacementValue: Value = self.safe_string(replacements.clone(), replacementKey.clone(), &[]);
if !is_equal(&replacementValue, &Value::Null) {
s = replace_all_str(&s, &replacementKey, &replacementValue);
}
}
}
let mut rawParts: Value = split(&s, &Value::Str("-".to_string()));
let mut parts: Value = Value::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_195: bool = true;
while { if !__for_first_195 { i = add(&i, &Value::Int(1)); } __for_first_195 = false; is_less_than(&i, &get_array_length(&rawParts)) } {
let mut w: Value = get_value(&rawParts, &i);
let mut w: Value = get_value(&rawParts, &i);
if is_greater_than(&get_array_length(&w), &Value::Int(0)) && !is_true(&self.in_array(w.clone(), stopWords.clone())) {
append_to_array(&mut parts, w.clone());
}
}
}
let mut joined: Value = join(&parts, &Value::Str("_".to_string()));
return to_upper(&joined);
Value::Null
}
fn slug_to_market_symbol(&self, mut eventSlug: Value, mut marketSlug: Value) -> Value {
// eventSlug is nullable (Str): markets without a parent event (e.g. myriad's 1:1 markets)
// pass undefined — the body already collapses an absent event to just the market part.
// a strict `string` param would make PHP/typed transpilers throw on null before the body runs.
// qualify the market handle with its event so two events that share a market label
// — e.g. kalshi's KXFEDDECISION-28JAN and -27OCT both list "Cut 25bps" — do NOT collapse
// to the same handle — a collision silently overwrites markets in this.markets and would
// resolve an outcome to the wrong event (wrong-market trade). skip the prefix when the
// event slug is absent or identical to the market slug (e.g. myriad's 1:1 markets), so
// already-unique handles stay clean.
let mut marketPart: Value = self.shorten_slug(marketSlug.clone());
let mut eventPart: Value = self.shorten_slug(eventSlug.clone());
if is_true(&(is_equal(&eventPart, &Value::Null))) || is_true(&(is_equal(&eventPart, &Value::Str("".to_string())))) || is_true(&(is_equal(&eventPart, &marketPart))) {
return marketPart;
}
return add(&add(&eventPart, &Value::Str("_".to_string())), &marketPart);
Value::Null
}
fn slug_to_outcome_symbol(&self, mut eventSlug: Value, mut marketSlug: Value, mut outcome: Value) -> Value {
// build on slugToMarketSymbol so the outcome handle stays consistent with the market symbol
// — both event-qualified or both not — otherwise a qualified market + unqualified outcome mismatch.
// the label gets a light slug treatment (uppercase alphanumerics joined by '_', no stop-word
// removal so labels like "UP OR DOWN" survive intact) — venue labels with spaces or
// currency symbols ("JD Vance", a dollar-sign price) yield clean handles (JD_VANCE, 120)
// instead of leaking raw text into the outcome handle
if is_equal(&outcome, &Value::Null) {
outcome = Value::Str("".to_string());
}
let mut upper: Value = to_upper(&outcome);
let mut allowed: Value = Value::Str("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789".to_string());
let mut chars: Value = self.string_to_chars_array(upper.clone());
let mut label: Value = Value::Str("".to_string());
let mut pendingSep: bool = false;
{
let mut i: Value = Value::Int(0);
let mut __for_first_196: bool = true;
while { if !__for_first_196 { i = add(&i, &Value::Int(1)); } __for_first_196 = false; is_less_than(&i, &get_array_length(&chars)) } {
let mut ch: Value = get_value(&chars, &i);
let mut ch: Value = get_value(&chars, &i);
if is_greater_than_or_equal(&get_index_of(&allowed, &ch), &Value::Int(0)) {
if is_true(&pendingSep) && is_true(&(!is_equal(&label, &Value::Str("".to_string())))) {
label = add(&label, &Value::Str("_".to_string()));
}
label = add(&label, &ch);
pendingSep = false;
} else {
pendingSep = true;
}
}
}
if is_equal(&label, &Value::Str("".to_string())) {
// a label with no alphanumerics at all (unrealistic, but keep the :LABEL contract)
label = upper.clone();
}
return add(&add(&self.slug_to_market_symbol(eventSlug.clone(), marketSlug.clone()), &Value::Str(":".to_string())), &label);
Value::Null
}
fn set_markets(&mut self, mut markets: Value, optional_args: &[Value]) -> Value {
let mut currencies = get_arg(optional_args, 0, Value::Null);
// prediction market rows carry only the unified `market` handle — `symbol` is
// deprecated there. the base indexer keys this.markets/this.symbols by 'symbol',
// so alias the handle onto a shallow copy per row; the caller's rows stay symbol-free
let mut marketsList: Value = self.to_array(markets.clone());
let mut aliased: Value = Value::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_197: bool = true;
while { if !__for_first_197 { i = add(&i, &Value::Int(1)); } __for_first_197 = false; is_less_than(&i, &get_array_length(&marketsList)) } {
let mut row: Value = get_value(&marketsList, &i);
let mut row: Value = get_value(&marketsList, &i);
let mut copy: Value = self.extend(Value::Map({
let mut m = indexmap::IndexMap::new();
m
}), &[row.clone()]);
add_element_to_object(&mut copy, &Value::Str("symbol".to_string()), self.safe_string2(row.clone(), Value::Str("market".to_string()), Value::Str("symbol".to_string()), &[]));
append_to_array(&mut aliased, copy.clone());
}
}
let mut stored: Value = self.super_set_markets(aliased.clone(), currencies.clone());
// strip the alias back off the stored rows — venues assemble user-visible event
// structures from this.markets (hyperliquid groups its outcome markets that way),
// so a leftover 'symbol' key would leak the deprecated field back to the caller
let mut marketKeys: Value = object_keys(&stored);
{
let mut i: Value = Value::Int(0);
let mut __for_first_198: bool = true;
while { if !__for_first_198 { i = add(&i, &Value::Int(1)); } __for_first_198 = false; is_less_than(&i, &get_array_length(&marketKeys)) } {
let mut key: Value = get_value(&marketKeys, &i);
let mut key: Value = get_value(&marketKeys, &i);
{ let __be_tmp = self.omit(get_value(&stored, &key), Value::Str("symbol".to_string()), &[]); add_element_to_object(&mut stored, &key, __be_tmp.clone()); };
}
}
self.populate_outcomes();
return stored;
Value::Null
}
fn index_market_outcomes(&mut self, mut market: Value) {
// index one market's outcome tokens into this.outcomes / this.outcomes_by_id,
// normalizing each to the canonical identity keys (outcome / outcomeId / market) so
// consumers and the safe* helpers stay uniform even when an exchange's parseMarket
// still emits the legacy symbol / id / marketSymbol keys. used both by populateOutcomes
// for a full rebuild and by on-demand single-market fetches (kalshi fetchOutcome), so a
// cache miss doesn't force a full O(markets x outcomes) rebuild per new outcome
if is_equal(&self.pred().outcomes, &Value::Null) {
self.pred_mut().outcomes = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
}
if is_equal(&self.pred().outcomes_by_id, &Value::Null) {
self.pred_mut().outcomes_by_id = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
}
let mut outcomesList: Value = self.safe_list_k(market.clone(), "outcomes", &[Value::List(vec![])]);
{
let mut j: Value = Value::Int(0);
let mut __for_first_199: bool = true;
while { if !__for_first_199 { j = add(&j, &Value::Int(1)); } __for_first_199 = false; is_less_than(&j, &get_array_length(&outcomesList)) } {
let mut oc: Value = get_value(&outcomesList, &j);
let mut oc: Value = get_value(&outcomesList, &j);
let mut ocSymbol: Value = self.safe_string2(oc.clone(), Value::Str("outcome".to_string()), Value::Str("symbol".to_string()), &[]);
let mut ocId: Value = self.safe_string2(oc.clone(), Value::Str("outcomeId".to_string()), Value::Str("id".to_string()), &[]);
// assign unconditionally — safeString2 keeps the canonical key when present
// and falls back to the legacy one, so this never clobbers and avoids a
// missing-key access that throws in Python/PHP, unlike TS undefined
add_element_to_object(&mut oc, &Value::Str("outcomeId".to_string()), ocId.clone());
{ let __be_tmp = self.safe_string2(oc.clone(), Value::Str("market".to_string()), Value::Str("marketSymbol".to_string()), &[]); add_element_to_object(&mut oc, &Value::Str("market".to_string()), __be_tmp.clone()); };
if !is_equal(&ocSymbol, &Value::Null) {
// shortenSlug is lossy, so two different markets can produce the same handle.
// on a real collision of same handle but different outcomeId, disambiguate the
// second one deterministically instead of silently overwriting the first —
// trading the wrong market would otherwise be indistinguishable
let mut existing: Value = self.safe_value(self.pred().outcomes.clone(), ocSymbol.clone(), &[]);
if !is_equal(&existing, &Value::Null) {
let mut existingId: Value = self.safe_string_k(existing.clone(), "outcomeId", &[]);
if is_true(&(!is_equal(&existingId, &Value::Null))) && is_true(&(!is_equal(&ocId, &Value::Null))) && is_true(&(!is_equal(&existingId, &ocId))) {
let mut idLen: Value = get_array_length(&ocId);
let mut suffix: Value = ocId.clone();
if is_greater_than(&idLen, &Value::Int(6)) {
suffix = slice(&ocId, &subtract(&idLen, &Value::Int(6)), &Value::Null);
}
ocSymbol = add(&add(&ocSymbol, &Value::Str("_".to_string())), &to_upper(&suffix));
}
}
add_element_to_object(&mut oc, &Value::Str("outcome".to_string()), ocSymbol.clone());
add_element_to_object(&mut self.pred_mut().outcomes, &ocSymbol, oc.clone());
} else {
add_element_to_object(&mut oc, &Value::Str("outcome".to_string()), ocSymbol.clone());
}
if !is_equal(&ocId, &Value::Null) {
add_element_to_object(&mut self.pred_mut().outcomes_by_id, &ocId, oc.clone());
}
}
}
}
fn populate_outcomes(&mut self) {
// rebuild the whole outcome lookup cache from this.markets (each market carries its
// outcome tokens under the outcomes key) so cached market data works offline. no-op on
// a cold instance where markets are not loaded yet (avoids a null-access crash on the
// eventId/slug-only fetchEvents path)
self.pred_mut().outcomes = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
self.pred_mut().outcomes_by_id = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
if is_equal(&self.markets, &Value::Null) {
return;
}
let mut marketKeys: Value = object_keys(&self.markets);
{
let mut i: Value = Value::Int(0);
let mut __for_first_200: bool = true;
while { if !__for_first_200 { i = add(&i, &Value::Int(1)); } __for_first_200 = false; is_less_than(&i, &get_array_length(&marketKeys)) } {
self.index_market_outcomes(get_value(&self.markets, &get_value(&marketKeys, &i)));
}
}
}
fn index_event_outcomes(&mut self, mut event: Value) {
// register a single event's markets into this.markets and rebuild the outcome cache so the
// handles fetchEvent() returns resolve immediately in outcome-addressed methods (fetchTicker,
// createOrder, ...). without this, on a cold instance or a loadAllOutcomes:false venue
// such as kalshi, the returned handles are unusable — fetchTicker(ev.markets[0].outcomes[0].outcome)
// BadSymbols because the outcome was never cached
if is_equal(&self.markets, &Value::Null) {
{ let __t = self.create_safe_dictionary(&[]); self.markets = __t; }
}
let mut markets: Value = self.safe_list_k(event.clone(), "markets", &[Value::List(vec![])]);
let mut marketsLength: Value = get_array_length(&markets);
{
let mut i: Value = Value::Int(0);
let mut __for_first_201: bool = true;
while { if !__for_first_201 { i = add(&i, &Value::Int(1)); } __for_first_201 = false; is_less_than(&i, &marketsLength) } {
let mut m: Value = get_value(&markets, &i);
let mut m: Value = get_value(&markets, &i);
let mut marketHandle: Value = self.safe_string2(m.clone(), Value::Str("market".to_string()), Value::Str("symbol".to_string()), &[]);
if !is_equal(&marketHandle, &Value::Null) {
add_element_to_object(&mut self.markets, &marketHandle, m.clone());
}
}
}
self.populate_outcomes();
}
fn load_outcomes<'ccxt_rec>(&'ccxt_rec mut self, optional_args: &'ccxt_rec [Value]) -> ::std::pin::Pin<Box<dyn ::std::future::Future<Output = Value> + Send + 'ccxt_rec>> { Box::pin(async move {
let mut outcomes = get_arg(optional_args, 0, Value::Null);
let mut reload = get_arg(optional_args, 1, Value::Bool(false));
let mut params = get_arg(optional_args, 2, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
// outcome-addressed methods call this first, mirroring loadMarkets(). two modes:
// - an `outcomes` list (scoped): sync-filter the cache and resolve ONLY the misses through
// fetchOutcomes — venues with a batch by-id endpoint (kalshi, polymarket) override it to
// collapse all misses into one request; a warm cache returns with zero per-outcome awaits
// - no `outcomes` (bulk): load the capped markets listing once and index every outcome —
// idempotent unless reload; only worth paying on venues whose whole universe is one
// cheap request (hyperliquid), or when the user explicitly wants the top-N set
// loadMarkets()/populateOutcomes() rebuild the lookup caches explicitly (the setMarkets
// override is not dispatched by the base loadMarkets under the Go/C#/Java transpilers)
if !is_equal(&outcomes, &Value::Null) {
let mut missing: Value = Value::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_202: bool = true;
while { if !__for_first_202 { i = add(&i, &Value::Int(1)); } __for_first_202 = false; is_less_than(&i, &get_array_length(&outcomes)) } {
if is_true(&reload) || !is_true(&self.has_outcome(get_value(&outcomes, &i))) {
append_to_array(&mut missing, get_value(&outcomes, &i));
}
}
}
let mut missingLength: Value = get_array_length(&missing);
let mut wasWarm: bool = is_true(&(!is_equal(&self.pred().outcomes, &Value::Null))) && !is_true(&self.is_empty(self.pred().outcomes.clone()));
let mut loadAll: Value = self.safe_bool_k(self.options.clone(), "loadAllOutcomes", &[Value::Bool(false)]);
if is_true(&(is_greater_than(&missingLength, &Value::Int(0)))) && is_true(&(is_equal(&loadAll, &Value::Bool(true)))) && !is_true(&wasWarm) && !is_true(&reload) {
// same trade-off as loadOutcome: on venues where the whole universe is one cheap
// request (hyperliquid), a cold miss bulk-warms once instead of fetching per outcome
self.load_outcomes(&[]).await;
let mut stillMissing: Value = Value::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_203: bool = true;
while { if !__for_first_203 { i = add(&i, &Value::Int(1)); } __for_first_203 = false; is_less_than(&i, &missingLength) } {
if !is_true(&self.has_outcome(get_value(&missing, &i))) {
append_to_array(&mut stillMissing, get_value(&missing, &i));
}
}
}
missing = stillMissing.clone();
missingLength = get_array_length(&missing);
}
if is_greater_than(&missingLength, &Value::Int(0)) {
self.fetch_outcomes(missing.clone()).await;
}
return self.pred().outcomes.clone();
}
if !is_true(&reload) && is_true(&(!is_equal(&self.pred().outcomes, &Value::Null))) && !is_true(&self.is_empty(self.pred().outcomes.clone())) {
return self.pred().outcomes.clone();
}
self.load_markets(&[reload.clone(), params.clone()]).await;
self.populate_outcomes();
return self.pred().outcomes.clone();
Value::Null
}) }
/*
* @ignore
* @method
* @name PredictionExchange#fetchOutcomes
* @description resolves several uncached outcomes. the base has no batch by-id endpoint, so it fetches them one by one through fetchOutcome (which throws BadSymbol for an unresolvable one); venues with a batch endpoint (kalshi, polymarket) override this to collapse the list into one request
* @param {string[]} outcomeSymbols the uncached outcome handles or ids to resolve
* @returns {object} the outcome cache
*/
fn fetch_outcomes(&mut self, mut outcomeSymbols: Value) -> impl ::std::future::Future<Output = Value> + Send { async move {
// async-virtual: try the derived exchange first
if let Some(__v) = self.dispatch_to_derived("fetch_outcomes", vec![outcomeSymbols.clone()]).await {
if !matches!(__v, crate::Value::Null) { return __v; }
}
{
let mut i: Value = Value::Int(0);
let mut __for_first_204: bool = true;
while { if !__for_first_204 { i = add(&i, &Value::Int(1)); } __for_first_204 = false; is_less_than(&i, &get_array_length(&outcomeSymbols)) } {
self.fetch_outcome(get_value(&outcomeSymbols, &i)).await;
}
}
return self.pred().outcomes.clone();
Value::Null
} }
fn load_outcome(&mut self, mut outcomeSymbol: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
let mut reload = get_arg(optional_args, 0, Value::Bool(false));
// resolve a single outcome — the per-outcome analogue of loadMarkets()+market(). a cache hit
// returns at once (pass reload=true to skip the cache and refetch the outcome's metadata).
// on a miss, fetchOutcome resolves just the requested outcome on demand — a by-id fetch on
// venues with such an endpoint (kalshi, polymarket) or the venue's scoped search otherwise.
// options.loadAllOutcomes (default false) opts back into the legacy bulk warm-up: the first
// miss loads the whole (capped) listing once so later lookups are 0-network hits — only
// sane on venues whose full universe is one cheap request (hyperliquid)
if is_equal(&outcomeSymbol, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" loadOutcome() requires an outcomeSymbol argument".to_string()))));
}
if !is_true(&reload) {
if is_true(&self.has_outcome(outcomeSymbol.clone())) {
return self.safe_outcome(outcomeSymbol.clone(), &[]);
}
let mut wasWarm: bool = is_true(&(!is_equal(&self.pred().outcomes, &Value::Null))) && !is_true(&self.is_empty(self.pred().outcomes.clone()));
// if markets are already loaded (offline-injected, or loaded by loadMarkets/fetchEvents)
// but the outcome cache is cold, index them for free before hitting the network — this
// makes cold-cache resolution consistent across languages regardless of loadAllOutcomes
if !is_true(&wasWarm) && is_true(&(!is_equal(&self.markets, &Value::Null))) && !is_true(&self.is_empty(self.markets.clone())) {
self.populate_outcomes();
if is_true(&self.has_outcome(outcomeSymbol.clone())) {
return self.safe_outcome(outcomeSymbol.clone(), &[]);
}
}
let mut loadAll: Value = self.safe_bool_k(self.options.clone(), "loadAllOutcomes", &[Value::Bool(false)]);
if is_true(&(is_equal(&loadAll, &Value::Bool(true)))) && !is_true(&wasWarm) {
// a miss on a cold cache: bulk-load once so later lookups are 0-network hits.
// a miss on an already-warm cache is authoritative — the outcome genuinely isn't
// listed, so fall through to fetchOutcome (a real BadSymbol) rather than refetching
// the whole listing (which would mask typos and clobber offline-injected markets)
self.load_outcomes(&[]).await;
if is_true(&self.has_outcome(outcomeSymbol.clone())) {
return self.safe_outcome(outcomeSymbol.clone(), &[]);
}
}
}
return self.fetch_outcome(outcomeSymbol.clone()).await;
Value::Null
} }
fn outcome_search_query(&self, mut outcomeSymbol: Value) -> Value {
// derive a human search query from a unified outcome handle (EVENT_MARKET:LABEL) so a
// cache miss can be resolved through the venue's scoped search instead of a bulk listing
// download. returns undefined for id-like inputs (numeric token ids, 0x hashes) that
// carry no searchable words
let mut marketPart: Value = outcomeSymbol.clone();
let mut colonIndex: Value = get_index_of(&outcomeSymbol, &Value::Str(":".to_string()));
if is_greater_than_or_equal(&colonIndex, &Value::Int(0)) {
marketPart = slice(&outcomeSymbol, &Value::Int(0), &colonIndex);
}
if is_equal(&get_index_of(&marketPart, &Value::Str("0x".to_string())), &Value::Int(0)) {
return Value::Null;
}
// handles join words with '_' (slug-derived) or legacy '-' separated inputs (normalized below)
let mut normalized: Value = replace_all_str(&to_lower(&marketPart), &Value::Str("-".to_string()), &Value::Str("_".to_string()));
let mut rawWords: Value = split(&normalized, &Value::Str("_".to_string()));
let mut words: Value = Value::List(vec![]);
let mut hasLetters: bool = false;
let mut letters: Value = Value::Str("abcdefghijklmnopqrstuvwxyz".to_string());
{
let mut i: Value = Value::Int(0);
let mut __for_first_206: bool = true;
while { if !__for_first_206 { i = add(&i, &Value::Int(1)); } __for_first_206 = false; is_less_than(&i, &get_array_length(&rawWords)) } {
let mut word: Value = get_value(&rawWords, &i);
let mut word: Value = get_value(&rawWords, &i);
// inline .length so the php transpiler emits strlen() — the standalone
// `const n = str.length;` statement form wrongly becomes count() (array)
if is_equal(&get_array_length(&word), &Value::Int(0)) {
continue;
}
let mut wordHasLetters: bool = false;
let mut chars: Value = self.string_to_chars_array(word.clone());
{
let mut ci: Value = Value::Int(0);
let mut __for_first_205: bool = true;
while { if !__for_first_205 { ci = add(&ci, &Value::Int(1)); } __for_first_205 = false; is_less_than(&ci, &get_array_length(&chars)) } {
if is_greater_than_or_equal(&get_index_of(&letters, &get_value(&chars, &ci)), &Value::Int(0)) {
wordHasLetters = true;
break;
}
}
}
// the query is the handle's letter-bearing words only. standalone numeric
// tokens (slug timestamps, strikes, years) are venue artifacts that title searches don't
// reliably index — and since the result is re-checked against the EXACT handle,
// a broader query only adds recall, never a wrong match
if !is_true(&wordHasLetters) {
continue;
}
append_to_array(&mut words, word.clone());
hasLetters = true;
}
}
let mut wordsLength: Value = get_array_length(&words);
if is_true(&(is_equal(&wordsLength, &Value::Int(0)))) || !is_true(&hasLetters) {
return Value::Null;
}
return join(&words, &Value::Str(" ".to_string()));
Value::Null
}
fn fetch_outcome(&mut self, mut outcomeSymbol: Value) -> impl ::std::future::Future<Output = Value> + Send { async move {
// async-virtual: try the derived exchange first
if let Some(__v) = self.dispatch_to_derived("fetch_outcome", vec![outcomeSymbol.clone()]).await {
if !matches!(__v, crate::Value::Null) { return __v; }
}
// fetch just one outcome on demand — never through a bulk listing download. the base has
// no generic by-id endpoint, so it derives a search query from the handle and resolves it
// through the venue's own scoped fetchEvents (which caches everything it finds), then
// re-checks the cache. venues with a real by-id fetch (kalshi by ticker, polymarket by
// token id) override this with a cheaper single fetch and fall back to super on a miss.
let mut searchQuery: Value = self.outcome_search_query(outcomeSymbol.clone());
if is_true(&(!is_equal(&searchQuery, &Value::Null))) && is_true(&self.safe_bool_k(self.has.clone(), "fetchEvents", &[Value::Bool(false)])) {
let mut searchLimit: Value = self.safe_integer_k(self.options.clone(), "fetchOutcomeSearchLimit", &[Value::Int(10)]);
let _try_result = futures::FutureExt::catch_unwind(std::panic::AssertUnwindSafe(async {
self.fetch_events(&[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("query".to_string(), searchQuery.clone());
m.insert("limit".to_string(), searchLimit.clone());
m
})]).await;
#[allow(unreachable_code)] { Value::Null }})).await;
if let Err(_try_err) = _try_result { let e: Value = panic_to_value(_try_err);
// a query with zero matches surfaces as BadSymbol on some venues — treat it as a
// plain miss (the guidance-rich throw below); let real transport errors propagate
if !is_true(&(is_instance(&e, &Value::Str("BadSymbol".to_string())))) {
panic!("{}", e);
}
}
if is_true(&self.has_outcome(outcomeSymbol.clone())) {
return self.safe_outcome(outcomeSymbol.clone(), &[]);
}
}
panic!("{}", crate::exchange_errors::bad_symbol(add(&add(&add(&self.id, &Value::Str(" could not resolve outcome ".to_string())), &outcomeSymbol), &Value::Str(" — call fetchEvents ({ 'query': ... }) first, or pass a known outcomeId".to_string()))));
Value::Null
} }
/*
* @method
* @name fetchTicker
* @description fetches a price ticker for a single prediction outcome
* @param {string} outcome unified outcome handle
* @param {object} [params] extra exchange-specific parameters
* @returns {object} a prediction [ticker structure](https://docs.ccxt.com/#/?id=ticker-structure)
*/
fn fetch_ticker(&mut self, mut outcome: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
// async-virtual: try the derived exchange first
if let Some(__v) = self.dispatch_to_derived("fetch_ticker", { let mut __args: Vec<crate::Value> = Vec::new(); __args.push(outcome.clone()); __args.extend_from_slice(optional_args); __args }).await {
if !matches!(__v, crate::Value::Null) { return __v; }
}
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" fetchTicker() is not supported yet".to_string()))));
Value::Null
} }
/*
* @method
* @name fetchTickers
* @description fetches price tickers for multiple prediction outcomes at once
* @param {string[]} [outcomes] unified outcome handles or outcome ids
* @param {object} [params] extra exchange-specific parameters
* @returns {object} a dictionary of prediction [ticker structures](https://docs.ccxt.com/#/?id=ticker-structure) indexed by outcome
*/
fn fetch_tickers(&mut self, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
// async-virtual: try the derived exchange first
if let Some(__v) = self.dispatch_to_derived("fetch_tickers", { let mut __args: Vec<crate::Value> = Vec::new(); __args.extend_from_slice(optional_args); __args }).await {
if !matches!(__v, crate::Value::Null) { return __v; }
}
let mut outcomes = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" fetchTickers() is not supported yet".to_string()))));
Value::Null
} }
/*
* @method
* @name fetchOrderBook
* @description fetches the order book for a prediction outcome
* @param {string} outcome unified outcome handle
* @param {int} [limit] the maximum number of order book entries to return
* @param {object} [params] extra exchange-specific parameters
* @returns {object} a prediction [order book structure](https://docs.ccxt.com/#/?id=order-book-structure)
*/
fn fetch_order_book(&mut self, mut outcome: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
// async-virtual: try the derived exchange first
if let Some(__v) = self.dispatch_to_derived("fetch_order_book", { let mut __args: Vec<crate::Value> = Vec::new(); __args.push(outcome.clone()); __args.extend_from_slice(optional_args); __args }).await {
if !matches!(__v, crate::Value::Null) { return __v; }
}
let mut limit = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" fetchOrderBook() is not supported yet".to_string()))));
Value::Null
} }
/*
* @method
* @name fetchOHLCV
* @description fetches historical candlestick data for a prediction outcome
* @param {string} outcome unified outcome handle
* @param {string} timeframe the length of time each candle represents
* @param {int} [since] timestamp in ms of the earliest candle to fetch
* @param {int} [limit] the maximum number of candles to fetch
* @param {object} [params] extra exchange-specific parameters
* @returns {int[][]} a list of candles ordered as timestamp, open, high, low, close, volume
*/
fn fetch_ohlcv(&mut self, mut outcome: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
// async-virtual: try the derived exchange first
if let Some(__v) = self.dispatch_to_derived("fetch_ohlcv", { let mut __args: Vec<crate::Value> = Vec::new(); __args.push(outcome.clone()); __args.extend_from_slice(optional_args); __args }).await {
if !matches!(__v, crate::Value::Null) { return __v; }
}
let mut timeframe = get_arg(optional_args, 0, Value::Str("1m".to_string()));
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
return self.super_fetch_ohlcv(outcome.clone(), timeframe.clone(), since.clone(), limit.clone(), params.clone()).await;
Value::Null
} }
/*
* @method
* @name fetchTrades
* @description get the list of most recent trades for a prediction outcome
* @param {string} outcome unified outcome handle
* @param {int} [since] timestamp in ms of the earliest trade to fetch
* @param {int} [limit] the maximum number of trades to fetch
* @param {object} [params] extra exchange-specific parameters
* @returns {object[]} a list of prediction [trade structures](https://docs.ccxt.com/#/?id=public-trades)
*/
fn fetch_trades(&mut self, mut outcome: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
// async-virtual: try the derived exchange first
if let Some(__v) = self.dispatch_to_derived("fetch_trades", { let mut __args: Vec<crate::Value> = Vec::new(); __args.push(outcome.clone()); __args.extend_from_slice(optional_args); __args }).await {
if !matches!(__v, crate::Value::Null) { return __v; }
}
let mut since = get_arg(optional_args, 0, Value::Null);
let mut limit = get_arg(optional_args, 1, Value::Null);
let mut params = get_arg(optional_args, 2, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" fetchTrades() is not supported yet".to_string()))));
Value::Null
} }
/*
* @method
* @name createOrder
* @description create a trade order on a prediction outcome
* @param {string} outcome unified outcome handle
* @param {string} type 'market' or 'limit'
* @param {string} side 'buy' or 'sell'
* @param {float} amount how many shares of the outcome to trade
* @param {float} [price] the price at which the order is to be filled, in cost per share
* @param {object} [params] extra exchange-specific parameters
* @returns {object} a prediction [order structure](https://docs.ccxt.com/#/?id=order-structure)
*/
fn create_order(&mut self, mut outcome: Value, mut type_var: Value, mut side: Value, mut amount: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
// async-virtual: try the derived exchange first
if let Some(__v) = self.dispatch_to_derived("create_order", { let mut __args: Vec<crate::Value> = Vec::new(); __args.push(outcome.clone()); __args.push(type_var.clone()); __args.push(side.clone()); __args.push(amount.clone()); __args.extend_from_slice(optional_args); __args }).await {
if !matches!(__v, crate::Value::Null) { return __v; }
}
let mut price = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" createOrder() is not supported yet".to_string()))));
Value::Null
} }
/*
* @method
* @name cancelOrder
* @description cancels an open order
* @param {string} id order id
* @param {string} [outcome] unified outcome handle
* @param {object} [params] extra exchange-specific parameters
* @returns {object} a prediction [order structure](https://docs.ccxt.com/#/?id=order-structure)
*/
fn cancel_order(&mut self, mut id: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
// async-virtual: try the derived exchange first
if let Some(__v) = self.dispatch_to_derived("cancel_order", { let mut __args: Vec<crate::Value> = Vec::new(); __args.push(id.clone()); __args.extend_from_slice(optional_args); __args }).await {
if !matches!(__v, crate::Value::Null) { return __v; }
}
let mut outcome = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" cancelOrder() is not supported yet".to_string()))));
Value::Null
} }
/*
* @method
* @name watchTicker
* @description watches a price ticker for a single prediction outcome
* @param {string} outcome unified outcome handle
* @param {object} [params] extra exchange-specific parameters
* @returns {object} a prediction [ticker structure](https://docs.ccxt.com/#/?id=ticker-structure)
*/
fn watch_ticker(&mut self, mut outcome: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" watchTicker() is not supported yet".to_string()))));
Value::Null
} }
/*
* @method
* @name watchOrderBook
* @description watches the order book for a prediction outcome
* @param {string} outcome unified outcome handle
* @param {int} [limit] the maximum number of order book entries to return
* @param {object} [params] extra exchange-specific parameters
* @returns {object} a prediction [order book structure](https://docs.ccxt.com/#/?id=order-book-structure)
*/
fn watch_order_book(&mut self, mut outcome: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
let mut limit = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" watchOrderBook() is not supported yet".to_string()))));
Value::Null
} }
/*
* @method
* @name watchTrades
* @description watches the most recent trades for a prediction outcome
* @param {string} outcome unified outcome handle
* @param {int} [since] timestamp in ms of the earliest trade to fetch
* @param {int} [limit] the maximum number of trades to fetch
* @param {object} [params] extra exchange-specific parameters
* @returns {object[]} a list of prediction [trade structures](https://docs.ccxt.com/#/?id=public-trades)
*/
fn watch_trades(&mut self, mut outcome: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
let mut since = get_arg(optional_args, 0, Value::Null);
let mut limit = get_arg(optional_args, 1, Value::Null);
let mut params = get_arg(optional_args, 2, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" watchTrades() is not supported yet".to_string()))));
Value::Null
} }
/*
* @method
* @name fetchOrders
* @description fetches information on multiple orders made by the user
* @param {string} [outcome] unified outcome handle
* @param {int} [since] timestamp in ms of the earliest order to fetch
* @param {int} [limit] the maximum number of orders to fetch
* @param {object} [params] extra exchange-specific parameters
* @returns {object[]} a list of prediction [order structures](https://docs.ccxt.com/#/?id=order-structure)
*/
fn fetch_orders(&mut self, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
// async-virtual: try the derived exchange first
if let Some(__v) = self.dispatch_to_derived("fetch_orders", { let mut __args: Vec<crate::Value> = Vec::new(); __args.extend_from_slice(optional_args); __args }).await {
if !matches!(__v, crate::Value::Null) { return __v; }
}
let mut outcome = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" fetchOrders() is not supported yet".to_string()))));
Value::Null
} }
/*
* @method
* @name fetchOpenOrders
* @description fetches information on the user's open orders
* @param {string} [outcome] unified outcome handle
* @param {int} [since] timestamp in ms of the earliest order to fetch
* @param {int} [limit] the maximum number of orders to fetch
* @param {object} [params] extra exchange-specific parameters
* @returns {object[]} a list of prediction [order structures](https://docs.ccxt.com/#/?id=order-structure)
*/
fn fetch_open_orders(&mut self, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
// async-virtual: try the derived exchange first
if let Some(__v) = self.dispatch_to_derived("fetch_open_orders", { let mut __args: Vec<crate::Value> = Vec::new(); __args.extend_from_slice(optional_args); __args }).await {
if !matches!(__v, crate::Value::Null) { return __v; }
}
let mut outcome = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" fetchOpenOrders() is not supported yet".to_string()))));
Value::Null
} }
/*
* @method
* @name fetchClosedOrders
* @description fetches information on multiple closed orders made by the user
* @param {string} [outcome] unified outcome handle
* @param {int} [since] timestamp in ms of the earliest order to fetch
* @param {int} [limit] the maximum number of orders to fetch
* @param {object} [params] extra exchange-specific parameters
* @returns {object[]} a list of prediction [order structures](https://docs.ccxt.com/#/?id=order-structure)
*/
fn fetch_closed_orders(&mut self, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
// async-virtual: try the derived exchange first
if let Some(__v) = self.dispatch_to_derived("fetch_closed_orders", { let mut __args: Vec<crate::Value> = Vec::new(); __args.extend_from_slice(optional_args); __args }).await {
if !matches!(__v, crate::Value::Null) { return __v; }
}
let mut outcome = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" fetchClosedOrders() is not supported yet".to_string()))));
Value::Null
} }
/*
* @method
* @name fetchOrderTrades
* @description fetch all the trades made from a single order
* @param {string} id order id
* @param {string} [outcome] unified outcome handle
* @param {int} [since] timestamp in ms of the earliest trade to fetch
* @param {int} [limit] the maximum number of trades to fetch
* @param {object} [params] extra exchange-specific parameters
* @returns {object[]} a list of prediction [trade structures](https://docs.ccxt.com/#/?id=trade-structure)
*/
fn fetch_order_trades(&mut self, mut id: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
let mut outcome = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" fetchOrderTrades() is not supported yet".to_string()))));
Value::Null
} }
/*
* @method
* @name fetchMyTrades
* @description fetch all trades made by the user
* @param {string} [outcome] unified outcome handle
* @param {int} [since] timestamp in ms of the earliest trade to fetch
* @param {int} [limit] the maximum number of trades to fetch
* @param {object} [params] extra exchange-specific parameters
* @returns {object[]} a list of prediction [trade structures](https://docs.ccxt.com/#/?id=trade-structure)
*/
fn fetch_my_trades(&mut self, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
// async-virtual: try the derived exchange first
if let Some(__v) = self.dispatch_to_derived("fetch_my_trades", { let mut __args: Vec<crate::Value> = Vec::new(); __args.extend_from_slice(optional_args); __args }).await {
if !matches!(__v, crate::Value::Null) { return __v; }
}
let mut outcome = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" fetchMyTrades() is not supported yet".to_string()))));
Value::Null
} }
/*
* @method
* @name fetchPosition
* @description fetch the open position held on a single prediction outcome
* @param {string} outcome unified outcome handle
* @param {object} [params] extra exchange-specific parameters
* @returns {object} a prediction [position structure](https://docs.ccxt.com/#/?id=position-structure)
*/
fn fetch_position(&mut self, mut outcome: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
// async-virtual: try the derived exchange first
if let Some(__v) = self.dispatch_to_derived("fetch_position", { let mut __args: Vec<crate::Value> = Vec::new(); __args.push(outcome.clone()); __args.extend_from_slice(optional_args); __args }).await {
if !matches!(__v, crate::Value::Null) { return __v; }
}
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" fetchPosition() is not supported yet".to_string()))));
Value::Null
} }
/*
* @method
* @name fetchPositions
* @description fetches the user's open positions
* @param {string[]} [outcomes] unified outcome handles to filter by
* @param {object} [params] extra exchange-specific parameters
* @returns {object[]} a list of prediction [position structures](https://docs.ccxt.com/#/?id=position-structure)
*/
fn fetch_positions(&mut self, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
// async-virtual: try the derived exchange first
if let Some(__v) = self.dispatch_to_derived("fetch_positions", { let mut __args: Vec<crate::Value> = Vec::new(); __args.extend_from_slice(optional_args); __args }).await {
if !matches!(__v, crate::Value::Null) { return __v; }
}
let mut outcomes = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" fetchPositions() is not supported yet".to_string()))));
Value::Null
} }
/*
* @method
* @name fetchTradingFee
* @description fetch the trading fee for a prediction outcome
* @param {string} outcome unified outcome handle
* @param {object} [params] extra exchange-specific parameters
* @returns {object} a prediction [fee structure](https://docs.ccxt.com/#/?id=fee-structure)
*/
fn fetch_trading_fee(&mut self, mut outcome: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
// async-virtual: try the derived exchange first
if let Some(__v) = self.dispatch_to_derived("fetch_trading_fee", { let mut __args: Vec<crate::Value> = Vec::new(); __args.push(outcome.clone()); __args.extend_from_slice(optional_args); __args }).await {
if !matches!(__v, crate::Value::Null) { return __v; }
}
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" fetchTradingFee() is not supported yet".to_string()))));
Value::Null
} }
/*
* @method
* @name fetchOpenInterest
* @description fetch the open interest of a prediction outcome
* @param {string} outcome unified outcome handle
* @param {object} [params] extra exchange-specific parameters
* @returns {object} an [open interest structure](https://docs.ccxt.com/#/?id=open-interest-structure)
*/
fn fetch_open_interest(&mut self, mut outcome: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
// async-virtual: try the derived exchange first
if let Some(__v) = self.dispatch_to_derived("fetch_open_interest", { let mut __args: Vec<crate::Value> = Vec::new(); __args.push(outcome.clone()); __args.extend_from_slice(optional_args); __args }).await {
if !matches!(__v, crate::Value::Null) { return __v; }
}
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" fetchOpenInterest() is not supported yet".to_string()))));
Value::Null
} }
/*
* @method
* @name createOrders
* @description create a list of trade orders
* @param {object[]} orders a list of PredictionOrderRequest objects, each carrying an `outcome` handle
* @param {object} [params] extra exchange-specific parameters
* @returns {object[]} a list of prediction [order structures](https://docs.ccxt.com/#/?id=order-structure)
*/
fn create_orders(&mut self, mut orders: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
// async-virtual: try the derived exchange first
if let Some(__v) = self.dispatch_to_derived("create_orders", { let mut __args: Vec<crate::Value> = Vec::new(); __args.push(orders.clone()); __args.extend_from_slice(optional_args); __args }).await {
if !matches!(__v, crate::Value::Null) { return __v; }
}
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" createOrders() is not supported yet".to_string()))));
Value::Null
} }
/*
* @method
* @name cancelOrders
* @description cancel multiple orders
* @param {string[]} ids order ids
* @param {string} [outcome] unified outcome handle
* @param {object} [params] extra exchange-specific parameters
* @returns {object[]} a list of prediction [order structures](https://docs.ccxt.com/#/?id=order-structure)
*/
fn cancel_orders(&mut self, mut ids: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
// async-virtual: try the derived exchange first
if let Some(__v) = self.dispatch_to_derived("cancel_orders", { let mut __args: Vec<crate::Value> = Vec::new(); __args.push(ids.clone()); __args.extend_from_slice(optional_args); __args }).await {
if !matches!(__v, crate::Value::Null) { return __v; }
}
let mut outcome = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" cancelOrders() is not supported yet".to_string()))));
Value::Null
} }
/*
* @method
* @name createMarketBuyOrderWithCost
* @description create a market buy order on a prediction outcome by providing the cost
* @param {string} outcome unified outcome handle
* @param {float} cost how much you want to spend, in cost terms
* @param {object} [params] extra exchange-specific parameters
* @returns {object} a prediction [order structure](https://docs.ccxt.com/#/?id=order-structure)
*/
fn create_market_buy_order_with_cost(&mut self, mut outcome: Value, mut cost: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
// safeBool, not this.options['...'] — a raw missing-key access throws KeyError in Python/PHP
// when the option is undeclared (it is for every prediction exchange)
if is_true(&self.safe_bool_k(self.options.clone(), "createMarketBuyOrderRequiresPrice", &[Value::Bool(false)])) || is_true(&self.safe_bool_k(self.has.clone(), "createMarketBuyOrderWithCost", &[Value::Bool(false)])) {
return <Self as crate::prediction_exchange_generated::PredictionBase>::create_order(self, outcome.clone(), Value::Str("market".to_string()), Value::Str("buy".to_string()), cost.clone(), &[Value::Int(1), params.clone()]).await;
}
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" createMarketBuyOrderWithCost() is not supported yet".to_string()))));
Value::Null
} }
/*
* @method
* @name createMarketSellOrderWithCost
* @description create a market sell order on a prediction outcome by providing the cost
* @param {string} outcome unified outcome handle
* @param {float} cost how much you want to receive, in cost terms
* @param {object} [params] extra exchange-specific parameters
* @returns {object} a prediction [order structure](https://docs.ccxt.com/#/?id=order-structure)
*/
fn create_market_sell_order_with_cost(&mut self, mut outcome: Value, mut cost: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_true(&self.safe_bool_k(self.options.clone(), "createMarketSellOrderRequiresPrice", &[Value::Bool(false)])) || is_true(&self.safe_bool_k(self.has.clone(), "createMarketSellOrderWithCost", &[Value::Bool(false)])) {
return <Self as crate::prediction_exchange_generated::PredictionBase>::create_order(self, outcome.clone(), Value::Str("market".to_string()), Value::Str("sell".to_string()), cost.clone(), &[Value::Int(1), params.clone()]).await;
}
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" createMarketSellOrderWithCost() is not supported yet".to_string()))));
Value::Null
} }
/*
* @method
* @name watchTickers
* @description watches price tickers for multiple prediction outcomes
* @param {string[]} [outcomes] unified outcome handles to watch
* @param {object} [params] extra exchange-specific parameters
* @returns {object} a dictionary of prediction [ticker structures](https://docs.ccxt.com/#/?id=ticker-structure)
*/
fn watch_tickers(&mut self, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
let mut outcomes = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" watchTickers() is not supported yet".to_string()))));
Value::Null
} }
/*
* @method
* @name watchOrders
* @description watches information on multiple orders made by the user
* @param {string} [outcome] unified outcome handle
* @param {int} [since] timestamp in ms of the earliest order to watch
* @param {int} [limit] the maximum number of orders to watch
* @param {object} [params] extra exchange-specific parameters
* @returns {object[]} a list of prediction [order structures](https://docs.ccxt.com/#/?id=order-structure)
*/
fn watch_orders(&mut self, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
let mut outcome = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" watchOrders() is not supported yet".to_string()))));
Value::Null
} }
/*
* @method
* @name watchMyTrades
* @description watches all trades made by the user
* @param {string} [outcome] unified outcome handle
* @param {int} [since] timestamp in ms of the earliest trade to watch
* @param {int} [limit] the maximum number of trades to watch
* @param {object} [params] extra exchange-specific parameters
* @returns {object[]} a list of prediction [trade structures](https://docs.ccxt.com/#/?id=trade-structure)
*/
fn watch_my_trades(&mut self, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
let mut outcome = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" watchMyTrades() is not supported yet".to_string()))));
Value::Null
} }
/*
* @method
* @name watchPositions
* @description watches the open positions held by the user
* @param {string[]} [outcomes] unified outcome handles to watch
* @param {int} [since] timestamp in ms of the earliest position to watch
* @param {int} [limit] the maximum number of positions to watch
* @param {object} [params] extra exchange-specific parameters
* @returns {object[]} a list of prediction [position structures](https://docs.ccxt.com/#/?id=position-structure)
*/
fn watch_positions(&mut self, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
let mut outcomes = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" watchPositions() is not supported yet".to_string()))));
Value::Null
} }
/*
* @method
* @name fetchSettlements
* @description fetches the user's settled (resolved) positions — the "close the loop" record after
* markets resolve, with the collateral paid out and the realized pnl
* @param {string} [outcome] filter to a single unified outcome handle
* @param {int} [since] timestamp in ms of the earliest settlement to fetch
* @param {int} [limit] the maximum number of settlements to fetch
* @param {object} [params] extra exchange-specific parameters
* @returns {object[]} a list of prediction settlement structures
*/
fn fetch_settlements(&mut self, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
let mut outcome = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" fetchSettlements() is not supported yet".to_string()))));
Value::Null
} }
fn safe_prediction_order(&self, mut outcomeOrder: Value, optional_args: &[Value]) -> Value {
let mut outcomeObj = get_arg(optional_args, 0, Value::Null);
// build the prediction order directly (do NOT delegate to the crypto safeOrder, which injects
// ~a dozen derivatives fields — stopPrice/triggerPrice/reduceOnly noise — the prediction type
// never declares, and whose parseTrades post-filters embedded fills by `symbol`, dropping every
// outcome-addressed row). prediction is always linear with a contract size of 1.
let mut amount: Value = self.omit_zero(self.safe_string_k(outcomeOrder.clone(), "amount", &[]));
let mut filled: Value = self.safe_string_k(outcomeOrder.clone(), "filled", &[]);
let mut remaining: Value = self.safe_string_k(outcomeOrder.clone(), "remaining", &[]);
let mut cost: Value = self.safe_string_k(outcomeOrder.clone(), "cost", &[]);
let mut average: Value = self.omit_zero(self.safe_string_k(outcomeOrder.clone(), "average", &[]));
let mut price: Value = self.omit_zero(self.safe_string_k(outcomeOrder.clone(), "price", &[]));
let mut side: Value = self.safe_string_k(outcomeOrder.clone(), "side", &[]);
let mut status: Value = self.safe_string_k(outcomeOrder.clone(), "status", &[]);
let mut lastTradeTimestamp: Value = self.safe_integer_k(outcomeOrder.clone(), "lastTradeTimestamp", &[]);
// parse embedded fills with the OUTCOME-aware parser (parseTrades would drop them on the symbol filter)
let mut rawTrades: Value = self.safe_list_k(outcomeOrder.clone(), "trades", &[Value::List(vec![])]);
let mut trades: Value = self.parse_prediction_trades(rawTrades.clone(), &[outcomeObj.clone()]);
let mut tradesLength: Value = get_array_length(&trades);
let mut feeList: Value = Value::List(vec![]);
if is_greater_than(&tradesLength, &Value::Int(0)) {
if is_equal(&filled, &Value::Null) {
filled = Value::Str("0".to_string());
}
if is_equal(&cost, &Value::Null) {
cost = Value::Str("0".to_string());
}
{
let mut i: Value = Value::Int(0);
let mut __for_first_207: bool = true;
while { if !__for_first_207 { i = add(&i, &Value::Int(1)); } __for_first_207 = false; is_less_than(&i, &tradesLength) } {
let mut trade: Value = get_value(&trades, &i);
let mut trade: Value = get_value(&trades, &i);
let mut tradeAmount: Value = self.safe_string_k(trade.clone(), "amount", &[]);
if !is_equal(&tradeAmount, &Value::Null) {
filled = crate::precise::Precise::stringAdd(&filled, &tradeAmount);
}
let mut tradeCost: Value = self.safe_string_k(trade.clone(), "cost", &[]);
if !is_equal(&tradeCost, &Value::Null) {
cost = crate::precise::Precise::stringAdd(&cost, &tradeCost);
}
if is_equal(&side, &Value::Null) {
side = self.safe_string_k(trade.clone(), "side", &[]);
}
let mut tradeTimestamp: Value = self.safe_integer_k(trade.clone(), "timestamp", &[]);
if !is_equal(&tradeTimestamp, &Value::Null) {
if is_equal(&lastTradeTimestamp, &Value::Null) {
lastTradeTimestamp = tradeTimestamp.clone();
} else if is_greater_than(&tradeTimestamp, &lastTradeTimestamp) {
lastTradeTimestamp = tradeTimestamp.clone();
}
}
let mut tradeFee: Value = self.safe_dict_k(trade.clone(), "fee", &[]);
if !is_equal(&tradeFee, &Value::Null) {
append_to_array(&mut feeList, tradeFee.clone());
}
}
}
}
// fill any totals the venue left undefined (linear, contract size 1)
if is_true(&(is_equal(&filled, &Value::Null))) && is_true(&(!is_equal(&amount, &Value::Null))) && is_true(&(!is_equal(&remaining, &Value::Null))) {
filled = crate::precise::Precise::stringSub(&amount, &remaining);
}
if is_true(&(is_equal(&remaining, &Value::Null))) && is_true(&(!is_equal(&amount, &Value::Null))) && is_true(&(!is_equal(&filled, &Value::Null))) {
remaining = crate::precise::Precise::stringSub(&amount, &filled);
}
if is_true(&(is_equal(&amount, &Value::Null))) && is_true(&(!is_equal(&filled, &Value::Null))) && is_true(&(!is_equal(&remaining, &Value::Null))) {
amount = crate::precise::Precise::stringAdd(&filled, &remaining);
}
if is_true(&(is_equal(&average, &Value::Null))) && is_true(&(!is_equal(&filled, &Value::Null))) && is_true(&(!is_equal(&cost, &Value::Null))) && is_true(&crate::precise::Precise::stringGt(&filled, &Value::Str("0".to_string()))) {
average = crate::precise::Precise::stringDiv(&cost, &filled);
}
if is_true(&(is_equal(&cost, &Value::Null))) && is_true(&(!is_equal(&filled, &Value::Null))) {
let mut multiplyPrice: Value = ternary(is_true(&(!is_equal(&average, &Value::Null))), average.clone(), price.clone());
if !is_equal(&multiplyPrice, &Value::Null) {
cost = crate::precise::Precise::stringMul(&filled, &multiplyPrice);
}
}
let mut fee: Value = self.safe_dict_k(outcomeOrder.clone(), "fee", &[]);
// own-line length reads so the regex transpiler emits count() (array), not strlen()
let mut feeListLength: Value = get_array_length(&feeList);
if is_true(&(is_equal(&fee, &Value::Null))) && is_true(&(is_greater_than(&feeListLength, &Value::Int(0)))) {
let mut reduced: Value = self.reduce_fees_by_currency(feeList.clone());
let mut reducedLength: Value = get_array_length(&reduced);
if is_greater_than(&reducedLength, &Value::Int(0)) {
fee = get_value(&reduced, &Value::Int(0));
}
}
// derive timeInForce/postOnly the same way the crypto safeOrder does (prediction has no
// trigger orders, so the isTriggerOrSLTp guard collapses): a market order defaults to IOC
let mut orderType: Value = self.safe_string_k(outcomeOrder.clone(), "type", &[]);
let mut timeInForce: Value = self.safe_string_k(outcomeOrder.clone(), "timeInForce", &[]);
let mut postOnly: Value = self.safe_bool_k(outcomeOrder.clone(), "postOnly", &[]);
if is_equal(&timeInForce, &Value::Null) {
if is_equal(&orderType, &Value::Str("market".to_string())) {
timeInForce = Value::Str("IOC".to_string());
}
if is_equal(&postOnly, &Value::Bool(true)) {
timeInForce = Value::Str("PO".to_string());
}
} else if is_equal(&postOnly, &Value::Null) {
postOnly = Value::Bool(is_equal(&timeInForce, &Value::Str("PO".to_string())));
}
let mut timestamp: Value = self.safe_integer_k(outcomeOrder.clone(), "timestamp", &[]);
let mut datetime: Value = self.safe_string_k(outcomeOrder.clone(), "datetime", &[]);
if is_equal(&datetime, &Value::Null) {
datetime = self.iso8601(timestamp.clone());
}
let mut result: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), self.safe_string_k(outcomeOrder.clone(), "id", &[]));
m.insert("clientOrderId".to_string(), self.safe_string_k(outcomeOrder.clone(), "clientOrderId", &[]));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), datetime.clone());
m.insert("lastTradeTimestamp".to_string(), lastTradeTimestamp.clone());
m.insert("lastUpdateTimestamp".to_string(), self.safe_integer_k(outcomeOrder.clone(), "lastUpdateTimestamp", &[]));
m.insert("status".to_string(), status.clone());
m.insert("type".to_string(), orderType.clone());
m.insert("timeInForce".to_string(), timeInForce.clone());
m.insert("side".to_string(), side.clone());
m.insert("price".to_string(), self.parse_number(price.clone(), &[]));
m.insert("average".to_string(), self.parse_number(average.clone(), &[]));
m.insert("amount".to_string(), self.parse_number(amount.clone(), &[]));
m.insert("filled".to_string(), self.parse_number(filled.clone(), &[]));
m.insert("remaining".to_string(), self.parse_number(remaining.clone(), &[]));
m.insert("cost".to_string(), self.parse_number(cost.clone(), &[]));
m.insert("fee".to_string(), fee.clone());
m.insert("reduceOnly".to_string(), self.safe_bool_k(outcomeOrder.clone(), "reduceOnly", &[]));
m.insert("postOnly".to_string(), postOnly.clone());
m.insert("trades".to_string(), trades.clone());
m.insert("outcome".to_string(), self.safe_string_k(outcomeOrder.clone(), "outcome", &[]));
m.insert("outcomeId".to_string(), self.safe_string_k(outcomeOrder.clone(), "outcomeId", &[]));
m.insert("label".to_string(), self.safe_string_k(outcomeOrder.clone(), "label", &[]));
m.insert("market".to_string(), self.safe_string_k(outcomeOrder.clone(), "market", &[]));
m.insert("event".to_string(), self.safe_string_k(outcomeOrder.clone(), "event", &[]));
m.insert("info".to_string(), self.safe_value_k(outcomeOrder.clone(), "info", &[outcomeOrder.clone()]));
m
});
return result;
Value::Null
}
fn safe_prediction_trade(&self, mut trade: Value, optional_args: &[Value]) -> Value {
let mut outcomeObj = get_arg(optional_args, 0, Value::Null);
// build the prediction trade directly (no crypto safeTrade, which leaks fields the type omits)
let mut price: Value = self.safe_string_k(trade.clone(), "price", &[]);
let mut amount: Value = self.safe_string_k(trade.clone(), "amount", &[]);
let mut cost: Value = self.safe_string_k(trade.clone(), "cost", &[]);
if is_true(&(is_equal(&cost, &Value::Null))) && is_true(&(!is_equal(&price, &Value::Null))) && is_true(&(!is_equal(&amount, &Value::Null))) {
cost = crate::precise::Precise::stringMul(&price, &amount);
}
let mut timestamp: Value = self.safe_integer_k(trade.clone(), "timestamp", &[]);
let mut datetime: Value = self.safe_string_k(trade.clone(), "datetime", &[]);
if is_equal(&datetime, &Value::Null) {
datetime = self.iso8601(timestamp.clone());
}
let mut result: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), self.safe_string_k(trade.clone(), "id", &[]));
m.insert("order".to_string(), self.safe_string_k(trade.clone(), "order", &[]));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), datetime.clone());
m.insert("type".to_string(), self.safe_string_k(trade.clone(), "type", &[]));
m.insert("side".to_string(), self.safe_string_k(trade.clone(), "side", &[]));
m.insert("takerOrMaker".to_string(), self.safe_string_k(trade.clone(), "takerOrMaker", &[]));
m.insert("price".to_string(), self.parse_number(price.clone(), &[]));
m.insert("amount".to_string(), self.parse_number(amount.clone(), &[]));
m.insert("cost".to_string(), self.parse_number(cost.clone(), &[]));
m.insert("fee".to_string(), self.safe_dict_k(trade.clone(), "fee", &[]));
m.insert("realizedPnl".to_string(), self.safe_number_k(trade.clone(), "realizedPnl", &[]));
m.insert("outcome".to_string(), self.safe_string_k(trade.clone(), "outcome", &[]));
m.insert("outcomeId".to_string(), self.safe_string_k(trade.clone(), "outcomeId", &[]));
m.insert("label".to_string(), self.safe_string_k(trade.clone(), "label", &[]));
m.insert("market".to_string(), self.safe_string_k(trade.clone(), "market", &[]));
m.insert("info".to_string(), self.safe_value_k(trade.clone(), "info", &[trade.clone()]));
m
});
return result;
Value::Null
}
fn safe_prediction_ticker(&self, mut ticker: Value, optional_args: &[Value]) -> Value {
let mut outcomeObj = get_arg(optional_args, 0, Value::Null);
// build the prediction ticker directly (no crypto safeTicker, which injects vwap/previousClose/
// indexPrice/markPrice the type omits). derive change/percentage/average only from open+close —
// prediction venues report those directly, so the crypto back-derivation from percentage is moot.
let mut open: Value = self.omit_zero(self.safe_string_k(ticker.clone(), "open", &[]));
let mut close: Value = self.omit_zero(self.safe_string2(ticker.clone(), Value::Str("close".to_string()), Value::Str("last".to_string()), &[]));
let mut last: Value = self.omit_zero(self.safe_string2(ticker.clone(), Value::Str("last".to_string()), Value::Str("close".to_string()), &[]));
let mut change: Value = self.safe_string_k(ticker.clone(), "change", &[]);
let mut percentage: Value = self.omit_zero(self.safe_string_k(ticker.clone(), "percentage", &[]));
let mut average: Value = self.omit_zero(self.safe_string_k(ticker.clone(), "average", &[]));
if is_true(&(is_equal(&change, &Value::Null))) && is_true(&(!is_equal(&open, &Value::Null))) && is_true(&(!is_equal(&close, &Value::Null))) {
change = crate::precise::Precise::stringSub(&close, &open);
}
if is_true(&(is_equal(&percentage, &Value::Null))) && is_true(&(!is_equal(&change, &Value::Null))) && is_true(&(!is_equal(&open, &Value::Null))) && is_true(&crate::precise::Precise::stringGt(&open, &Value::Str("0".to_string()))) {
percentage = crate::precise::Precise::stringMul(&crate::precise::Precise::stringDiv(&change, &open), &Value::Str("100".to_string()));
}
if is_true(&(is_equal(&average, &Value::Null))) && is_true(&(!is_equal(&open, &Value::Null))) && is_true(&(!is_equal(&close, &Value::Null))) {
average = crate::precise::Precise::stringDiv(&crate::precise::Precise::stringAdd(&open, &close), &Value::Str("2".to_string()));
}
let mut timestamp: Value = self.safe_integer_k(ticker.clone(), "timestamp", &[]);
let mut datetime: Value = self.safe_string_k(ticker.clone(), "datetime", &[]);
if is_equal(&datetime, &Value::Null) {
datetime = self.iso8601(timestamp.clone());
}
let mut result: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), datetime.clone());
m.insert("high".to_string(), self.safe_number_k(ticker.clone(), "high", &[]));
m.insert("low".to_string(), self.safe_number_k(ticker.clone(), "low", &[]));
m.insert("bid".to_string(), self.parse_number(self.omit_zero(self.safe_string_k(ticker.clone(), "bid", &[])), &[]));
m.insert("bidVolume".to_string(), self.safe_number_k(ticker.clone(), "bidVolume", &[]));
m.insert("ask".to_string(), self.parse_number(self.omit_zero(self.safe_string_k(ticker.clone(), "ask", &[])), &[]));
m.insert("askVolume".to_string(), self.safe_number_k(ticker.clone(), "askVolume", &[]));
m.insert("open".to_string(), self.parse_number(open.clone(), &[]));
m.insert("close".to_string(), self.parse_number(close.clone(), &[]));
m.insert("last".to_string(), self.parse_number(last.clone(), &[]));
m.insert("change".to_string(), self.parse_number(change.clone(), &[]));
m.insert("percentage".to_string(), self.parse_number(percentage.clone(), &[]));
m.insert("average".to_string(), self.parse_number(average.clone(), &[]));
m.insert("baseVolume".to_string(), self.safe_number_k(ticker.clone(), "baseVolume", &[]));
m.insert("quoteVolume".to_string(), self.safe_number_k(ticker.clone(), "quoteVolume", &[]));
m.insert("openInterest".to_string(), self.safe_number_k(ticker.clone(), "openInterest", &[]));
m.insert("outcome".to_string(), self.safe_string_k(ticker.clone(), "outcome", &[]));
m.insert("outcomeId".to_string(), self.safe_string_k(ticker.clone(), "outcomeId", &[]));
m.insert("label".to_string(), self.safe_string_k(ticker.clone(), "label", &[]));
m.insert("market".to_string(), self.safe_string_k(ticker.clone(), "market", &[]));
m.insert("event".to_string(), self.safe_string_k(ticker.clone(), "event", &[]));
m.insert("info".to_string(), self.safe_value_k(ticker.clone(), "info", &[ticker.clone()]));
m
});
return result;
Value::Null
}
fn safe_prediction_position(&self, mut position: Value) -> Value {
// build the prediction position directly (no crypto safePosition, which carries the whole
// leverage/marginMode/liquidation block the prediction type omits)
let mut timestamp: Value = self.safe_integer_k(position.clone(), "timestamp", &[]);
let mut datetime: Value = self.safe_string_k(position.clone(), "datetime", &[]);
if is_equal(&datetime, &Value::Null) {
datetime = self.iso8601(timestamp.clone());
}
let mut result: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), self.safe_string_k(position.clone(), "id", &[]));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), datetime.clone());
m.insert("contracts".to_string(), self.safe_number_k(position.clone(), "contracts", &[]));
m.insert("contractSize".to_string(), self.safe_number_k(position.clone(), "contractSize", &[]));
m.insert("side".to_string(), self.safe_string_k(position.clone(), "side", &[]));
m.insert("notional".to_string(), self.safe_number_k(position.clone(), "notional", &[]));
m.insert("unrealizedPnl".to_string(), self.safe_number_k(position.clone(), "unrealizedPnl", &[]));
m.insert("realizedPnl".to_string(), self.safe_number_k(position.clone(), "realizedPnl", &[]));
m.insert("collateral".to_string(), self.safe_number_k(position.clone(), "collateral", &[]));
m.insert("entryPrice".to_string(), self.safe_number_k(position.clone(), "entryPrice", &[]));
m.insert("markPrice".to_string(), self.safe_number_k(position.clone(), "markPrice", &[]));
m.insert("lastPrice".to_string(), self.safe_number_k(position.clone(), "lastPrice", &[]));
m.insert("percentage".to_string(), self.safe_number_k(position.clone(), "percentage", &[]));
m.insert("resolved".to_string(), self.safe_bool_k(position.clone(), "resolved", &[]));
m.insert("won".to_string(), self.safe_bool_k(position.clone(), "won", &[]));
m.insert("settleFraction".to_string(), self.safe_number_k(position.clone(), "settleFraction", &[]));
m.insert("payout".to_string(), self.safe_number_k(position.clone(), "payout", &[]));
m.insert("outcome".to_string(), self.safe_string_k(position.clone(), "outcome", &[]));
m.insert("outcomeId".to_string(), self.safe_string_k(position.clone(), "outcomeId", &[]));
m.insert("label".to_string(), self.safe_string_k(position.clone(), "label", &[]));
m.insert("market".to_string(), self.safe_string_k(position.clone(), "market", &[]));
m.insert("event".to_string(), self.safe_string_k(position.clone(), "event", &[]));
m.insert("info".to_string(), self.safe_value_k(position.clone(), "info", &[position.clone()]));
m
});
return result;
Value::Null
}
fn safe_prediction_order_book(&self, mut orderbook: Value, optional_args: &[Value]) -> Value {
let mut outcomeObj = get_arg(optional_args, 0, Value::Null);
// normalize a parsed order book to the prediction shape: replace the unified
// `symbol` with the `outcome` handle and attach the outcome identity fields
// outcomeId and market - so books match the PredictionOrderBook structure.
let mut fallback: Value = self.safe_string2(orderbook.clone(), Value::Str("outcome".to_string()), Value::Str("symbol".to_string()), &[]);
add_element_to_object(&mut orderbook, &Value::Str("outcome".to_string()), ternary(is_true(&(is_equal(&outcomeObj, &Value::Null))), fallback.clone(), self.safe_string_k(outcomeObj.clone(), "outcome", &[fallback.clone()])));
{ let __be_tmp = ternary(is_true(&(is_equal(&outcomeObj, &Value::Null))), self.safe_string_k(orderbook.clone(), "outcomeId", &[]), self.safe_string_k(outcomeObj.clone(), "outcomeId", &[])); add_element_to_object(&mut orderbook, &Value::Str("outcomeId".to_string()), __be_tmp.clone()); };
{ let __be_tmp = ternary(is_true(&(is_equal(&outcomeObj, &Value::Null))), self.safe_string_k(orderbook.clone(), "market", &[]), self.safe_string_k(outcomeObj.clone(), "market", &[])); add_element_to_object(&mut orderbook, &Value::Str("market".to_string()), __be_tmp.clone()); };
return self.omit(orderbook.clone(), Value::Str("symbol".to_string()), &[]);
Value::Null
}
fn parse_prediction_ticker(&self, mut ticker: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" parsePredictionTicker() is not supported yet".to_string()))));
Value::Null
}
fn parse_prediction_order(&self, mut order: Value, optional_args: &[Value]) -> Value {
// virtual-dispatch (static: DerivedExchange::parse_prediction_order(self, ...))
{ let __v = crate::exchange::DerivedExchange::parse_prediction_order(self, order.clone(), crate::runtime::get_arg(optional_args, 0, crate::Value::Null)); if !matches!(__v, crate::Value::Null) { return __v; } }
let mut market = get_arg(optional_args, 0, Value::Null);
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" parsePredictionOrder() is not supported yet".to_string()))));
Value::Null
}
fn parse_prediction_trade(&self, mut trade: Value, optional_args: &[Value]) -> Value {
// virtual-dispatch (static: DerivedExchange::parse_prediction_trade(self, ...))
{ let __v = crate::exchange::DerivedExchange::parse_prediction_trade(self, trade.clone(), crate::runtime::get_arg(optional_args, 0, crate::Value::Null)); if !matches!(__v, crate::Value::Null) { return __v; } }
let mut market = get_arg(optional_args, 0, Value::Null);
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" parsePredictionTrade() is not supported yet".to_string()))));
Value::Null
}
fn parse_prediction_position(&self, mut position: Value, optional_args: &[Value]) -> Value {
// virtual-dispatch (static: DerivedExchange::parse_prediction_position(self, ...))
{ let __v = crate::exchange::DerivedExchange::parse_prediction_position(self, position.clone(), crate::runtime::get_arg(optional_args, 0, crate::Value::Null)); if !matches!(__v, crate::Value::Null) { return __v; } }
let mut market = get_arg(optional_args, 0, Value::Null);
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" parsePredictionPosition() is not supported yet".to_string()))));
Value::Null
}
fn parse_prediction_open_interest(&self, mut interest: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" parsePredictionOpenInterest() is not supported yet".to_string()))));
Value::Null
}
/*
* @ignore
* @method
* @name PredictionExchange#parsePredictionTrades
* @description parses a list of raw trades with the exchange's parsePredictionTrade, sorts them and filters by the outcome handle — the prediction analogue of the base parseTrades
* @param {object[]} trades the raw trades
* @param {object} [outcomeObj] the resolved outcome object the trades belong to
* @param {int} [since] timestamp in ms of the earliest trade to return
* @param {int} [limit] the maximum number of trades to return
* @param {object} [params] extra fields to merge into every parsed trade
* @returns {object[]} a list of prediction [trade structures](https://docs.ccxt.com/#/?id=public-trades)
*/
fn parse_prediction_trades(&self, mut trades: Value, optional_args: &[Value]) -> Value {
let mut outcomeObj = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
// prediction-market analogue of the base parseTrades: the base aggregator post-filters
// by the market's `symbol` key, but prediction structures carry an `outcome` handle
// instead — and an outcome object rebuilt from cached markets may still hold a legacy
// `symbol` key, which would silently drop every parsed row
let mut rows: Value = self.to_array(trades.clone());
let mut results: Value = Value::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_208: bool = true;
while { if !__for_first_208 { i = add(&i, &Value::Int(1)); } __for_first_208 = false; is_less_than(&i, &get_array_length(&rows)) } {
let mut parsed: Value = <Self as crate::prediction_exchange_generated::PredictionBase>::parse_prediction_trade(self, get_value(&rows, &i), &[outcomeObj.clone()]);
let mut trade: Value = self.extend(parsed.clone(), &[params.clone()]);
append_to_array(&mut results, trade.clone());
}
}
results = self.sort_by2(results.clone(), Value::Str("timestamp".to_string()), Value::Str("id".to_string()), &[]);
let mut outcomeHandle: Value = self.safe_string_k(outcomeObj.clone(), "outcome", &[]);
return self.filter_by_outcome_since_limit(results.clone(), &[outcomeHandle.clone(), since.clone(), limit.clone()]);
Value::Null
}
/*
* @ignore
* @method
* @name PredictionExchange#parsePredictionOrders
* @description parses a list of raw orders with the exchange's parsePredictionOrder, sorts them and filters by the outcome handle — the prediction analogue of the base parseOrders
* @param {object[]} orders the raw orders
* @param {object} [outcomeObj] the resolved outcome object the orders belong to
* @param {int} [since] timestamp in ms of the earliest order to return
* @param {int} [limit] the maximum number of orders to return
* @param {object} [params] extra fields to merge into every parsed order
* @returns {object[]} a list of prediction [order structures](https://docs.ccxt.com/#/?id=order-structure)
*/
fn parse_prediction_orders(&self, mut orders: Value, optional_args: &[Value]) -> Value {
let mut outcomeObj = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
// prediction-market analogue of the base parseOrders — see parsePredictionTrades
let mut rows: Value = self.to_array(orders.clone());
let mut results: Value = Value::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_209: bool = true;
while { if !__for_first_209 { i = add(&i, &Value::Int(1)); } __for_first_209 = false; is_less_than(&i, &get_array_length(&rows)) } {
let mut parsed: Value = <Self as crate::prediction_exchange_generated::PredictionBase>::parse_prediction_order(self, get_value(&rows, &i), &[outcomeObj.clone()]);
let mut order: Value = self.extend(parsed.clone(), &[params.clone()]);
append_to_array(&mut results, order.clone());
}
}
results = self.sort_by(results.clone(), Value::Str("timestamp".to_string()), &[]);
let mut outcomeHandle: Value = self.safe_string_k(outcomeObj.clone(), "outcome", &[]);
return self.filter_by_outcome_since_limit(results.clone(), &[outcomeHandle.clone(), since.clone(), limit.clone()]);
Value::Null
}
/*
* @ignore
* @method
* @name PredictionExchange#parsePredictionPositions
* @description parses a list of raw positions with the exchange's parsePredictionPosition — the prediction analogue of the base parsePositions
* @param {object[]} positions the raw positions
* @param {object} [params] extra fields to merge into every parsed position
* @returns {object[]} a list of prediction [position structures](https://docs.ccxt.com/#/?id=position-structure)
*/
fn parse_prediction_positions(&self, mut positions: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
// prediction-market analogue of the base parsePositions, which resolves its `symbols`
// argument through marketSymbols() and would throw BadSymbol on outcome handles.
// venue-specific outcome filtering stays in the exchange (position identity differs
// per venue: kalshi positions are market-level, polymarket ones are per token)
let mut rows: Value = self.to_array(positions.clone());
let mut results: Value = Value::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_210: bool = true;
while { if !__for_first_210 { i = add(&i, &Value::Int(1)); } __for_first_210 = false; is_less_than(&i, &get_array_length(&rows)) } {
let mut parsed: Value = <Self as crate::prediction_exchange_generated::PredictionBase>::parse_prediction_position(self, get_value(&rows, &i), &[]);
let mut position: Value = self.extend(parsed.clone(), &[params.clone()]);
append_to_array(&mut results, position.clone());
}
}
return results;
Value::Null
}
fn filter_by_outcome_since_limit(&self, mut array: Value, optional_args: &[Value]) -> Value {
let mut outcome = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut tail = get_arg(optional_args, 3, Value::Bool(false));
return self.filter_by_value_since_limit(array.clone(), Value::Str("outcome".to_string()), &[outcome.clone(), since.clone(), limit.clone(), Value::Str("timestamp".to_string()), tail.clone()]);
Value::Null
}
fn filter_by_outcomes_since_limit(&self, mut array: Value, optional_args: &[Value]) -> Value {
let mut outcomes = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut tail = get_arg(optional_args, 3, Value::Bool(false));
let mut result: Value = self.filter_by_array(array.clone(), Value::Str("outcome".to_string()), &[outcomes.clone(), Value::Bool(false)]);
return self.filter_by_since_limit(result.clone(), &[since.clone(), limit.clone(), Value::Str("timestamp".to_string()), tail.clone()]);
Value::Null
}
fn amount_to_prediction_precision(&self, mut outcome: Value, mut amount: Value) -> Value {
let mut outcomeObj: Value = self.outcome(outcome.clone());
let mut marketSymbol: Value = self.safe_string_k(outcomeObj.clone(), "market", &[]);
return self.amount_to_precision(marketSymbol.clone(), amount.clone());
Value::Null
}
fn price_to_prediction_precision(&self, mut outcome: Value, mut price: Value) -> Value {
let mut outcomeObj: Value = self.outcome(outcome.clone());
let mut marketSymbol: Value = self.safe_string_k(outcomeObj.clone(), "market", &[]);
return self.price_to_precision(marketSymbol.clone(), price.clone());
Value::Null
}
fn cost_to_prediction_precision(&self, mut outcome: Value, mut cost: Value) -> Value {
let mut outcomeObj: Value = self.outcome(outcome.clone());
let mut marketSymbol: Value = self.safe_string_k(outcomeObj.clone(), "market", &[]);
return self.cost_to_precision(marketSymbol.clone(), cost.clone());
Value::Null
}
// ------------------------------------------------------------------------
// shared EVM helpers — RLP encoding + a minimal JSON-RPC client + raw-tx
// broadcast, used by the on-chain (EOA) trading paths of EVM prediction
// venues (limitless, myriad). signEvmTransaction stays per-exchange because
// it needs the noble crypto imports (keccak/ecdsa/secp256k1) which the
// per-language prediction base skeletons don't carry; this base
// sendEvmTransaction dispatches to the exchange's signEvmTransaction override
fn pad_hex_to_even(&self, mut hex: Value) -> Value {
if is_equal(&hex, &Value::Null) {
return Value::Str("".to_string());
}
// prepend a nibble so the hex has an even number of characters (whole bytes)
let mut hexLength: Value = get_array_length(&hex);
if !is_equal(&(mod_val(&hexLength, &Value::Int(2))), &Value::Int(0)) {
return add(&Value::Str("0".to_string()), &hex);
}
return hex;
Value::Null
}
fn pad_hex_address(&self, mut address: Value) -> Value {
if is_equal(&address, &Value::Null) {
return Value::Str("".to_string());
}
// left-pads a 20-byte address to a 32-byte ABI word (24 leading zero bytes)
let mut stripped: Value = self.remove0x_prefix(address.clone());
return add(&Value::Str("000000000000000000000000".to_string()), &stripped);
Value::Null
}
fn rlp_encode_bytes(&self, mut hex: Value) -> Value {
if is_equal(&hex, &Value::Null) {
return Value::Str("".to_string());
}
// RLP-encodes a single byte string (hex without 0x) per the Ethereum RLP spec
let mut byteLength: Value = self.parse_to_int(divide(&get_array_length(&hex), &Value::Int(2)));
if is_equal(&byteLength, &Value::Int(0)) {
return Value::Str("80".to_string());
}
if is_true(&(is_equal(&byteLength, &Value::Int(1)))) && is_true(&(is_less_than(&hex, &Value::Str("80".to_string())))) {
return hex;
}
if is_less_than(&byteLength, &Value::Int(56)) {
return add(&self.int_to_base16(add(&Value::Int(128), &byteLength), &[]), &hex);
}
let mut lengthHex: Value = self.int_to_base16(byteLength.clone(), &[]);
lengthHex = self.pad_hex_to_even(lengthHex.clone());
let mut lengthOfLength: Value = self.parse_to_int(divide(&get_array_length(&lengthHex), &Value::Int(2)));
return add(&add(&self.int_to_base16(add(&Value::Int(183), &lengthOfLength), &[]), &lengthHex), &hex);
Value::Null
}
fn rlp_encode_list(&self, mut items: Value) -> Value {
let mut concatenated: Value = Value::Str("".to_string());
{
let mut i: Value = Value::Int(0);
let mut __for_first_211: bool = true;
while { if !__for_first_211 { i = add(&i, &Value::Int(1)); } __for_first_211 = false; is_less_than(&i, &get_array_length(&items)) } {
concatenated = add(&concatenated, &get_value(&items, &i));
}
}
let mut byteLength: Value = self.parse_to_int(divide(&get_array_length(&concatenated), &Value::Int(2)));
if is_less_than(&byteLength, &Value::Int(56)) {
return add(&self.int_to_base16(add(&Value::Int(192), &byteLength), &[]), &concatenated);
}
let mut lengthHex: Value = self.int_to_base16(byteLength.clone(), &[]);
lengthHex = self.pad_hex_to_even(lengthHex.clone());
let mut lengthOfLength: Value = self.parse_to_int(divide(&get_array_length(&lengthHex), &Value::Int(2)));
return add(&add(&self.int_to_base16(add(&Value::Int(247), &lengthOfLength), &[]), &lengthHex), &concatenated);
Value::Null
}
fn int_to_rlp_hex(&self, mut value: Value) -> Value {
if is_equal(&value, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" intToRlpHex() requires a value argument".to_string()))));
}
// an integer as its minimal big-endian byte hex; 0 is the empty byte string
if is_equal(&value, &Value::Int(0)) {
return Value::Str("".to_string());
}
let mut hex: Value = self.int_to_base16(value.clone(), &[]);
hex = self.pad_hex_to_even(hex.clone());
return hex;
Value::Null
}
fn hex_to_rlp_bytes(&self, mut hexValue: Value) -> Value {
// a hex value (e.g. an RPC result) as minimal big-endian byte hex; leading zero bytes
// are stripped and 0 becomes the empty byte string (RLP integer encoding)
if is_equal(&hexValue, &Value::Null) {
return Value::Str("".to_string());
}
let mut h: Value = self.remove0x_prefix(hexValue.clone());
let mut start: Value = Value::Int(0);
let mut total: Value = get_array_length(&h);
while is_true(&(is_less_than(&start, &total))) && is_true(&(is_equal(&slice(&h, &start, &add(&start, &Value::Int(1))), &Value::Str("0".to_string())))) {
start = add(&start, &Value::Int(1));
}
h = slice(&h, &start, &Value::Null);
if is_equal(&h, &Value::Str("".to_string())) {
return Value::Str("".to_string());
}
h = self.pad_hex_to_even(h.clone());
return h;
Value::Null
}
// eslint-disable-next-line no-unused-vars
fn sign_evm_transaction(&self, mut tx: Value, mut privateKey: Value) -> Value {
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" signEvmTransaction() must be overridden by the exchange".to_string()))));
Value::Null
}
fn eth_rpc(&mut self, mut rpcUrl: Value, mut method: Value, mut rpcParams: Value) -> impl ::std::future::Future<Output = Value> + Send { async move {
let mut payload: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("jsonrpc".to_string(), Value::Str("2.0".to_string()));
m.insert("id".to_string(), Value::Int(1));
m.insert("method".to_string(), method.clone());
m.insert("params".to_string(), rpcParams.clone());
m
});
let mut headers: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("Content-Type".to_string(), Value::Str("application/json".to_string()));
m
});
let __ws_arg_0 = self.json(payload.clone());
let mut response: Value = self.fetch(rpcUrl.clone(), &[Value::Str("POST".to_string()), headers.clone(), __ws_arg_0]).await;
let mut rpcError: Value = self.safe_value_k(response.clone(), "error", &[]);
if !is_equal(&rpcError, &Value::Null) {
panic!("{}", crate::exchange_errors::exchange_error(add(&add(&add(&add(&self.id, &Value::Str(" rpc ".to_string())), &method), &Value::Str(" error: ".to_string())), &self.json(rpcError.clone()))));
}
return self.safe_value_k(response.clone(), "result", &[]);
Value::Null
} }
fn send_evm_transaction(&mut self, mut rpcUrl: Value, mut chainId: Value, mut fromAddress: Value, mut to: Value, mut value: Value, mut data: Value, mut gasLimit: Value) -> impl ::std::future::Future<Output = Value> + Send { async move {
let mut nonce: Value = self.eth_rpc(rpcUrl.clone(), Value::Str("eth_getTransactionCount".to_string()), Value::List(vec![fromAddress.clone(), Value::Str("pending".to_string())])).await;
let mut gasPrice: Value = self.eth_rpc(rpcUrl.clone(), Value::Str("eth_gasPrice".to_string()), Value::List(vec![])).await;
let mut tx: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("chainId".to_string(), chainId.clone());
m.insert("nonce".to_string(), nonce.clone());
m.insert("maxPriorityFeePerGas".to_string(), gasPrice.clone());
m.insert("maxFeePerGas".to_string(), gasPrice.clone());
m.insert("gasLimit".to_string(), gasLimit.clone());
m.insert("to".to_string(), to.clone());
m.insert("value".to_string(), value.clone());
m.insert("data".to_string(), data.clone());
m
});
let mut signed: Value = self.sign_evm_transaction(tx.clone(), self.privateKey.clone());
return self.eth_rpc(rpcUrl.clone(), Value::Str("eth_sendRawTransaction".to_string()), Value::List(vec![signed.clone()])).await;
Value::Null
} }
fn wait_for_transaction_receipt(&mut self, mut rpcUrl: Value, mut txHash: Value, optional_args: &[Value]) -> impl ::std::future::Future<Output = Value> + Send { async move {
let mut timeout = get_arg(optional_args, 0, Value::Int(60000));
let mut start: Value = self.milliseconds();
while is_less_than(&(subtract(&self.milliseconds(), &start)), &timeout) {
let mut receipt: Value = self.eth_rpc(rpcUrl.clone(), Value::Str("eth_getTransactionReceipt".to_string()), Value::List(vec![txHash.clone()])).await;
if is_true(&(!is_equal(&receipt, &Value::Null))) && is_true(&(!is_equal(&receipt, &Value::Null))) {
return receipt;
}
self.sleep(Value::Int(2000)).await;
}
panic!("{}", crate::exchange_errors::exchange_error(add(&add(&add(&self.id, &Value::Str(" transaction ".to_string())), &txHash), &Value::Str(" not mined within timeout".to_string()))));
Value::Null
} }
/// Prediction-base fall-through for a prediction Core's `call_dynamic`.
fn call_dynamic_prediction_base<'a>(&'a mut self, method: &'a str, args: Vec<crate::Value>)
-> std::pin::Pin<Box<dyn std::future::Future<Output = crate::Value> + Send + 'a>>
{
Box::pin(async move {
match method {
"amount_to_prediction_precision" => <Self as crate::prediction_exchange_generated::PredictionBase>::amount_to_prediction_precision(self, args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)),
"apply_event_fetch_params" => <Self as crate::prediction_exchange_generated::PredictionBase>::apply_event_fetch_params(self, args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"cancel_order" => <Self as crate::prediction_exchange_generated::PredictionBase>::cancel_order(self, args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"cancel_orders" => <Self as crate::prediction_exchange_generated::PredictionBase>::cancel_orders(self, args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"cost_to_prediction_precision" => <Self as crate::prediction_exchange_generated::PredictionBase>::cost_to_prediction_precision(self, args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)),
"create_market_buy_order_with_cost" => <Self as crate::prediction_exchange_generated::PredictionBase>::create_market_buy_order_with_cost(self, args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), &args.get(2..).unwrap_or(&[]).to_vec()[..]).await,
"create_market_sell_order_with_cost" => <Self as crate::prediction_exchange_generated::PredictionBase>::create_market_sell_order_with_cost(self, args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), &args.get(2..).unwrap_or(&[]).to_vec()[..]).await,
"create_order" => <Self as crate::prediction_exchange_generated::PredictionBase>::create_order(self, args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), args.get(3).cloned().unwrap_or(crate::Value::Null), &args.get(4..).unwrap_or(&[]).to_vec()[..]).await,
"create_orders" => <Self as crate::prediction_exchange_generated::PredictionBase>::create_orders(self, args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"eth_rpc" => <Self as crate::prediction_exchange_generated::PredictionBase>::eth_rpc(self, args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null)).await,
"events_list" => <Self as crate::prediction_exchange_generated::PredictionBase>::events_list(self),
"fetch_closed_orders" => <Self as crate::prediction_exchange_generated::PredictionBase>::fetch_closed_orders(self, &args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_event" => <Self as crate::prediction_exchange_generated::PredictionBase>::fetch_event(self, args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_events" => <Self as crate::prediction_exchange_generated::PredictionBase>::fetch_events(self, &args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_my_trades" => <Self as crate::prediction_exchange_generated::PredictionBase>::fetch_my_trades(self, &args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_ohlcv" => <Self as crate::prediction_exchange_generated::PredictionBase>::fetch_ohlcv(self, args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_open_interest" => <Self as crate::prediction_exchange_generated::PredictionBase>::fetch_open_interest(self, args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_open_orders" => <Self as crate::prediction_exchange_generated::PredictionBase>::fetch_open_orders(self, &args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_order_book" => <Self as crate::prediction_exchange_generated::PredictionBase>::fetch_order_book(self, args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_order_trades" => <Self as crate::prediction_exchange_generated::PredictionBase>::fetch_order_trades(self, args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_orders" => <Self as crate::prediction_exchange_generated::PredictionBase>::fetch_orders(self, &args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_outcome" => <Self as crate::prediction_exchange_generated::PredictionBase>::fetch_outcome(self, args.get(0).cloned().unwrap_or(crate::Value::Null)).await,
"fetch_outcomes" => <Self as crate::prediction_exchange_generated::PredictionBase>::fetch_outcomes(self, args.get(0).cloned().unwrap_or(crate::Value::Null)).await,
"fetch_position" => <Self as crate::prediction_exchange_generated::PredictionBase>::fetch_position(self, args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_positions" => <Self as crate::prediction_exchange_generated::PredictionBase>::fetch_positions(self, &args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_settlements" => <Self as crate::prediction_exchange_generated::PredictionBase>::fetch_settlements(self, &args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_ticker" => <Self as crate::prediction_exchange_generated::PredictionBase>::fetch_ticker(self, args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_tickers" => <Self as crate::prediction_exchange_generated::PredictionBase>::fetch_tickers(self, &args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_trades" => <Self as crate::prediction_exchange_generated::PredictionBase>::fetch_trades(self, args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_trading_fee" => <Self as crate::prediction_exchange_generated::PredictionBase>::fetch_trading_fee(self, args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"filter_by_outcome_since_limit" => <Self as crate::prediction_exchange_generated::PredictionBase>::filter_by_outcome_since_limit(self, args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"filter_by_outcomes_since_limit" => <Self as crate::prediction_exchange_generated::PredictionBase>::filter_by_outcomes_since_limit(self, args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"filter_events_by_search_in" => <Self as crate::prediction_exchange_generated::PredictionBase>::filter_events_by_search_in(self, args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), &args.get(2..).unwrap_or(&[]).to_vec()[..]),
"filter_events_by_status" => <Self as crate::prediction_exchange_generated::PredictionBase>::filter_events_by_status(self, args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"filter_events_by_tags" => <Self as crate::prediction_exchange_generated::PredictionBase>::filter_events_by_tags(self, args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"get_event" => <Self as crate::prediction_exchange_generated::PredictionBase>::get_event(self, args.get(0).cloned().unwrap_or(crate::Value::Null)),
"has_outcome" => <Self as crate::prediction_exchange_generated::PredictionBase>::has_outcome(self, args.get(0).cloned().unwrap_or(crate::Value::Null)),
"hex_to_rlp_bytes" => <Self as crate::prediction_exchange_generated::PredictionBase>::hex_to_rlp_bytes(self, args.get(0).cloned().unwrap_or(crate::Value::Null)),
"int_to_rlp_hex" => <Self as crate::prediction_exchange_generated::PredictionBase>::int_to_rlp_hex(self, args.get(0).cloned().unwrap_or(crate::Value::Null)),
"is_prediction" => <Self as crate::prediction_exchange_generated::PredictionBase>::is_prediction(self),
"load_events" => <Self as crate::prediction_exchange_generated::PredictionBase>::load_events(self, &args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"load_events_helper" => <Self as crate::prediction_exchange_generated::PredictionBase>::load_events_helper(self, &args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"load_outcome" => <Self as crate::prediction_exchange_generated::PredictionBase>::load_outcome(self, args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"normalize_tag_key" => <Self as crate::prediction_exchange_generated::PredictionBase>::normalize_tag_key(self, args.get(0).cloned().unwrap_or(crate::Value::Null)),
"outcome" => <Self as crate::prediction_exchange_generated::PredictionBase>::outcome(self, args.get(0).cloned().unwrap_or(crate::Value::Null)),
"outcome_search_query" => <Self as crate::prediction_exchange_generated::PredictionBase>::outcome_search_query(self, args.get(0).cloned().unwrap_or(crate::Value::Null)),
"pad_hex_address" => <Self as crate::prediction_exchange_generated::PredictionBase>::pad_hex_address(self, args.get(0).cloned().unwrap_or(crate::Value::Null)),
"pad_hex_to_even" => <Self as crate::prediction_exchange_generated::PredictionBase>::pad_hex_to_even(self, args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_prediction_open_interest" => <Self as crate::prediction_exchange_generated::PredictionBase>::parse_prediction_open_interest(self, args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_prediction_order" => <Self as crate::prediction_exchange_generated::PredictionBase>::parse_prediction_order(self, args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_prediction_orders" => <Self as crate::prediction_exchange_generated::PredictionBase>::parse_prediction_orders(self, args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_prediction_position" => <Self as crate::prediction_exchange_generated::PredictionBase>::parse_prediction_position(self, args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_prediction_positions" => <Self as crate::prediction_exchange_generated::PredictionBase>::parse_prediction_positions(self, args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_prediction_ticker" => <Self as crate::prediction_exchange_generated::PredictionBase>::parse_prediction_ticker(self, args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_prediction_trade" => <Self as crate::prediction_exchange_generated::PredictionBase>::parse_prediction_trade(self, args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_prediction_trades" => <Self as crate::prediction_exchange_generated::PredictionBase>::parse_prediction_trades(self, args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_search_queries" => <Self as crate::prediction_exchange_generated::PredictionBase>::parse_search_queries(self, &args.get(0..).unwrap_or(&[]).to_vec()[..]),
"price_to_prediction_precision" => <Self as crate::prediction_exchange_generated::PredictionBase>::price_to_prediction_precision(self, args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)),
"require_event_query" => <Self as crate::prediction_exchange_generated::PredictionBase>::require_event_query(self, &args.get(0..).unwrap_or(&[]).to_vec()[..]),
"rlp_encode_bytes" => <Self as crate::prediction_exchange_generated::PredictionBase>::rlp_encode_bytes(self, args.get(0).cloned().unwrap_or(crate::Value::Null)),
"rlp_encode_list" => <Self as crate::prediction_exchange_generated::PredictionBase>::rlp_encode_list(self, args.get(0).cloned().unwrap_or(crate::Value::Null)),
"safe_outcome" => <Self as crate::prediction_exchange_generated::PredictionBase>::safe_outcome(self, args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"safe_outcome_symbol" => <Self as crate::prediction_exchange_generated::PredictionBase>::safe_outcome_symbol(self, args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"safe_prediction_order" => <Self as crate::prediction_exchange_generated::PredictionBase>::safe_prediction_order(self, args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"safe_prediction_order_book" => <Self as crate::prediction_exchange_generated::PredictionBase>::safe_prediction_order_book(self, args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"safe_prediction_position" => <Self as crate::prediction_exchange_generated::PredictionBase>::safe_prediction_position(self, args.get(0).cloned().unwrap_or(crate::Value::Null)),
"safe_prediction_ticker" => <Self as crate::prediction_exchange_generated::PredictionBase>::safe_prediction_ticker(self, args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"safe_prediction_trade" => <Self as crate::prediction_exchange_generated::PredictionBase>::safe_prediction_trade(self, args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"send_evm_transaction" => <Self as crate::prediction_exchange_generated::PredictionBase>::send_evm_transaction(self, args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), args.get(3).cloned().unwrap_or(crate::Value::Null), args.get(4).cloned().unwrap_or(crate::Value::Null), args.get(5).cloned().unwrap_or(crate::Value::Null), args.get(6).cloned().unwrap_or(crate::Value::Null)).await,
"set_events" => <Self as crate::prediction_exchange_generated::PredictionBase>::set_events(self, args.get(0).cloned().unwrap_or(crate::Value::Null)),
"set_markets" => <Self as crate::prediction_exchange_generated::PredictionBase>::set_markets(self, args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"shorten_slug" => <Self as crate::prediction_exchange_generated::PredictionBase>::shorten_slug(self, args.get(0).cloned().unwrap_or(crate::Value::Null)),
"sign_evm_transaction" => <Self as crate::prediction_exchange_generated::PredictionBase>::sign_evm_transaction(self, args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)),
"slug_to_market_symbol" => <Self as crate::prediction_exchange_generated::PredictionBase>::slug_to_market_symbol(self, args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)),
"slug_to_outcome_symbol" => <Self as crate::prediction_exchange_generated::PredictionBase>::slug_to_outcome_symbol(self, args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null)),
"wait_for_transaction_receipt" => <Self as crate::prediction_exchange_generated::PredictionBase>::wait_for_transaction_receipt(self, args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), &args.get(2..).unwrap_or(&[]).to_vec()[..]).await,
"watch_my_trades" => <Self as crate::prediction_exchange_generated::PredictionBase>::watch_my_trades(self, &args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"watch_order_book" => <Self as crate::prediction_exchange_generated::PredictionBase>::watch_order_book(self, args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"watch_orders" => <Self as crate::prediction_exchange_generated::PredictionBase>::watch_orders(self, &args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"watch_positions" => <Self as crate::prediction_exchange_generated::PredictionBase>::watch_positions(self, &args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"watch_ticker" => <Self as crate::prediction_exchange_generated::PredictionBase>::watch_ticker(self, args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"watch_tickers" => <Self as crate::prediction_exchange_generated::PredictionBase>::watch_tickers(self, &args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"watch_trades" => <Self as crate::prediction_exchange_generated::PredictionBase>::watch_trades(self, args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
_ => self.call_dynamic_base(method, args).await,
}
})
}
}