// 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
#![allow(unused, non_snake_case, clippy::all)]
use crate::Value;
use crate::get_value;
use crate::runtime::*;
// Base methods are now trait methods (review #1: static dispatch). Bring the
// traits into scope so `self.market(...)`, `self.safe_market(...)`,
// `self.load_markets(...)`, … on this Core resolve to the base defaults.
use crate::exchange_generated::ExchangeBase;
use crate::exchange::ExchangeRuntime;
// Dynamic `this[method](...)` re-entries are emitted as
// `self.call_dynamic_checked(...)` (blanket-impl'd on every Core) so an
// unresolvable name raises NotSupported instead of yielding a silent Null.
use crate::exchange::CallDynamicChecked;
pub struct GrvtCore {
pub exchange: crate::exchange::Exchange,
}
impl GrvtCore {
pub fn new(config: Option<crate::Value>) -> Self {
let mut s = Self { exchange: crate::exchange::Exchange::new(config) };
s.init();
s
}
pub fn init(&mut self) {
let described = GrvtCore::describe(self);
self.initialize_properties(described);
// compatibility for sandbox/testnet options in userConfig
let user_config = self.userConfig.clone();
<Self as crate::exchange_generated::ExchangeBase>::after_construct(self, &[user_config]);
}
/// Compatibility no-op. The old pointer-based dispatch needed a post-move
/// `bind()`; static trait dispatch (review #1) needs no binding, so this
/// just exists so callers that still call it keep compiling.
#[inline]
pub fn bind(&mut self) {}
}
impl crate::exchange::DerivedExchange for GrvtCore {
fn parse_ticker(&self, ticker: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on GrvtCore.
GrvtCore::parse_ticker(self, ticker, &[market])
}
fn parse_trade(&self, trade: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on GrvtCore.
GrvtCore::parse_trade(self, trade, &[market])
}
fn parse_order(&self, order: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on GrvtCore.
GrvtCore::parse_order(self, order, &[market])
}
fn parse_market(&self, market: crate::Value) -> crate::Value {
// Forward to the inherent method on GrvtCore.
GrvtCore::parse_market(self, market)
}
fn parse_ohlcv(&self, ohlcv: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on GrvtCore.
GrvtCore::parse_ohlcv(self, ohlcv, &[market])
}
fn parse_balance(&self, response: crate::Value) -> crate::Value {
// Forward to the inherent method on GrvtCore.
GrvtCore::parse_balance(self, response)
}
fn parse_position(&self, position: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on GrvtCore.
GrvtCore::parse_position(self, position, &[market])
}
fn parse_transfer(&self, transfer: crate::Value, currency: crate::Value) -> crate::Value {
// Forward to the inherent method on GrvtCore.
GrvtCore::parse_transfer(self, transfer, &[currency])
}
fn parse_currency(&self, currency: crate::Value) -> crate::Value {
// Forward to the inherent method on GrvtCore.
GrvtCore::parse_currency(self, currency)
}
fn parse_funding_rate_history(&self, entry: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on GrvtCore.
GrvtCore::parse_funding_rate_history(self, entry, &[market])
}
fn parse_transaction(&self, transaction: crate::Value, currency: crate::Value) -> crate::Value {
// Forward to the inherent method on GrvtCore.
GrvtCore::parse_transaction(self, transaction, &[currency])
}
fn parse_income(&self, info: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on GrvtCore.
GrvtCore::parse_income(self, info, &[market])
}
fn parse_margin_mode(&self, margin_mode: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on GrvtCore.
GrvtCore::parse_margin_mode(self, margin_mode, &[market])
}
fn parse_leverage(&self, leverage: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on GrvtCore.
GrvtCore::parse_leverage(self, leverage, &[market])
}
fn sign(&self, path: crate::Value, api: crate::Value, method: crate::Value, params: crate::Value, headers: crate::Value, body: crate::Value) -> crate::Value {
// Forward to the inherent method on GrvtCore.
GrvtCore::sign(self, path, &[api, method, params, headers, body])
}
fn handle_errors(&self, code: crate::Value, reason: crate::Value, url: crate::Value, method: crate::Value, headers: crate::Value, body: crate::Value, response: crate::Value, request_headers: crate::Value, request_body: crate::Value) -> crate::Value {
// Forward to the inherent method on GrvtCore.
GrvtCore::handle_errors(self, code, reason, url, method, headers, body, response, request_headers, request_body)
}
}
impl crate::exchange_generated::ExchangeBase for GrvtCore {
fn call_dynamic<'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 {
"cancel_all_orders" => self.cancel_all_orders(&args[..]).await,
"cancel_order" => self.cancel_order(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"convert_to_big_int_custom" => self.convert_to_big_int_custom(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"create_order" => self.create_order(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[4.min(args.len())..]).await,
"create_signed_request" => self.create_signed_request(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), &args[2.min(args.len())..]),
"default_signature" => self.default_signature(),
"eip_definitions" => self.eip_definitions(),
"eip_domain_data" => self.eip_domain_data(),
"eip_message_for_order" => self.eip_message_for_order(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)),
"fee_amount_multiplier" => self.fee_amount_multiplier(),
"fetch_balance" => self.fetch_balance(&args[..]).await,
"fetch_currencies" => self.fetch_currencies(&args[..]).await,
"fetch_deposits" => self.fetch_deposits(&args[..]).await,
"fetch_funding_history" => self.fetch_funding_history(&args[..]).await,
"fetch_funding_rate_history" => self.fetch_funding_rate_history(&args[..]).await,
"fetch_leverages" => self.fetch_leverages(&args[..]).await,
"fetch_margin_modes" => self.fetch_margin_modes(&args[..]).await,
"fetch_markets" => self.fetch_markets(&args[..]).await,
"fetch_my_trades" => self.fetch_my_trades(&args[..]).await,
"fetch_ohlcv" => self.fetch_ohlcv(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_open_orders" => self.fetch_open_orders(&args[..]).await,
"fetch_order" => self.fetch_order(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_order_book" => self.fetch_order_book(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_orders" => self.fetch_orders(&args[..]).await,
"fetch_positions" => self.fetch_positions(&args[..]).await,
"fetch_ticker" => self.fetch_ticker(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_trades" => self.fetch_trades(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_transfers" => self.fetch_transfers(&args[..]).await,
"fetch_withdrawals" => self.fetch_withdrawals(&args[..]).await,
"filter_transfers_by_type" => self.filter_transfers_by_type(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), &args[2.min(args.len())..]),
"format_signature_rs" => self.format_signature_rs(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"get_sub_account_id" => self.get_sub_account_id(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"handle_errors" => self.handle_errors(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), args.get(7).cloned().unwrap_or(crate::Value::Null), args.get(8).cloned().unwrap_or(crate::Value::Null)),
"handle_until_option_string" => self.handle_until_option_string(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), &args[2.min(args.len())..]),
"initialize_client" => self.initialize_client(&args[..]).await,
"internal_fetch_transfers" => self.internal_fetch_transfers(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"load_account_infos" => self.load_account_infos().await,
"parse_balance" => self.parse_balance(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_currency" => self.parse_currency(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_funding_rate_history" => self.parse_funding_rate_history(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_income" => self.parse_income(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_leverage" => self.parse_leverage(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_margin_mode" => self.parse_margin_mode(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_market" => self.parse_market(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_ohlcv" => self.parse_ohlcv(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_order" => self.parse_order(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_order_status" => self.parse_order_status(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_position" => self.parse_position(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_ticker" => self.parse_ticker(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_trade" => self.parse_trade(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_transaction" => self.parse_transaction(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_transfer" => self.parse_transfer(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"request_id" => self.request_id(),
"set_leverage" => self.set_leverage(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"sign" => self.sign(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"sign_in" => self.sign_in(&args[..]).await,
"sign_in_with_api_key" => self.sign_in_with_api_key(&args[..]).await,
"sign_in_with_private_key" => self.sign_in_with_private_key(&args[..]).await,
"time_in_force_to_int" => self.time_in_force_to_int(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"transfer" => self.transfer(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[4.min(args.len())..]).await,
"uses_private_key" => self.uses_private_key(),
"withdraw" => self.withdraw(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[3.min(args.len())..]).await,
// Fall through to the base-only methods (cancelOrderWithClientOrderId, …).
_ => self.call_dynamic_base(method, args).await,
}
})
}
}
impl std::ops::Deref for GrvtCore {
type Target = crate::exchange::Exchange;
fn deref(&self) -> &crate::exchange::Exchange { &self.exchange }
}
impl std::ops::DerefMut for GrvtCore {
fn deref_mut(&mut self) -> &mut crate::exchange::Exchange { &mut self.exchange }
}
impl GrvtCore {
pub fn describe(&self) -> Value {
let mut rlOthers: Value = Value::Int(40);
let mut rlOrders: Value = Value::Int(20);
return self.deep_extend(self.super_describe(), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), Value::Str("grvt".into()));
m.insert("name".to_string(), Value::Str("GRVT".into()));
m.insert("countries".to_string(), Value::from(vec![Value::Str("SG".into())]));
m.insert("rateLimit".to_string(), Value::Int(10));
m.insert("certified".to_string(), Value::Bool(false));
m.insert("version".to_string(), Value::Str("v1".into()));
m.insert("dex".to_string(), Value::Bool(true));
m.insert("pro".to_string(), Value::Bool(true));
m.insert("has".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("CORS".to_string(), Value::Null);
m.insert("spot".to_string(), Value::Bool(false));
m.insert("margin".to_string(), Value::Bool(false));
m.insert("swap".to_string(), Value::Bool(true));
m.insert("future".to_string(), Value::Bool(false));
m.insert("option".to_string(), Value::Bool(false));
m.insert("cancelAllOrders".to_string(), Value::Bool(true));
m.insert("cancelOrder".to_string(), Value::Bool(true));
m.insert("createOrder".to_string(), Value::Bool(true));
m.insert("fetchBalance".to_string(), Value::Bool(true));
m.insert("fetchCurrencies".to_string(), Value::Bool(true));
m.insert("fetchDeposits".to_string(), Value::Bool(true));
m.insert("fetchFundingHistory".to_string(), Value::Bool(true));
m.insert("fetchFundingRateHistory".to_string(), Value::Bool(true));
m.insert("fetchLeverages".to_string(), Value::Bool(true));
m.insert("fetchMarginModes".to_string(), Value::Bool(true));
m.insert("fetchMarkets".to_string(), Value::Bool(true));
m.insert("fetchMyTrades".to_string(), Value::Bool(true));
m.insert("fetchOHLCV".to_string(), Value::Bool(true));
m.insert("fetchOpenOrders".to_string(), Value::Bool(true));
m.insert("fetchOrder".to_string(), Value::Bool(true));
m.insert("fetchOrderBook".to_string(), Value::Bool(true));
m.insert("fetchOrders".to_string(), Value::Bool(true));
m.insert("fetchPositions".to_string(), Value::Bool(true));
m.insert("fetchTicker".to_string(), Value::Bool(true));
m.insert("fetchTrades".to_string(), Value::Bool(true));
m.insert("fetchTransfers".to_string(), Value::Bool(true));
m.insert("fetchWithdrawals".to_string(), Value::Bool(true));
m.insert("setLeverage".to_string(), Value::Bool(true));
m.insert("signIn".to_string(), Value::Bool(true));
m.insert("transfer".to_string(), Value::Bool(true));
m.insert("withdraw".to_string(), Value::Bool(true));
m
}));
m.insert("timeframes".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("1m".to_string(), Value::Str("CI_1_M".into()));
m.insert("3m".to_string(), Value::Str("CI_3_M".into()));
m.insert("5m".to_string(), Value::Str("CI_5_M".into()));
m.insert("15m".to_string(), Value::Str("CI_15_M".into()));
m.insert("30m".to_string(), Value::Str("CI_30_M".into()));
m.insert("1h".to_string(), Value::Str("CI_1_H".into()));
m.insert("2h".to_string(), Value::Str("CI_2_H".into()));
m.insert("4h".to_string(), Value::Str("CI_4_H".into()));
m.insert("6h".to_string(), Value::Str("CI_6_H".into()));
m.insert("8h".to_string(), Value::Str("CI_8_H".into()));
m.insert("12h".to_string(), Value::Str("CI_12_H".into()));
m.insert("1d".to_string(), Value::Str("CI_1_D".into()));
m.insert("3d".to_string(), Value::Str("CI_3_D".into()));
m.insert("5d".to_string(), Value::Str("CI_5_D".into()));
m.insert("1w".to_string(), Value::Str("CI_1_W".into()));
m.insert("2w".to_string(), Value::Str("CI_2_W".into()));
m.insert("3w".to_string(), Value::Str("CI_3_W".into()));
m.insert("4w".to_string(), Value::Str("CI_4_W".into()));
m
}));
m.insert("urls".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("logo".to_string(), Value::Str("https://github.com/user-attachments/assets/cff0d37c-e594-40cb-88b3-90650ddadc18".into()));
m.insert("api".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("privateEdge".to_string(), Value::Str("https://edge.grvt.io/".into()));
m.insert("privateTrading".to_string(), Value::Str("https://trades.grvt.io/".into()));
m.insert("publicMarket".to_string(), Value::Str("https://market-data.grvt.io/".into()));
m
}));
m.insert("test".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("privateEdge".to_string(), Value::Str("https://edge.testnet.grvt.io/".into()));
m.insert("privateTrading".to_string(), Value::Str("https://trades.testnet.grvt.io/".into()));
m.insert("publicMarket".to_string(), Value::Str("https://market-data.testnet.grvt.io/".into()));
m
}));
m.insert("www".to_string(), Value::Str("https://grvt.io".into()));
m.insert("referral".to_string(), Value::Str("https://grvt.io/?ref=WBLS9D1".into()));
m.insert("doc".to_string(), Value::from(vec![Value::Str("https://api-docs.grvt.io/".into())]));
m.insert("fees".to_string(), Value::Str("https://help.grvt.io/en/articles/9614699-how-does-grvt-s-fee-model-work".into()));
m
}));
m.insert("api".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("privateEdge".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("get".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("api/v1/deposit/addresses".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), rlOthers.clone());
m
}));
m.insert("api/v1/bridge/withdrawal-info".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), rlOthers.clone());
m
}));
m.insert("api/v1/bridge/withdrawal-status".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), rlOthers.clone());
m
}));
m.insert("api/v1/referral/epochs".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), rlOthers.clone());
m
}));
m.insert("api/v1/referral/points".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), rlOthers.clone());
m
}));
m.insert("api/v1/referral/data".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), rlOthers.clone());
m
}));
m.insert("api/v1/referral/indirect_data".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), rlOthers.clone());
m
}));
m
}));
m.insert("post".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("auth/api_key/login".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(100));
m
}));
m.insert("auth/wallet/login".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(100));
m
}));
m.insert("auth/builder/authorize".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(100));
m
}));
m.insert("api/v1/deposit/generate-address".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(100));
m
}));
m.insert("api/v1/bridge/withdrawal-quote".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(100));
m
}));
m.insert("api/v1/bridge/withdraw".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(100));
m
}));
m
}));
m
}));
m.insert("publicMarket".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("post".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("full/v1/instrument".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("full/v1/all_instruments".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("full/v1/instruments".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("full/v1/currency".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(12));
m
}));
m.insert("full/v1/margin_rules".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(12));
m
}));
m.insert("full/v1/mini".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("full/v1/ticker".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("full/v1/book".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(12));
m
}));
m.insert("full/v1/trade".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(12));
m
}));
m.insert("full/v1/trade_history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(12));
m
}));
m.insert("full/v1/kline".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(12));
m
}));
m.insert("full/v1/funding".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(12));
m
}));
m.insert("full/v1/supported_assets".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(12));
m
}));
m.insert("full/v1/get_all_collateral_asset_info".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(12));
m
}));
m
}));
m
}));
m.insert("privateTrading".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("post".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("full/v1/create_order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("full/v1/cancel_order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("full/v1/cancel_on_disconnect".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(100));
m
}));
m.insert("full/v1/cancel_all_orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(50));
m
}));
m.insert("full/v1/order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), rlOrders.clone());
m
}));
m.insert("full/v1/order_history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), rlOrders.clone());
m
}));
m.insert("full/v1/open_orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), rlOrders.clone());
m
}));
m.insert("full/v1/fill_history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), rlOrders.clone());
m
}));
m.insert("full/v1/positions".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), rlOrders.clone());
m
}));
m.insert("full/v1/funding_payment_history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), rlOthers.clone());
m
}));
m.insert("full/v1/get_sub_accounts".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), rlOthers.clone());
m
}));
m.insert("full/v1/account_summary".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), rlOthers.clone());
m
}));
m.insert("full/v1/account_history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), rlOthers.clone());
m
}));
m.insert("full/v1/aggregated_account_summary".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), rlOthers.clone());
m
}));
m.insert("full/v1/funding_account_summary".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), rlOthers.clone());
m
}));
m.insert("full/v1/transfer".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(100));
m
}));
m.insert("full/v1/deposit_history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(100));
m
}));
m.insert("full/v1/transfer_history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(100));
m
}));
m.insert("full/v1/withdrawal".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(100));
m
}));
m.insert("full/v1/withdrawal_history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(100));
m
}));
m.insert("full/v1/add_position_margin".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), rlOthers.clone());
m
}));
m.insert("full/v1/get_position_margin_limits".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), rlOthers.clone());
m
}));
m.insert("full/v1/set_position_config".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), rlOthers.clone());
m
}));
m.insert("full/v1/set_initial_leverage".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), rlOthers.clone());
m
}));
m.insert("full/v1/get_all_initial_leverage".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), rlOthers.clone());
m
}));
m.insert("full/v1/set_derisk_mm_ratio".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), rlOthers.clone());
m
}));
m.insert("full/v1/vault_burn_tokens".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), rlOthers.clone());
m
}));
m.insert("full/v1/vault_invest".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), rlOthers.clone());
m
}));
m.insert("full/v1/vault_investor_summary".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), rlOthers.clone());
m
}));
m.insert("full/v1/vault_redeem".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), rlOthers.clone());
m
}));
m.insert("full/v1/vault_redeem_cancel".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), rlOthers.clone());
m
}));
m.insert("full/v1/vault_view_redemption_queue".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), rlOthers.clone());
m
}));
m.insert("full/v1/vault_manager_investor_history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), rlOthers.clone());
m
}));
m.insert("full/v1/authorize_builder".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), rlOthers.clone());
m
}));
m.insert("full/v1/get_authorized_builders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), rlOthers.clone());
m
}));
m.insert("full/v1/builder_fill_history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), rlOthers.clone());
m
}));
m.insert("full/v1/create_rfq".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("full/v1/cancel_rfq".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("full/v1/ecn_from_broker".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), rlOthers.clone());
m
}));
m.insert("full/v2/bulk_orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(50));
m
}));
m.insert("full/v1/position_history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), rlOrders);
m
}));
m.insert("full/v1/interest_payment_history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), rlOthers.clone());
m
}));
m.insert("full/v1/get_collateral_preference".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), rlOthers.clone());
m
}));
m.insert("full/v1/spot_account_summary".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), rlOthers.clone());
m
}));
m.insert("full/v1/set_indicative_prices".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), rlOthers);
m
}));
m.insert("full/v1/withdrawal_fee".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(100));
m
}));
m
}));
m
}));
m
}));
m.insert("options".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("accountId".to_string(), Value::Null);
m.insert("networks".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("ARBITRUM".to_string(), Value::Str("42161".into()));
m.insert("AVAXC".to_string(), Value::Str("43114".into()));
m.insert("BASE".to_string(), Value::Str("8453".into()));
m.insert("BEP20".to_string(), Value::Str("56".into()));
m.insert("ERC20".to_string(), Value::Str("1".into()));
m.insert("OP".to_string(), Value::Str("10".into()));
m.insert("SOL".to_string(), Value::Str("900".into()));
m.insert("TRC20".to_string(), Value::Str("728126428".into()));
m.insert("ZKSYNCERA".to_string(), Value::Str("324".into()));
m.insert("KAIA".to_string(), Value::Str("8217".into()));
m
}));
m.insert("networksById".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("1".to_string(), Value::Str("ERC20".into()));
m
}));
m.insert("builderFee".to_string(), Value::Bool(true));
m.insert("builder".to_string(), Value::Str("0x21d2a053495994b1132a38cd1171acec40c6741e".into()));
m.insert("builderRate".to_string(), Value::Float(0.01));
m
}));
m.insert("precisionMode".to_string(), Value::Int(crate::runtime::TICK_SIZE));
m.insert("features".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("default".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("sandbox".to_string(), Value::Bool(true));
m.insert("createOrder".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("marginMode".to_string(), Value::Bool(false));
m.insert("triggerPrice".to_string(), Value::Bool(true));
m.insert("triggerPriceType".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("last".to_string(), Value::Bool(true));
m.insert("mark".to_string(), Value::Bool(true));
m.insert("index".to_string(), Value::Bool(true));
m.insert("median".to_string(), Value::Bool(true));
m
}));
m.insert("triggerDirection".to_string(), Value::Bool(true));
m.insert("stopLossPrice".to_string(), Value::Bool(true));
m.insert("takeProfitPrice".to_string(), Value::Bool(true));
m.insert("attachedStopLossTakeProfit".to_string(), Value::Null);
m.insert("timeInForce".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("IOC".to_string(), Value::Bool(true));
m.insert("FOK".to_string(), Value::Bool(true));
m.insert("PO".to_string(), Value::Bool(true));
m.insert("GTD".to_string(), Value::Bool(false));
m
}));
m.insert("hedged".to_string(), Value::Bool(false));
m.insert("leverage".to_string(), Value::Bool(false));
m.insert("marketBuyRequiresPrice".to_string(), Value::Bool(false));
m.insert("marketBuyByCost".to_string(), Value::Bool(false));
m.insert("selfTradePrevention".to_string(), Value::Bool(false));
m.insert("trailing".to_string(), Value::Bool(false));
m.insert("iceberg".to_string(), Value::Bool(false));
m
}));
m.insert("createOrders".to_string(), Value::Null);
m.insert("fetchMyTrades".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("marginMode".to_string(), Value::Bool(false));
m.insert("limit".to_string(), Value::Int(1000));
m.insert("daysBack".to_string(), Value::Int(1000));
m.insert("untilDays".to_string(), Value::Int(1000));
m.insert("symbolRequired".to_string(), Value::Bool(false));
m
}));
m.insert("fetchOrder".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("marginMode".to_string(), Value::Bool(false));
m.insert("trigger".to_string(), Value::Bool(false));
m.insert("trailing".to_string(), Value::Bool(false));
m.insert("symbolRequired".to_string(), Value::Bool(false));
m
}));
m.insert("fetchOpenOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("marginMode".to_string(), Value::Bool(false));
m.insert("limit".to_string(), Value::Null);
m.insert("trigger".to_string(), Value::Bool(false));
m.insert("trailing".to_string(), Value::Bool(false));
m.insert("symbolRequired".to_string(), Value::Bool(false));
m
}));
m.insert("fetchOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("marginMode".to_string(), Value::Bool(false));
m.insert("limit".to_string(), Value::Int(1000));
m.insert("daysBack".to_string(), Value::Null);
m.insert("untilDays".to_string(), Value::Null);
m.insert("trigger".to_string(), Value::Bool(false));
m.insert("trailing".to_string(), Value::Bool(false));
m.insert("symbolRequired".to_string(), Value::Bool(false));
m
}));
m.insert("fetchClosedOrders".to_string(), Value::Null);
m.insert("fetchOHLCV".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("limit".to_string(), Value::Int(1000));
m
}));
m
}));
m.insert("spot".to_string(), Value::Null);
m.insert("swap".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("linear".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("extends".to_string(), Value::Str("default".into()));
m
}));
m.insert("inverse".to_string(), Value::Null);
m
}));
m.insert("future".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("linear".to_string(), Value::Null);
m.insert("inverse".to_string(), Value::Null);
m
}));
m
}));
m.insert("requiredCredentials".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("privateKey".to_string(), Value::Bool(true));
m.insert("apiKey".to_string(), Value::Bool(false));
m.insert("secret".to_string(), Value::Bool(false));
m
}));
m.insert("quoteJsonNumbers".to_string(), Value::Bool(false));
m.insert("exceptions".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("exact".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("1000".to_string(), Value::Str("AuthenticationError".into()).clone());
m.insert("1001".to_string(), Value::Str("PermissionDenied".into()).clone());
m.insert("1002".to_string(), Value::Str("OperationFailed".into()).clone());
m.insert("1003".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("1004".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("1005".to_string(), Value::Str("OperationFailed".into()).clone());
m.insert("1006".to_string(), Value::Str("RateLimitExceeded".into()).clone());
m.insert("1008".to_string(), Value::Str("PermissionDenied".into()).clone());
m.insert("1009".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("1012".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("1400".to_string(), Value::Str("PermissionDenied".into()).clone());
m.insert("2000".to_string(), Value::Str("PermissionDenied".into()).clone());
m.insert("2001".to_string(), Value::Str("InvalidNonce".into()).clone());
m.insert("2002".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("2003".to_string(), Value::Str("PermissionDenied".into()).clone());
m.insert("2004".to_string(), Value::Str("InvalidNonce".into()).clone());
m.insert("2005".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("2006".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("2007".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("2008".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("2010".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("2011".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("2012".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("2020".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("2021".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("2030".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("2031".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("2032".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("2040".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("2041".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("2042".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("2050".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("2051".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("2060".to_string(), Value::Str("BadSymbol".into()).clone());
m.insert("2061".to_string(), Value::Str("BadSymbol".into()).clone());
m.insert("2062".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("2063".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("2064".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("2065".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("2070".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("2080".to_string(), Value::Str("InsufficientFunds".into()).clone());
m.insert("2081".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("2082".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("2083".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("2090".to_string(), Value::Str("RateLimitExceeded".into()).clone());
m.insert("2100".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("2101".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("2102".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("2103".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("2104".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("2105".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("2107".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("2108".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("2110".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("2111".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("2112".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("2113".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("2114".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("2115".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("2116".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("2117".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("2300".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("2301".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("2400".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("2401".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("2402".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("3000".to_string(), Value::Str("BadSymbol".into()).clone());
m.insert("3004".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("3005".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("3006".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("3021".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("3031".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("4000".to_string(), Value::Str("InsufficientFunds".into()).clone());
m.insert("4002".to_string(), Value::Str("OperationFailed".into()).clone());
m.insert("4010".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("5000".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("5001".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("5002".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("5003".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("5004".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("5005".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("6000".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("6100".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("7000".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("7001".to_string(), Value::Str("InsufficientFunds".into()).clone());
m.insert("7002".to_string(), Value::Str("OperationFailed".into()).clone());
m.insert("7003".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("7004".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("7005".to_string(), Value::Str("InsufficientFunds".into()).clone());
m.insert("7006".to_string(), Value::Str("OperationFailed".into()).clone());
m.insert("7007".to_string(), Value::Str("PermissionDenied".into()).clone());
m.insert("7100".to_string(), Value::Str("OperationFailed".into()).clone());
m.insert("7101".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("7102".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("7103".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("7201".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("7450".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("7451".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("7452".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("7453".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("7454".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("7455".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("7500".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("7501".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("7502".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("7503".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("7504".to_string(), Value::Str("OperationRejected".into()).clone());
m
}));
m.insert("broad".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
m
}));
m
})]);
Value::Null
}
pub fn eip_definitions(&self) -> Value {
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("EIP712_ORDER_TYPE".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("Order".to_string(), Value::from(vec![Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("name".to_string(), Value::Str("subAccountID".into()));
m.insert("type".to_string(), Value::Str("uint64".into()));
m
}), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("name".to_string(), Value::Str("isMarket".into()));
m.insert("type".to_string(), Value::Str("bool".into()));
m
}), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("name".to_string(), Value::Str("timeInForce".into()));
m.insert("type".to_string(), Value::Str("uint8".into()));
m
}), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("name".to_string(), Value::Str("postOnly".into()));
m.insert("type".to_string(), Value::Str("bool".into()));
m
}), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("name".to_string(), Value::Str("reduceOnly".into()));
m.insert("type".to_string(), Value::Str("bool".into()));
m
}), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("name".to_string(), Value::Str("legs".into()));
m.insert("type".to_string(), Value::Str("OrderLeg[]".into()));
m
}), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("name".to_string(), Value::Str("nonce".into()));
m.insert("type".to_string(), Value::Str("uint32".into()));
m
}), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("name".to_string(), Value::Str("expiration".into()));
m.insert("type".to_string(), Value::Str("int64".into()));
m
})]));
m.insert("OrderLeg".to_string(), Value::from(vec![Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("name".to_string(), Value::Str("assetID".into()));
m.insert("type".to_string(), Value::Str("uint256".into()));
m
}), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("name".to_string(), Value::Str("contractSize".into()));
m.insert("type".to_string(), Value::Str("uint64".into()));
m
}), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("name".to_string(), Value::Str("limitPrice".into()));
m.insert("type".to_string(), Value::Str("uint64".into()));
m
}), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("name".to_string(), Value::Str("isBuyingContract".into()));
m.insert("type".to_string(), Value::Str("bool".into()));
m
})]));
m
}));
m.insert("EIP712_ORDER_WITH_BUILDER_TYPE".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("OrderWithBuilderFee".to_string(), Value::from(vec![Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("name".to_string(), Value::Str("subAccountID".into()));
m.insert("type".to_string(), Value::Str("uint64".into()));
m
}), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("name".to_string(), Value::Str("isMarket".into()));
m.insert("type".to_string(), Value::Str("bool".into()));
m
}), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("name".to_string(), Value::Str("timeInForce".into()));
m.insert("type".to_string(), Value::Str("uint8".into()));
m
}), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("name".to_string(), Value::Str("postOnly".into()));
m.insert("type".to_string(), Value::Str("bool".into()));
m
}), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("name".to_string(), Value::Str("reduceOnly".into()));
m.insert("type".to_string(), Value::Str("bool".into()));
m
}), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("name".to_string(), Value::Str("legs".into()));
m.insert("type".to_string(), Value::Str("OrderLeg[]".into()));
m
}), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("name".to_string(), Value::Str("builder".into()));
m.insert("type".to_string(), Value::Str("address".into()));
m
}), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("name".to_string(), Value::Str("builderFee".into()));
m.insert("type".to_string(), Value::Str("uint32".into()));
m
}), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("name".to_string(), Value::Str("nonce".into()));
m.insert("type".to_string(), Value::Str("uint32".into()));
m
}), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("name".to_string(), Value::Str("expiration".into()));
m.insert("type".to_string(), Value::Str("int64".into()));
m
})]));
m.insert("OrderLeg".to_string(), Value::from(vec![Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("name".to_string(), Value::Str("assetID".into()));
m.insert("type".to_string(), Value::Str("uint256".into()));
m
}), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("name".to_string(), Value::Str("contractSize".into()));
m.insert("type".to_string(), Value::Str("uint64".into()));
m
}), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("name".to_string(), Value::Str("limitPrice".into()));
m.insert("type".to_string(), Value::Str("uint64".into()));
m
}), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("name".to_string(), Value::Str("isBuyingContract".into()));
m.insert("type".to_string(), Value::Str("bool".into()));
m
})]));
m
}));
m.insert("EIP712_TRANSFER_TYPE".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("Transfer".to_string(), Value::from(vec![Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("name".to_string(), Value::Str("fromAccount".into()));
m.insert("type".to_string(), Value::Str("address".into()));
m
}), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("name".to_string(), Value::Str("fromSubAccount".into()));
m.insert("type".to_string(), Value::Str("uint64".into()));
m
}), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("name".to_string(), Value::Str("toAccount".into()));
m.insert("type".to_string(), Value::Str("address".into()));
m
}), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("name".to_string(), Value::Str("toSubAccount".into()));
m.insert("type".to_string(), Value::Str("uint64".into()));
m
}), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("name".to_string(), Value::Str("tokenCurrency".into()));
m.insert("type".to_string(), Value::Str("uint8".into()));
m
}), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("name".to_string(), Value::Str("numTokens".into()));
m.insert("type".to_string(), Value::Str("uint64".into()));
m
}), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("name".to_string(), Value::Str("nonce".into()));
m.insert("type".to_string(), Value::Str("uint32".into()));
m
}), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("name".to_string(), Value::Str("expiration".into()));
m.insert("type".to_string(), Value::Str("int64".into()));
m
})]));
m
}));
m.insert("EIP712_WITHDRAWAL_TYPE".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("Withdrawal".to_string(), Value::from(vec![Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("name".to_string(), Value::Str("fromAccount".into()));
m.insert("type".to_string(), Value::Str("address".into()));
m
}), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("name".to_string(), Value::Str("toEthAddress".into()));
m.insert("type".to_string(), Value::Str("address".into()));
m
}), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("name".to_string(), Value::Str("tokenCurrency".into()));
m.insert("type".to_string(), Value::Str("uint8".into()));
m
}), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("name".to_string(), Value::Str("numTokens".into()));
m.insert("type".to_string(), Value::Str("uint64".into()));
m
}), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("name".to_string(), Value::Str("nonce".into()));
m.insert("type".to_string(), Value::Str("uint32".into()));
m
}), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("name".to_string(), Value::Str("expiration".into()));
m.insert("type".to_string(), Value::Str("int64".into()));
m
})]));
m
}));
m.insert("EIP712_BUILDER_APPROVAL_TYPE".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("AuthorizeBuilder".to_string(), Value::from(vec![Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("name".to_string(), Value::Str("mainAccountID".into()));
m.insert("type".to_string(), Value::Str("address".into()));
m
}), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("name".to_string(), Value::Str("builderAccountID".into()));
m.insert("type".to_string(), Value::Str("address".into()));
m
}), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("name".to_string(), Value::Str("maxFutureFeeRate".into()));
m.insert("type".to_string(), Value::Str("uint32".into()));
m
}), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("name".to_string(), Value::Str("maxSpotFeeRate".into()));
m.insert("type".to_string(), Value::Str("uint32".into()));
m
}), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("name".to_string(), Value::Str("nonce".into()));
m.insert("type".to_string(), Value::Str("uint32".into()));
m
}), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("name".to_string(), Value::Str("expiration".into()));
m.insert("type".to_string(), Value::Str("int64".into()));
m
})]));
m
}));
m.insert("EIP712_WALLETLOGIN_TYPE".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("WalletLogin".to_string(), Value::from(vec![Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("name".to_string(), Value::Str("signer".into()));
m.insert("type".to_string(), Value::Str("address".into()));
m
}), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("name".to_string(), Value::Str("nonce".into()));
m.insert("type".to_string(), Value::Str("uint32".into()));
m
}), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("name".to_string(), Value::Str("expiration".into()));
m.insert("type".to_string(), Value::Str("int64".into()));
m
})]));
m
}));
m
});
Value::Null
}
pub fn uses_private_key(&self) -> Value {
let mut privateKeyDefined: Value = Value::Bool((self.privateKey.clone() != Value::Null) && (self.privateKey.as_str() != Some("")));
let mut apiKeyDefined: bool = (self.apiKey.clone() != Value::Null) && (self.apiKey.as_str() != Some(""));
if matches!(&privateKeyDefined, Value::Bool(true)) && apiKeyDefined {
panic!("{}", crate::exchange_errors::exchange_error("You should provide either \"privateKey\" or \"apikey & secret\""));
}
return privateKeyDefined;
Value::Null
}
/*
* @method
* @name grvt#signIn
* @description sign in, must be called prior to using other authenticated methods
* @see https://api-docs.grvt.io/#authentication
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns response from exchange
*/
pub async fn sign_in(&mut self, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
// if (this.usesPrivateKey ()) {
// await this.signInWithPrivateKey (params);
// await this.initializeClient (params);
// } else {
// await this.signInWithApiKey (params);
// }
if (self.privateKey.clone() == Value::Null) || (self.privateKey.as_str() == Some("")) {
panic!("{}", crate::exchange_errors::permission_denied("Private key is required for this operation. If you used joined GRVT through email registration instead of Web3 wallet, then read: https://github.com/ccxt/ccxt/wiki/FAQ#how-to-use-the-grvt-exchange-in-ccxt"));
}
self.sign_in_with_private_key(&[params.clone()]).await;
self.initialize_client(&[params]).await;
self.load_account_infos().await;
return Value::Bool(true);
Value::Null
}
pub async fn sign_in_with_api_key(&mut self, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut now: Value = self.milliseconds();
// expires in 24 hours as CS suggested
let mut expires: Value = self.safe_integer_k(self.options.clone(), "signInExpiration", &[Value::Int(0)]);
// if previous sign-in not expired (give 10 seconds margin)
if (expires != Value::Null) && expires.as_f64().unwrap_or(f64::NAN) > (match (&(now), &(Value::Int(10000))) { (Value::Int(x), Value::Int(y)) => Value::Int(x + y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 + *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x + *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x + y), _ => Value::Null }).as_f64().unwrap_or(f64::NAN) {
return Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("api_key".to_string(), self.apiKey.clone());
m
});
let __ws_arg_0 = self.extend(request, &[params]);
let mut response: Value = self.private_edge_post_auth_api_key_login(&[__ws_arg_0]).await;
//
// {
// "location": "",
// "status": "success"
// }
//
if let Value::Dict(__d) = &mut self.options { std::sync::Arc::make_mut(__d).insert("signInExpiration".into(), (match (&(now), &(Value::Int(86400000))) { (Value::Int(x), Value::Int(y)) => Value::Int(x + y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 + *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x + *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x + y), _ => Value::Null })); }; // 24 hours
return response;
Value::Null
}
pub async fn sign_in_with_private_key(&mut self, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
self.check_required_credentials(&[]);
let mut now: Value = self.milliseconds();
// expires in 24 hours as CS suggested
let mut expires: Value = self.safe_integer_k(self.options.clone(), "signInExpiration", &[Value::Int(0)]);
// if previous sign-in not expired (give 10 seconds margin)
if (expires != Value::Null) && expires.as_f64().unwrap_or(f64::NAN) > (match (&(now), &(Value::Int(10000))) { (Value::Int(x), Value::Int(y)) => Value::Int(x + y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 + *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x + *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x + y), _ => Value::Null }).as_f64().unwrap_or(f64::NAN) {
return Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
}
let mut walletAddress: Value = self.eth_get_address_from_private_key(self.privateKey.clone(), &[]);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("address".to_string(), walletAddress);
m.insert("signature".to_string(), self.default_signature());
m
});
request = self.create_signed_request(request.clone(), Value::Str("EIP712_WALLETLOGIN_TYPE".into()), &[]);
let __ws_arg_1 = self.extend(request, &[params]);
let mut response: Value = self.private_edge_post_auth_wallet_login(&[__ws_arg_1]).await;
//
// {
// "location": "",
// "status": "success"
// }
//
if let Value::Dict(__d) = &mut self.options { std::sync::Arc::make_mut(__d).insert("signInExpiration".into(), (match (&(now), &(Value::Int(86400000))) { (Value::Int(x), Value::Int(y)) => Value::Int(x + y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 + *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x + *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x + y), _ => Value::Null })); }; // 24 hours
return response;
Value::Null
}
pub async fn initialize_client(&mut self, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut builderFee: Value = self.safe_bool_k(params.clone(), "builderFee", &[self.safe_bool(self.options.clone(), Value::Str("builderFee".into()), &[Value::Bool(true)])]); // we shouldn't omit here
if (builderFee.as_bool() != Some(true)) {
return Value::Bool(false);
}
let mut approvedBuilderFee: Value = self.safe_bool_k(self.options.clone(), "approvedBuilderFee", &[Value::Bool(false)]);
if (approvedBuilderFee.as_bool() == Some(true)) {
return Value::Bool(true);
}
let mut results: Value = promise_all(&Value::from(vec![self.private_trading_post_full_v1_get_authorized_builders(&[]).await, self.load_account_infos().await])).await;
//
// {
// "results": [{
// "builder_account_id": "GRVT_MAIN_ACCOUNT_ID_HERE",
// "max_futures_fee_rate": 0.001,
// "max_spot_fee_rate": 0.0001
// }]
// }
//
let mut currentBuilders: Value = self.safe_dict(results, Value::Int(0), &[]);
let mut approvedBuilder: Value = self.safe_list_k(currentBuilders, "results", &[Value::from(vec![])]);
let mut length: f64 = ((approvedBuilder.len() as i64) as f64);
let mut found: bool = false;
{
let mut i: Value = Value::Int(0);
let mut __for_first_721: bool = true;
while { if !__for_first_721 { i = (match (&(i), &(Value::Int(1))) { (Value::Int(x), Value::Int(y)) => Value::Int(x + y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 + *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x + *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x + y), _ => Value::Null }); } __for_first_721 = false; i.as_f64().unwrap_or(f64::NAN) < length } {
let mut builderInfo: Value = self.safe_dict(approvedBuilder.clone(), i.clone(), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut builderAccountId: Value = self.safe_string_k(builderInfo, "builder_account_id", &[]);
if (builderAccountId.as_str() == self.safe_string_k(self.options.clone(), "builder", &[]).as_str()) {
found = true;
break;
}
}
}
if found {
if let Value::Dict(__d) = &mut self.options { std::sync::Arc::make_mut(__d).insert("approvedBuilderFee".into(), Value::Bool(true)); }
} else {
let _try_result = futures::FutureExt::catch_unwind(std::panic::AssertUnwindSafe(async {
let mut defaultFromAccountId: Value = self.safe_string_k(self.options.clone(), "userMainAccountId", &[]); // this.ethGetAddressFromPrivateKey (this.secret); // this.safeString (this.options, 'userMainAccountId');
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("main_account_id".to_string(), defaultFromAccountId);
m.insert("builder_account_id".to_string(), self.safe_string_k(self.options.clone(), "builder", &[]));
m.insert("max_futures_fee_rate".to_string(), self.safe_string_k(self.options.clone(), "builderRate", &[]));
m.insert("max_spot_fee_rate".to_string(), self.safe_string_k(self.options.clone(), "builderRate", &[]));
m.insert("signature".to_string(), self.default_signature());
m
});
request = self.create_signed_request(request.clone(), Value::Str("EIP712_BUILDER_APPROVAL_TYPE".into()), &[]);
let __ws_arg_2 = self.extend(request, &[params]);
let mut authResponse: Value = self.private_trading_post_full_v1_authorize_builder(&[__ws_arg_2]).await;
//
// {
// "result": {
// "ack": "true",
// "tx_id":"0"
// }
// }
//
let mut authResult: Value = self.safe_dict_k(authResponse.clone(), "result", &[]);
let mut ack: Value = self.safe_bool_k(authResult, "ack", &[]);
if (ack.as_bool() != Some(true)) {
panic!("{}", crate::exchange_errors::exchange_error(format!("{}{}", Value::Str("Builder authorization failed, ".into()), json_stringify(&authResponse))));
}
if let Value::Dict(__d) = &mut self.options { std::sync::Arc::make_mut(__d).insert("approvedBuilderFee".into(), Value::Bool(true)); }
#[allow(unreachable_code)] { Value::Null }})).await;
if let Err(_try_err) = _try_result { let e: Value = panic_to_value(_try_err);
if let Value::Dict(__d) = &mut self.options { std::sync::Arc::make_mut(__d).insert("builderFee".into(), Value::Bool(false)); }; // disable builder fee if an error occurs
}
}
return Value::Null;
Value::Null
}
/*
* @method
* @name grvt#fetchMarkets
* @description retrieves data on all markets
* @see https://api-docs.grvt.io/market_data_api/#get-instrument-prod
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object[]} an array of objects representing market data
*/
pub async fn fetch_markets(&mut self, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut marketsPromise: Value = self.public_market_post_full_v1_all_instruments(&[params]).await;
//
// {
// "result": [
// {
// "instrument": "AAVE_USDT_Perp",
// "instrument_hash": "0x032201",
// "base": "AAVE",
// "quote": "USDT",
// "kind": "PERPETUAL",
// "venues": [
// "ORDERBOOK",
// "RFQ"
// ],
// "settlement_period": "PERPETUAL",
// "base_decimals": "9",
// "quote_decimals": "6",
// "tick_size": "0.01",
// "min_size": "0.1",
// "create_time": "1764303867576216941",
// "max_position_size": "3000.0",
// "funding_interval_hours": "8",
// "adjusted_funding_rate_cap": "0.75",
// "adjusted_funding_rate_floor": "-0.75"
// },
// ...
//
let mut promises: Value = Value::from(vec![marketsPromise]);
if !(self.is_empty_string(self.apiKey.clone()).as_bool() == Some(true)) || !(self.is_empty_string(self.privateKey.clone()).as_bool() == Some(true)) {
append_to_array(&mut promises, self.sign_in(&[]).await);
}
let mut results: Value = promise_all(&promises).await;
let mut response: Value = self.safe_dict(results, Value::Int(0), &[]);
let mut result: Value = self.safe_list_k(response, "result", &[Value::from(vec![])]);
return self.parse_markets(result);
Value::Null
}
pub fn parse_market(&self, mut market: Value) -> Value {
//
// {
// "instrument": "BTC_USDT_Perp",
// "instrument_hash": "0x030501",
// "base": "BTC",
// "quote": "USDT",
// "kind": "PERPETUAL",
// "venues": [
// "ORDERBOOK",
// "RFQ"
// ],
// "settlement_period": "PERPETUAL",
// "base_decimals": 9,
// "quote_decimals": 6,
// "tick_size": "0.1",
// "min_size": "0.001",
// "create_time": "1768040726362828205",
// "max_position_size": "1000.0",
// "funding_interval_hours": 8,
// "adjusted_funding_rate_cap": "0.3",
// "adjusted_funding_rate_floor": "-0.3",
// "min_notional": "100.0"
// }
//
let mut marketId: Value = self.safe_string_k(market.clone(), "instrument", &[]);
let mut baseId: Value = self.safe_string_k(market.clone(), "base", &[]);
let mut quoteId: Value = self.safe_string_k(market.clone(), "quote", &[]);
let mut settleId: Value = quoteId.clone();
let mut base: Value = self.safe_currency_code(baseId.clone(), &[]);
let mut quote: Value = self.safe_currency_code(quoteId.clone(), &[]);
if (base == Value::Null) || (quote == Value::Null) {
return Value::Null;
}
let mut settle: Value = self.safe_currency_code(settleId.clone(), &[]);
let mut symbol: Value = Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", base, Value::Str("/".into())).into()), quote).into()), Value::Str(":".into())).into()), settle).into());
let mut type_var: Value = Value::Null;
let mut typeRaw: Option<String> = self.safe_string_k(market.clone(), "kind", &[]).as_str().map(str::to_owned);
if (typeRaw.as_deref() == Some("PERPETUAL")) {
type_var = Value::Str("swap".into());
}
let mut isSpot: Value = (Value::Bool(type_var.as_str() == Some("spot")));
let mut isSwap: Value = (Value::Bool(type_var.as_str() == Some("swap")));
let mut isFuture: Value = (Value::Bool(type_var.as_str() == Some("future")));
let mut isContract: Value = Value::Bool(matches!(&isSwap, Value::Bool(true)) || matches!(&isFuture, Value::Bool(true)));
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), marketId);
m.insert("symbol".to_string(), symbol);
m.insert("base".to_string(), base);
m.insert("quote".to_string(), quote);
m.insert("settle".to_string(), settle);
m.insert("baseId".to_string(), baseId);
m.insert("quoteId".to_string(), quoteId);
m.insert("settleId".to_string(), settleId);
m.insert("type".to_string(), type_var);
m.insert("spot".to_string(), isSpot);
m.insert("margin".to_string(), Value::Bool(false));
m.insert("swap".to_string(), isSwap.clone());
m.insert("future".to_string(), isFuture);
m.insert("option".to_string(), Value::Bool(false));
m.insert("active".to_string(), Value::Null);
m.insert("contract".to_string(), isContract);
m.insert("linear".to_string(), (if matches!(&isSwap, Value::Bool(true)) { Value::Bool(true) } else { Value::Null }));
m.insert("inverse".to_string(), (if matches!(&isSwap, Value::Bool(true)) { Value::Bool(false) } else { Value::Null }));
m.insert("contractSize".to_string(), self.parse_number(Value::Str("1".into()), &[]));
m.insert("expiry".to_string(), Value::Null);
m.insert("expiryDatetime".to_string(), Value::Null);
m.insert("strike".to_string(), Value::Null);
m.insert("optionType".to_string(), Value::Null);
m.insert("precision".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("amount".to_string(), self.safe_number_k(market.clone(), "min_size", &[]));
m.insert("price".to_string(), self.safe_number_k(market.clone(), "tick_size", &[]));
m.insert("base".to_string(), self.parse_number(self.parse_precision(&[self.safe_string_k(market.clone(), "base_decimals", &[])]), &[]));
m.insert("quote".to_string(), self.parse_number(self.parse_precision(&[self.safe_string_k(market.clone(), "quote_decimals", &[])]), &[]));
m
}));
m.insert("limits".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("leverage".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), Value::Null);
m.insert("max".to_string(), Value::Null);
m
}));
m.insert("amount".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), self.safe_number_k(market.clone(), "min_size", &[]));
m.insert("max".to_string(), self.safe_number_k(market.clone(), "max_position_size", &[]));
m
}));
m.insert("price".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), Value::Null);
m.insert("max".to_string(), Value::Null);
m
}));
m.insert("cost".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), self.safe_number_k(market.clone(), "min_notional", &[]));
m.insert("max".to_string(), Value::Null);
m
}));
m
}));
m.insert("created".to_string(), self.safe_integer_product_k(market.clone(), "create_time", Value::Float(0.000001), &[]));
m.insert("info".to_string(), market);
m
});
Value::Null
}
/*
* @method
* @name grvt#fetchCurrencies
* @description fetches all available currencies on an exchange
* @see https://api-docs.grvt.io/market_data_api/#get-currency-response
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} an associative dictionary of currencies
*/
pub async fn fetch_currencies(&mut self, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("".to_string(), Value::Str("".into()));
m
}); // workaround for php [] empty arr
let mut response: Value = self.public_market_post_full_v1_currency(&[request]).await;
//
// {
// "result": [
// {
// "id": "4",
// "symbol": "ETH",
// "balance_decimals": "9",
// "quantity_multiplier": "1000000000"
// },
// ..
//
let mut responseResult: Value = self.safe_list_k(response, "result", &[Value::from(vec![])]);
return self.parse_currencies(responseResult);
Value::Null
}
pub fn parse_currency(&self, mut rawCurrency: Value) -> Value {
//
// {
// "id": "4",
// "symbol": "ETH",
// "balance_decimals": "9",
// "quantity_multiplier": "1000000000"
// },
//
let mut id: Value = self.safe_string_k(rawCurrency.clone(), "symbol", &[]);
let mut code: Value = self.safe_currency_code(id.clone(), &[]);
return self.safe_currency_structure(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), rawCurrency.clone());
m.insert("id".to_string(), id);
m.insert("code".to_string(), code);
m.insert("name".to_string(), Value::Null);
m.insert("active".to_string(), Value::Null);
m.insert("deposit".to_string(), Value::Null);
m.insert("withdraw".to_string(), Value::Null);
m.insert("fee".to_string(), Value::Null);
m.insert("precision".to_string(), self.parse_number(self.parse_precision(&[self.safe_string_k(rawCurrency.clone(), "balance_decimals", &[])]), &[]));
m.insert("limits".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("amount".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), Value::Null);
m.insert("max".to_string(), Value::Null);
m
}));
m.insert("withdraw".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), Value::Null);
m.insert("max".to_string(), Value::Null);
m
}));
m.insert("deposit".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), Value::Null);
m.insert("max".to_string(), Value::Null);
m
}));
m
}));
m.insert("type".to_string(), Value::Str("crypto".into()));
m.insert("networks".to_string(), Value::Null);
m.insert("numericId".to_string(), self.safe_integer_k(rawCurrency, "id", &[]));
m
}));
Value::Null
}
/*
* @method
* @name grvt#fetchTicker
* @description fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
* @see https://api-docs.grvt.io/market_data_api/#ticker_1
* @param {string} symbol unified symbol of the market to fetch the ticker for
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a [ticker structure]{@link https://docs.ccxt.com/?id=ticker-structure}
*/
pub async fn fetch_ticker(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("instrument".to_string(), self.market_id(symbol));
m
});
let __ws_arg_3 = self.extend(request, &[params]);
let mut response: Value = self.public_market_post_full_v1_ticker(&[__ws_arg_3]).await;
//
// {
// "result": {
// "event_time": "1764774730025055205",
// "instrument": "BTC_USDT_Perp",
// "mark_price": "92697.300078773",
// "index_price": "92727.818122278",
// "last_price": "92683.0",
// "last_size": "0.001",
// "mid_price": "92682.95",
// "best_bid_price": "92682.9",
// "best_bid_size": "5.332",
// "best_ask_price": "92683.0",
// "best_ask_size": "0.009",
// "funding_rate_8h_curr": "0.0037",
// "funding_rate_8h_avg": "0.0037",
// "interest_rate": "0.0",
// "forward_price": "0.0",
// "buy_volume_24h_b": "2893.898",
// "sell_volume_24h_b": "2907.847",
// "buy_volume_24h_q": "266955739.1606",
// "sell_volume_24h_q": "268170211.7109",
// "high_price": "93908.3",
// "low_price": "89900.1",
// "open_price": "90129.2",
// "open_interest": "1523.218935908",
// "long_short_ratio": "1.472543",
// "funding_rate": "0.0037",
// "next_funding_time": "1764777600000000000"
// }
// }
//
let mut result: Value = self.safe_dict_k(response, "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_ticker(result, &[market]);
Value::Null
}
pub fn parse_ticker(&self, mut ticker: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// {
// "event_time": "1764774730025055205",
// "instrument": "BTC_USDT_Perp",
// "mark_price": "92697.300078773",
// "index_price": "92727.818122278",
// "last_price": "92683.0",
// "last_size": "0.001",
// "mid_price": "92682.95",
// "best_bid_price": "92682.9",
// "best_bid_size": "5.332",
// "best_ask_price": "92683.0",
// "best_ask_size": "0.009",
// "funding_rate_8h_curr": "0.0037",
// "funding_rate_8h_avg": "0.0037",
// "interest_rate": "0.0",
// "forward_price": "0.0",
// "buy_volume_24h_b": "2893.898",
// "sell_volume_24h_b": "2907.847",
// "buy_volume_24h_q": "266955739.1606",
// "sell_volume_24h_q": "268170211.7109",
// "high_price": "93908.3",
// "low_price": "89900.1",
// "open_price": "90129.2",
// "open_interest": "1523.218935908",
// "long_short_ratio": "1.472543",
// "funding_rate": "0.0037",
// "next_funding_time": "1764777600000000000"
// }
//
let mut marketId: Value = self.safe_string_k(ticker.clone(), "instrument", &[]);
let mut timestamp: Value = self.safe_integer_product_k(ticker.clone(), "event_time", Value::Float(0.000001), &[]);
return self.safe_ticker(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), ticker.clone());
m.insert("symbol".to_string(), self.safe_symbol(marketId, &[market]));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp));
m.insert("open".to_string(), self.safe_string_k(ticker.clone(), "open_price", &[]));
m.insert("high".to_string(), self.safe_string_k(ticker.clone(), "high_price", &[]));
m.insert("low".to_string(), self.safe_string_k(ticker.clone(), "low_price", &[]));
m.insert("last".to_string(), self.safe_string_k(ticker.clone(), "last_price", &[]));
m.insert("bid".to_string(), self.safe_string_k(ticker.clone(), "best_bid_price", &[]));
m.insert("bidVolume".to_string(), self.safe_string_k(ticker.clone(), "best_bid_size", &[]));
m.insert("ask".to_string(), self.safe_string_k(ticker.clone(), "best_ask_price", &[]));
m.insert("askVolume".to_string(), self.safe_string_k(ticker.clone(), "best_ask_size", &[]));
m.insert("change".to_string(), Value::Null);
m.insert("percentage".to_string(), Value::Null);
m.insert("baseVolume".to_string(), self.safe_string_k(ticker.clone(), "buy_volume_24h_b", &[]));
m.insert("quoteVolume".to_string(), self.safe_string_k(ticker.clone(), "buy_volume_24h_q", &[]));
m.insert("markPrice".to_string(), self.safe_string_k(ticker.clone(), "mark_price", &[]));
m.insert("indexPrice".to_string(), self.safe_string_k(ticker, "index_price", &[]));
m.insert("vwap".to_string(), Value::Null);
m.insert("average".to_string(), Value::Null);
m.insert("previousClose".to_string(), Value::Null);
m
}), &[]);
Value::Null
}
/*
* @method
* @name grvt#fetchOrderBook
* @description fetches information on open orders with bid (buy) and ask (sell) prices, volumes and other data
* @see https://api-docs.grvt.io/market_data_api/#orderbook-levels
* @param {string} symbol unified symbol of the market to fetch the order book for
* @param {int} [limit] the maximum amount of order book entries to return
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.loc] crypto location, default: us
* @returns {object} an [order book structure]{@link https://docs.ccxt.com/?id=order-book-structure}
*/
pub async fn fetch_order_book(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
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
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("instrument".to_string(), self.market_id(symbol));
m
});
let mut limitResolved: Value = (if (limit == Value::Null) { Value::Int(100) } else { limit });
if limitResolved.as_f64().unwrap_or(f64::NAN) <= ((500i64) as f64) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("depth".into(), self.find_nearest_ceiling(Value::from(vec![Value::Int(10), Value::Int(50), Value::Int(100), Value::Int(500)]), limitResolved)); }
}
let __ws_arg_4 = self.extend(request, &[params]);
let mut response: Value = self.public_market_post_full_v1_book(&[__ws_arg_4]).await;
//
// {
// "result": {
// "event_time": "1764777396650000000",
// "instrument": "BTC_USDT_Perp",
// "bids": [
// { "price": "92336.0", "size": "0.005", "num_orders": "1" },
// ...
// ],
// "asks": [
// { "price": "92336.1", "size": "5.711", "num_orders": "37" },
// ...
// ]
// }
// }
//
let mut result: Value = self.safe_dict_k(response, "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut timestamp: Value = self.parse8601(self.safe_string_k(result.clone(), "event_time", &[]));
let mut marketId: Value = self.safe_string_k(result.clone(), "instrument", &[]);
return self.parse_order_book(result, self.safe_symbol(marketId, &[]), &[timestamp, Value::Str("bids".into()), Value::Str("asks".into()), Value::Str("price".into()), Value::Str("size".into())]);
Value::Null
}
/*
* @method
* @name grvt#fetchTrades
* @description get the list of most recent trades for a particular symbol
* @see https://api-docs.grvt.io/market_data_api/#trade_1
* @param {string} symbol unified symbol of the market
* @param {int} [since] timestamp in ms of the earliest item to fetch
* @param {int} [limit] the maximum amount of items to fetch
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {int} [params.until] timestamp in ms for the ending date filter, default is the current time
* @returns {Trade[]} a list of [trade structures]{@link https://docs.ccxt.com/?id=public-trades}
*/
pub async fn fetch_trades(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
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
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("instrument".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m
});
if (limit != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("limit".into(), crate::runtime::Math::min(&limit, &Value::Int(1000))); }
}
let mut requestUntilOptionStringparamsUntilOptionStringVariable = self.handle_until_option_string(Value::Str("end_time".into()), request, &[params, Value::Int(1000000)]);
let mut requestUntilOptionString: Value = requestUntilOptionStringparamsUntilOptionStringVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsUntilOptionString: Value = requestUntilOptionStringparamsUntilOptionStringVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
if (since != Value::Null) {
add_element_to_object(&mut requestUntilOptionString, &Value::Str("start_time".into()), self.number_to_string((match (&(since), &(Value::Int(1000000))) { (Value::Int(x), Value::Int(y)) => Value::Int(x * y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 * *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x * *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x * y), _ => Value::Null })));
}
let __ws_arg_5 = self.extend(requestUntilOptionString, &[paramsUntilOptionString]);
let mut response: Value = self.public_market_post_full_v1_trade_history(&[__ws_arg_5]).await;
//
// {
// "next": "eyJ0cmFkZUlkIjo2NDc5MTAyMywidHJhZGVJbmRleCI6MX0",
// "result": [
// {
// "event_time": "1764779531332118705",
// "instrument": "ETH_USDT_Perp",
// "is_taker_buyer": false,
// "size": "23.73",
// "price": "3089.88",
// "mark_price": "3089.360002315",
// "index_price": "3090.443723246",
// "interest_rate": "0.0",
// "forward_price": "0.0",
// "trade_id": "64796657-1",
// "venue": "ORDERBOOK",
// "is_rpi": false
// },
// ...
//
let mut result: Value = self.safe_list_k(response, "result", &[Value::from(vec![])]);
return self.parse_trades(result, &[market, since, limit]);
Value::Null
}
pub fn parse_trade(&self, mut trade: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// fetchTrades
//
// {
// "event_time": "1764779531332118705",
// "instrument": "ETH_USDT_Perp",
// "size": "23.73",
// "price": "3089.88",
// "is_rpi": false,
// "mark_price": "3089.360002315",
// "index_price": "3090.443723246",
// "interest_rate": "0.0",
// "forward_price": "0.0",
// "trade_id": "64796657-1",
// "venue": "ORDERBOOK",
// "is_taker_buyer": false
// }
//
// fetchMyTrades
//
// {
// "event_time": "1764945709702747558",
// "instrument": "BTC_USDT_Perp",
// "size": "0.001",
// "price": "90000.0",
// "is_rpi": false
// "mark_price": "90050.164063298",
// "index_price": "90089.803654938",
// "interest_rate": "0.0",
// "forward_price": "0.0",
// "trade_id": "65424692-2",
// "venue": "ORDERBOOK",
// "is_buyer": true,
// "is_taker": false,
// "broker": "UNSPECIFIED",
// "realized_pnl": "0.0",
// "fee": "-0.00009",
// "fee_rate": "0.0",
// "order_id": "0x01010105034cddc7000000006621285c",
// "client_order_id": "1375879248",
// "signer": "0x42c9f56f2c9da534f64b8806d64813b29c62a01d",
// "sub_account_id": "2147050003876484",
// }
//
let mut marketId: Value = self.safe_string_k(trade.clone(), "instrument", &[]);
let mut marketResolved: Value = self.safe_market(&[marketId, market]);
let mut timestamp: Value = self.safe_integer_product_k(trade.clone(), "event_time", Value::Float(0.000001), &[]);
let mut takerOrMaker: Value = Value::Null;
let mut isTakerBuyer: Value = self.safe_bool_k(trade.clone(), "is_taker_buyer", &[]);
let mut side: Value = Value::Null;
if (isTakerBuyer != Value::Null) {
side = (if isTakerBuyer.as_bool() == Some(true) { Value::Str("buy".into()) } else { Value::Str("sell".into()) });
takerOrMaker = Value::Str("taker".into());
} else {
let mut isTaker: Value = self.safe_bool_k(trade.clone(), "is_taker", &[Value::Bool(false)]);
let mut isBuyer: Value = self.safe_bool_k(trade.clone(), "is_buyer", &[Value::Bool(false)]);
takerOrMaker = (if isTaker.as_bool() == Some(true) { Value::Str("taker".into()) } else { Value::Str("maker".into()) });
side = (if isBuyer.as_bool() == Some(true) { Value::Str("buy".into()) } else { Value::Str("sell".into()) });
}
let mut fee: Value = Value::Null;
let mut feeString: Value = self.safe_string_k(trade.clone(), "fee", &[]);
if (feeString != Value::Null) {
fee = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), self.parse_number(feeString, &[]));
m.insert("currency".to_string(), marketResolved.as_map().and_then(|__m| __m.get("quote")).cloned().unwrap_or(Value::Null));
m.insert("rate".to_string(), self.safe_number_k(trade.clone(), "fee_rate", &[]));
m
});
}
return self.safe_trade(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), trade.clone());
m.insert("id".to_string(), self.safe_string_k(trade.clone(), "trade_id", &[]));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp));
m.insert("symbol".to_string(), marketResolved.as_map().and_then(|__m| __m.get("symbol")).cloned().unwrap_or(Value::Null));
m.insert("side".to_string(), side);
m.insert("takerOrMaker".to_string(), takerOrMaker);
m.insert("price".to_string(), self.safe_string_k(trade.clone(), "price", &[]));
m.insert("amount".to_string(), self.safe_string_k(trade.clone(), "size", &[]));
m.insert("cost".to_string(), Value::Null);
m.insert("fee".to_string(), fee);
m.insert("order".to_string(), self.safe_string_k(trade, "order_id", &[]));
m
}), &[marketResolved]);
Value::Null
}
/*
* @method
* @name grvt#fetchOHLCV
* @description fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market
* @see https://api-docs.grvt.io/market_data_api/#candlestick_1
* @param {string} symbol unified symbol of the market to fetch OHLCV data for
* @param {string} timeframe the length of time each candle represents
* @param {int} [since] timestamp in ms of the earliest item to fetch
* @param {int} [limit] the maximum amount of items to fetch
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {int} [params.until] timestamp in ms for the ending date filter, default is the current time
* @param {boolean} [params.paginate] default false, when true will automatically paginate by calling this endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
* @returns {int[][]} A list of candles ordered as timestamp, open, high, low, close, volume
*/
pub async fn fetch_ohlcv(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut timeframe = get_arg(optional_args, 0, Value::Str("1m".into()));
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
}));
let mut maxLimit: Value = Value::Int(1000);
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut paginateparamsPaginateVariable = self.handle_option_bool_and_params(params, Value::Str("fetchOHLCV".into()), Value::Str("paginate".into()), &[Value::Bool(false)]);
let mut paginate: Value = paginateparamsPaginateVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsPaginate: Value = paginateparamsPaginateVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
if is_true(&paginate) {
return self.fetch_paginated_call_deterministic(Value::Str("fetchOHLCV".into()), &[symbol.clone(), since.clone(), limit.clone(), timeframe.clone(), paramsPaginate.clone(), maxLimit]).await;
}
let mut market: Value = self.market(symbol);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("instrument".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m.insert("interval".to_string(), self.safe_string(self.timeframes.clone(), timeframe.clone(), &[timeframe.clone()]));
m
});
let mut priceTypeMap: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("last".to_string(), Value::Str("TRADE".into()));
m.insert("mark".to_string(), Value::Str("MARK".into()));
m.insert("index".to_string(), Value::Str("INDEX".into()));
m
});
let mut selectedPriceType: Value = self.safe_string_k(paramsPaginate.clone(), "priceType", &[Value::Str("last".into())]);
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("type".into(), self.safe_string(priceTypeMap, selectedPriceType, &[])); }
if (limit != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("limit".into(), crate::runtime::Math::min(&limit, &Value::Int(1000))); }
}
let mut requestUntilOptionStringparamsUntilOptionStringVariable = self.handle_until_option_string(Value::Str("end_time".into()), request, &[paramsPaginate, Value::Int(1000000)]);
let mut requestUntilOptionString: Value = requestUntilOptionStringparamsUntilOptionStringVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsUntilOptionString: Value = requestUntilOptionStringparamsUntilOptionStringVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
if (since != Value::Null) {
add_element_to_object(&mut requestUntilOptionString, &Value::Str("start_time".into()), self.number_to_string((match (&(since), &(Value::Int(1000000))) { (Value::Int(x), Value::Int(y)) => Value::Int(x * y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 * *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x * *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x * y), _ => Value::Null })));
}
let __ws_arg_6 = self.extend(requestUntilOptionString, &[paramsUntilOptionString]);
let mut response: Value = self.public_market_post_full_v1_kline(&[__ws_arg_6]).await;
//
// {
// "result": [
// {
// "open_time": "1767288240000000000",
// "close_time": "1767288300000000000",
// "open": "88178.8",
// "close": "88176.7",
// "high": "88192.7",
// "low": "88176.6",
// "volume_b": "15.32",
// "volume_q": "1350962.4782",
// "trades": 38,
// "instrument": "BTC_USDT_Perp"
// },
// ],
// "next": "eyJvcGVuVGltZSI6MTc2NzI1ODMwMDAwMDAwMDAwMH0"
// }
//
let mut candles: Value = self.safe_list_k(response, "result", &[Value::from(vec![])]);
return self.parse_ohlc_vs(candles, &[market, timeframe, since, limit]);
Value::Null
}
pub fn parse_ohlcv(&self, mut ohlcv: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
return Value::from(vec![self.safe_integer_product_k(ohlcv.clone(), "open_time", Value::Float(0.000001), &[]), self.safe_number_k(ohlcv.clone(), "open", &[]), self.safe_number_k(ohlcv.clone(), "high", &[]), self.safe_number_k(ohlcv.clone(), "low", &[]), self.safe_number_k(ohlcv.clone(), "close", &[]), self.safe_number_k(ohlcv, "volume_b", &[])]);
Value::Null
}
/*
* @method
* @name grvt#fetchFundingRateHistory
* @description fetches historical funding rate prices
* @see https://api-docs.grvt.io/market_data_api/#funding-rate
* @param {string} symbol unified symbol of the market to fetch the funding rate history for
* @param {int} [since] timestamp in ms of the earliest funding rate to fetch
* @param {int} [limit] the maximum amount of [funding rate structures]{@link https://docs.ccxt.com/?id=funding-rate-history-structure} to fetch
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {int} [params.until] timestamp in ms of the latest item
* @param {boolean} [params.paginate] default false, when true will automatically paginate by calling this endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
* @returns {object[]} a list of [funding rate structures]{@link https://docs.ccxt.com/?id=funding-rate-history-structure}
*/
pub async fn fetch_funding_rate_history(&mut self, optional_args: &[Value]) -> Value {
let mut symbol = 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
}));
if (symbol == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" fetchFundingRateHistory() requires a symbol argument".into()))));
}
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut paginateparamsPaginateVariable = self.handle_option_bool_and_params(params, Value::Str("fetchFundingRateHistory".into()), Value::Str("paginate".into()), &[Value::Bool(false)]);
let mut paginate: Value = paginateparamsPaginateVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsPaginate: Value = paginateparamsPaginateVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
if is_true(&paginate) {
return self.fetch_paginated_call_deterministic(Value::Str("fetchFundingRateHistory".into()), &[symbol.clone(), since.clone(), limit.clone(), Value::Str("8h".into()), paramsPaginate.clone()]).await;
}
let mut market: Value = self.market(symbol);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("instrument".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m
});
if (limit != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("limit".into(), crate::runtime::Math::min(&limit, &Value::Int(1000))); }
}
let mut requestUntilOptionStringparamsUntilOptionStringVariable = self.handle_until_option_string(Value::Str("end_time".into()), request, &[paramsPaginate, Value::Int(1000000)]);
let mut requestUntilOptionString: Value = requestUntilOptionStringparamsUntilOptionStringVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsUntilOptionString: Value = requestUntilOptionStringparamsUntilOptionStringVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
if (since != Value::Null) {
add_element_to_object(&mut requestUntilOptionString, &Value::Str("start_time".into()), self.number_to_string((match (&(since), &(Value::Int(1000000))) { (Value::Int(x), Value::Int(y)) => Value::Int(x * y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 * *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x * *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x * y), _ => Value::Null })));
}
let __ws_arg_7 = self.extend(requestUntilOptionString, &[paramsUntilOptionString]);
let mut response: Value = self.public_market_post_full_v1_funding(&[__ws_arg_7]).await;
//
// {
// "result": [
// {
// "instrument": "BTC_USDT_Perp",
// "funding_rate": "-0.0034",
// "funding_time": "1760494260000000000",
// "mark_price": "112721.159060304",
// "funding_rate_8_h_avg": "-0.0038",
// "funding_interval_hours": "0"
// },
// ...
// ],
// "next": "eyJmdW5kaW5nVGltZSI6MTc2MDQ5NDI2MDAwMDAwMDAwMH0"
// }
//
let mut result: Value = self.safe_list_k(response, "result", &[Value::from(vec![])]);
return self.parse_funding_rate_histories(result, &[market]);
Value::Null
}
pub fn parse_funding_rate_history(&self, mut rawItem: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// {
// "instrument": "BTC_USDT_Perp",
// "funding_rate": "-0.0034",
// "funding_time": "1760494260000000000",
// "mark_price": "112721.159060304",
// "funding_rate_8_h_avg": "-0.0038",
// "funding_interval_hours": "0"
// },
//
let mut marketId: Value = self.safe_string_k(rawItem.clone(), "instrument", &[]);
let mut ts: Value = self.safe_integer_product_k(rawItem.clone(), "funding_time", Value::Float(0.000001), &[]);
// the api documents funding_rate in percentage points, and a unified
// fundingRate is a fraction, with the Manual's examples reading 0.000072
let mut rate: Value = self.safe_string_k(rawItem.clone(), "funding_rate", &[]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), rawItem);
m.insert("symbol".to_string(), self.safe_symbol(marketId, &[market]));
m.insert("fundingRate".to_string(), self.parse_number(crate::precise::Precise::stringDiv(&rate, &Value::Str("100".into())), &[]));
m.insert("timestamp".to_string(), ts.clone());
m.insert("datetime".to_string(), self.iso8601(ts));
m
});
Value::Null
}
pub fn get_sub_account_id(&self, mut params: Value) -> Value {
let mut subAccountId: Value = self.handle_option_and_params(params, Value::Str("getSubAccountId".into()), Value::Str("accountId".into()), &[]).as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
if (subAccountId == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" you should set \"accountId\" in options or params, which can be found in the grvt dashboard, under Api-Keys page".into()))));
}
return to_string_val(&subAccountId);
Value::Null
}
/*
* @method
* @name grvt#fetchBalance
* @description query for account info
* @see https://api-docs.grvt.io/trading_api/#sub-account-summary
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a [balance structure]{@link https://docs.ccxt.com/?id=balance-structure}
*/
pub async fn fetch_balance(&mut self, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
self.load_markets_and_sign_in().await;
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("sub_account_id".to_string(), self.get_sub_account_id(params.clone()));
m
});
let __ws_arg_8 = self.extend(request, &[params]);
let mut response: Value = self.private_trading_post_full_v1_account_summary(&[__ws_arg_8]).await;
//
// {
// "result": {
// "event_time": "1764863116142428457",
// "sub_account_id": "2147050003876484",
// "margin_type": "SIMPLE_CROSS_MARGIN",
// "settle_currency": "USDT",
// "unrealized_pnl": "0.0",
// "total_equity": "15.0",
// "initial_margin": "0.0",
// "maintenance_margin": "0.0",
// "available_balance": "15.0",
// "spot_balances": [
// {
// "currency": "USDT",
// "balance": "15.0",
// "index_price": "1.000289735"
// }
// ],
// "positions": [],
// "settle_index_price": "1.000289735",
// "derisk_margin": "0.0",
// "derisk_to_maintenance_margin_ratio": "1.0",
// "total_cross_equity": "15.0",
// "cross_unrealized_pnl": "0.0"
// }
// }
//
let mut result: Value = self.safe_dict_k(response, "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_balance(result);
Value::Null
}
pub fn parse_balance(&self, mut response: Value) -> Value {
//
// {
// "event_time": "1764863116142428457",
// "sub_account_id": "2147050003876484",
// "margin_type": "SIMPLE_CROSS_MARGIN",
// "settle_currency": "USDT",
// "unrealized_pnl": "0.0",
// "total_equity": "15.0",
// "initial_margin": "0.0",
// "maintenance_margin": "0.0",
// "available_balance": "15.0",
// "spot_balances": [
// {
// "currency": "USDT",
// "balance": "15.0",
// "index_price": "1.000289735"
// }
// ],
// "positions": [],
// "settle_index_price": "1.000289735",
// "derisk_margin": "0.0",
// "derisk_to_maintenance_margin_ratio": "1.0",
// "total_cross_equity": "15.0",
// "cross_unrealized_pnl": "0.0"
// }
//
let mut timestamp: Value = self.safe_integer_product_k(response.clone(), "event_time", Value::Float(0.000001), &[]);
let mut result: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), response.clone());
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp));
m
});
let mut spotBalances: Value = self.safe_list_k(response.clone(), "spot_balances", &[Value::from(vec![])]);
let mut availableBalance: Value = self.safe_string_k(response, "available_balance", &[]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_722: bool = true;
while { if !__for_first_722 { i = (match (&(i), &(Value::Int(1))) { (Value::Int(x), Value::Int(y)) => Value::Int(x + y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 + *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x + *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x + y), _ => Value::Null }); } __for_first_722 = false; i.as_f64().unwrap_or(f64::NAN) < ((spotBalances.len() as i64) as f64) } {
let mut balance: Value = self.safe_dict(spotBalances.clone(), i.clone(), &[]);
let mut currencyId: Value = self.safe_string_k(balance.clone(), "currency", &[]);
let mut code: Value = self.safe_currency_code(currencyId, &[]);
let mut account: Value = self.account();
if let Value::Dict(__d) = &mut account { std::sync::Arc::make_mut(__d).insert("total".into(), self.safe_string_k(balance, "balance", &[])); }
if let Value::Dict(__d) = &mut account { std::sync::Arc::make_mut(__d).insert("free".into(), availableBalance.clone()); }; // todo: revise after API team clarification
if (code != Value::Null) {
if let Value::Dict(__d) = &mut result { std::sync::Arc::make_mut(__d).insert(crate::runtime::stringify_param(&code), account); }
}
}
}
return self.safe_balance(result);
Value::Null
}
/*
* @method
* @name grvt#fetchDeposits
* @description fetch all deposits made to an account
* @see https://api-docs.grvt.io/trading_api/#transfer
* @param {string} [code] unified currency code
* @param {int} [since] the earliest time in ms to fetch deposits for
* @param {int} [limit] the maximum number of deposits structures to retrieve
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {int} [params.until] timestamp in ms of the latest item
* @returns {object[]} a list of [transaction structures]{@link https://docs.ccxt.com/?id=transaction-structure}
*/
pub async fn fetch_deposits(&mut self, optional_args: &[Value]) -> Value {
let mut code = 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
}));
self.load_markets_and_sign_in().await;
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut currency: Value = Value::Null;
if (code != Value::Null) {
currency = self.currency(code);
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("currency".into(), Value::from(vec![currency.as_map().and_then(|__m| __m.get("code")).cloned().unwrap_or(Value::Null)])); }
}
if (limit != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("limit".into(), crate::runtime::Math::min(&limit, &Value::Int(1000))); }
}
let mut requestUntilOptionStringparamsUntilOptionStringVariable = self.handle_until_option_string(Value::Str("end_time".into()), request, &[params, Value::Int(1000000)]);
let mut requestUntilOptionString: Value = requestUntilOptionStringparamsUntilOptionStringVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsUntilOptionString: Value = requestUntilOptionStringparamsUntilOptionStringVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
if (since != Value::Null) {
add_element_to_object(&mut requestUntilOptionString, &Value::Str("start_time".into()), self.number_to_string((match (&(since), &(Value::Int(1000000))) { (Value::Int(x), Value::Int(y)) => Value::Int(x * y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 * *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x * *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x * y), _ => Value::Null })));
}
let mut useTransfersEndpoint: Value = self.safe_bool_k(self.options.clone(), "useTransfersEndpointForDepositsWithdrawals", &[Value::Bool(true)]);
if (useTransfersEndpoint.as_bool() == Some(true)) {
let __ws_arg_9 = self.extend(requestUntilOptionString.clone(), &[paramsUntilOptionString.clone()]);
let mut transfers: Value = self.internal_fetch_transfers(__ws_arg_9, &[currency.clone(), since.clone(), limit.clone()]).await;
let mut filteredResults: Value = self.filter_transfers_by_type(transfers, Value::Str("deposit".into()), &[Value::Bool(true)]);
let mut transactions: Value = self.get_list_from_object_values(get_value(&filteredResults, &Value::Int(0)), Value::Str("info".into()));
return self.parse_transactions(transactions, &[currency.clone(), since.clone(), limit.clone()]);
} else {
let __ws_arg_10 = self.extend(requestUntilOptionString, &[paramsUntilOptionString]);
let mut response: Value = self.private_trading_post_full_v1_deposit_history(&[__ws_arg_10]).await;
//
// {
// "result": [{
// "l_1_hash": "0x10000101000203040506",
// "l_2_hash": "0x10000101000203040506",
// "to_account_id": "0xc73c0c2538fd9b833d20933ccc88fdaa74fcb0d0",
// "currency": "USDT",
// "num_tokens": "1500.0",
// "initiated_time": "1697788800000000000",
// "confirmed_time": "1697788800000000000",
// "from_address": "0xc73c0c2538fd9b833d20933ccc88fdaa74fcb0d0"
// }],
// "next": "Qw0918="
// }
//
let mut result: Value = self.safe_list_k(response, "result", &[Value::from(vec![])]);
return self.parse_transactions(result, &[currency, since, limit]);
}
Value::Null
}
/*
* @method
* @name grvt#fetchWithdrawals
* @description fetch all withdrawals made from an account
* @see https://api-docs.grvt.io/trading_api/#withdrawal-history
* @param {string} [code] unified currency code of the currency transferred
* @param {int} [since] the earliest time in ms to fetch transfers for (default 24 hours ago)
* @param {int} [limit] the maximum number of transfer structures to retrieve (default 50, max 200)
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {int} [params.until] timestamp in ms of the latest item
* @returns {object[]} a list of [transaction structures]{@link https://docs.ccxt.com/?id=transaction-structure}
*/
pub async fn fetch_withdrawals(&mut self, optional_args: &[Value]) -> Value {
let mut code = 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
}));
self.load_markets_and_sign_in().await;
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut currency: Value = Value::Null;
if (code == Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("currency".into(), Value::Null); }
} else {
currency = self.currency(code);
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("currency".into(), Value::from(vec![currency.as_map().and_then(|__m| __m.get("code")).cloned().unwrap_or(Value::Null)])); }
}
if (limit != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("limit".into(), crate::runtime::Math::min(&limit, &Value::Int(1000))); }
}
let mut requestUntilOptionStringparamsUntilOptionStringVariable = self.handle_until_option_string(Value::Str("end_time".into()), request, &[params, Value::Int(1000000)]);
let mut requestUntilOptionString: Value = requestUntilOptionStringparamsUntilOptionStringVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsUntilOptionString: Value = requestUntilOptionStringparamsUntilOptionStringVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
if (since != Value::Null) {
add_element_to_object(&mut requestUntilOptionString, &Value::Str("start_time".into()), self.number_to_string((match (&(since), &(Value::Int(1000000))) { (Value::Int(x), Value::Int(y)) => Value::Int(x * y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 * *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x * *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x * y), _ => Value::Null })));
}
let mut useTransfersEndpoint: Value = self.safe_bool_k(self.options.clone(), "useTransfersEndpointForDepositsWithdrawals", &[Value::Bool(true)]);
if (useTransfersEndpoint.as_bool() == Some(true)) {
let __ws_arg_11 = self.extend(requestUntilOptionString.clone(), &[paramsUntilOptionString.clone()]);
let mut transfers: Value = self.internal_fetch_transfers(__ws_arg_11, &[currency.clone(), since.clone(), limit.clone()]).await;
let mut filteredResults: Value = self.filter_transfers_by_type(transfers, Value::Str("withdrawal".into()), &[Value::Bool(true)]);
let mut transactions: Value = self.get_list_from_object_values(get_value(&filteredResults, &Value::Int(0)), Value::Str("info".into()));
return self.parse_transactions(transactions, &[currency.clone(), since.clone(), limit.clone()]);
} else {
let __ws_arg_12 = self.extend(requestUntilOptionString, &[paramsUntilOptionString]);
let mut response: Value = self.private_trading_post_full_v1_withdrawal_history(&[__ws_arg_12]).await;
//
// {
// "result": [{
// "tx_id": "1028403",
// "from_account_id": "0xc73c0c2538fd9b833d20933ccc88fdaa74fcb0d0",
// "to_eth_address": "0xc73c0c2538fd9b833d20933ccc88fdaa74fcb0d0",
// "currency": "USDT",
// "num_tokens": "1500.0",
// "signature": {
// "signer": "0xc73c0c2538fd9b833d20933ccc88fdaa74fcb0d0",
// "r": "0xb788d96fee91c7cdc35918e0441b756d4000ec1d07d900c73347d9abbc20acc8",
// "s": "0x3d786193125f7c29c958647da64d0e2875ece2c3f845a591bdd7dae8c475e26d",
// "v": 28,
// "expiration": "1697788800000000000",
// "nonce": 1234567890,
// "chain_id": "325"
// },
// "event_time": "1697788800000000000",
// "l_1_hash": "0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef",
// "l_2_hash": "0xabcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890"
// }],
// "next": "Qw0918="
// }
//
let mut result: Value = self.safe_list_k(response, "result", &[Value::from(vec![])]);
return self.parse_transactions(result, &[currency, since, limit]);
}
Value::Null
}
pub async fn internal_fetch_transfers(&mut self, mut req: Value, optional_args: &[Value]) -> Value {
let mut currency = 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 response: Value = self.private_trading_post_full_v1_transfer_history(&[req]).await;
//
// {
// "result": [
// {
// "tx_id": "65119836",
// "from_account_id": "0xc451b0191351ce308fdfd779d73814c910fc5ecb",
// "from_sub_account_id": "0",
// "to_account_id": "0x42c9f56f2c9da534f64b8806d64813b29c62a01d",
// "to_sub_account_id": "0",
// "currency": "USDT",
// "num_tokens": "4.998",
// "signature": {
// "signer": "0xf4fdbaf9655bfd607098f4f887aaca58c9667203",
// "r": "0x5f780b99e5e8516f85e66af49b469eeeeeee724290d7f49f1e84b25ad038fa81",
// "s": "0x66c76fdb37a25db8c6b368625d96ee91ab1ffca1786d84dc806b08d1460e97bc",
// "v": "27",
// "expiration": "1767455807929000000",
// "nonce": "45905",
// "chain_id": "0"
// },
// "event_time": "1764863808817370541",
// "transfer_type": "NON_NATIVE_BRIDGE_DEPOSIT",
// "transfer_metadata": "{\\"provider\\":\\"rhino\\",\\"direction\\":\\"deposit\\",\\"chainid\\":\\"8453\\",\\"endpoint\\":\\"0x01b89ac919ead1bd513b548962075137c683b9ab\\",\\"provider_tx_id\\":\\"0x1dff8c839f8e21b5af7e121a1ae926017e734aafe8c4ae9942756b3091793b4f\\",\\"provider_ref_id\\":\\"6931aefa5f1ab6fcf0d2f856\\"}"
// },
// ...
// ],
// "next": ""
// }
//
let mut rows: Value = self.safe_list_k(response, "result", &[Value::from(vec![])]);
let mut transfers: Value = self.parse_transfers(rows, &[currency, since, limit]);
return transfers;
Value::Null
}
pub fn parse_transaction(&self, mut transaction: Value, optional_args: &[Value]) -> Value {
let mut currency = get_arg(optional_args, 0, Value::Null);
//
// fetchDeposits
//
// {
// "l_1_hash": "0x10000101000203040506",
// "l_2_hash": "0x10000101000203040506",
// "to_account_id": "0xc73c0c2538fd9b833d20933ccc88fdaa74fcb0d0",
// "currency": "USDT",
// "num_tokens": "1500.0",
// "initiated_time": "1697788800000000000",
// "confirmed_time": "1697788800000000000",
// "from_address": "0xc73c0c2538fd9b833d20933ccc88fdaa74fcb0d0"
// }
//
// fetchWithdrawals
//
// {
// "tx_id": "1028403",
// "from_account_id": "0xc73c0c2538fd9b833d20933ccc88fdaa74fcb0d0",
// "to_eth_address": "0xc73c0c2538fd9b833d20933ccc88fdaa74fcb0d0",
// "currency": "USDT",
// "num_tokens": "1500.0",
// "signature": {
// "signer": "0xc73c0c2538fd9b833d20933ccc88fdaa74fcb0d0",
// "r": "0xb788d96fee91c7cdc35918e0441b756d4000ec1d07d900c73347d9abbc20acc8",
// "s": "0x3d786193125f7c29c958647da64d0e2875ece2c3f845a591bdd7dae8c475e26d",
// "v": 28,
// "expiration": "1697788800000000000",
// "nonce": 1234567890,
// "chain_id": "325"
// },
// "event_time": "1697788800000000000",
// "l_1_hash": "0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef",
// "l_2_hash": "0xabcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890"
// }
//
// fetchTransfers
//
// {
// "tx_id": "65119836",
// "from_account_id": "0xc451b0191351ce308fdfd779d73814c910fc5ecb",
// "from_sub_account_id": "0",
// "to_account_id": "0x42c9f56f2c9da534f64b8806d64813b29c62a01d",
// "to_sub_account_id": "0",
// "currency": "USDT",
// "num_tokens": "4.998",
// "signature": {
// "signer": "0xf4fdbaf9655bfd607098f4f887aaca58c9667203",
// "r": "0x5f780b99e5e8516f85e66af49b469eeeeeee724290d7f49f1e84b25ad038fa81",
// "s": "0x66c76fdb37a25db8c6b368625d96ee91ab1ffca1786d84dc806b08d1460e97bc",
// "v": "27",
// "expiration": "1767455807929000000",
// "nonce": "45905",
// "chain_id": "0"
// },
// "event_time": "1764863808817370541",
// "transfer_type": "NON_NATIVE_BRIDGE_DEPOSIT",
// "transfer_metadata": "{\\"provider\\":\\"rhino\\",\\"direction\\":\\"deposit\\",\\"chainid\\":\\"8453\\",\\"endpoint\\":\\"0x01b89ac919ead1bd513b548962075137c683b9ab\\",\\"provider_tx_id\\":\\"0x1dff8c839f8e21b5af7e121a1ae926017e734aafe8c4ae9942756b3091793b4f\\",\\"provider_ref_id\\":\\"6931aefa5f1ab6fcf0d2f856\\"}"
// },
//
// withdraw
//
// {
// "result": {
// "ack": "true"
// }
// }
//
let mut direction: Value = Value::Null;
let mut txId: Value = Value::Null;
let mut networkCode: Value = Value::Null;
let mut addressFrom: Value = self.safe_string_k(transaction.clone(), "from_account_id", &[]);
let mut addressTo: Value = self.safe_string_k(transaction.clone(), "to_account_id", &[]);
let mut currencyId: Value = self.safe_string_k(transaction.clone(), "currency", &[]);
let mut code: Value = self.safe_currency_code(currencyId, &[currency]);
if (matches!(&transaction, Value::Dict(__d) if __d.contains_key("transfer_metadata"))) {
let mut metaData: Value = self.omit_zero(self.safe_string_k(transaction.clone(), "transfer_metadata", &[]));
if (metaData != Value::Null) {
let mut parsedMeta: Value = self.parse_json_value(metaData);
direction = self.safe_string_lower_k(parsedMeta.clone(), "direction", &[]);
txId = self.safe_string_k(parsedMeta.clone(), "provider_tx_id", &[]);
networkCode = self.network_id_to_code(&[self.safe_string_k(parsedMeta.clone(), "chainid", &[]), code.clone()]);
if (direction.as_str() == Some("withdrawal")) {
addressTo = self.safe_string_k(parsedMeta.clone(), "endpoint", &[]);
} else if (direction.as_str() == Some("deposit")) {
addressFrom = self.safe_string_k(parsedMeta, "endpoint", &[]);
}
}
}
let mut timestamp: Value = self.safe_integer_product2(transaction.clone(), Value::Str("event_time".into()), Value::Str("initiated_time".into()), Value::Float(0.000001), &[]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), transaction.clone());
m.insert("id".to_string(), Value::Null);
m.insert("txid".to_string(), txId);
m.insert("type".to_string(), direction);
m.insert("currency".to_string(), code);
m.insert("network".to_string(), networkCode);
m.insert("amount".to_string(), self.safe_number_k(transaction, "num_tokens", &[]));
m.insert("status".to_string(), Value::Null);
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp));
m.insert("address".to_string(), Value::Null);
m.insert("addressFrom".to_string(), addressFrom);
m.insert("addressTo".to_string(), addressTo);
m.insert("tag".to_string(), Value::Null);
m.insert("tagFrom".to_string(), Value::Null);
m.insert("tagTo".to_string(), Value::Null);
m.insert("updated".to_string(), Value::Null);
m.insert("comment".to_string(), Value::Null);
m.insert("fee".to_string(), Value::Null);
m
});
Value::Null
}
/*
* @method
* @name grvt#fetchTransfers
* @description fetch a history of internal transfers made on an account
* @see https://api-docs.grvt.io/trading_api/#transfer-history
* @param {string} code unified currency code of the currency transferred
* @param {int} [since] the earliest time in ms to fetch transfers for
* @param {int} [limit] the maximum number of transfers structures to retrieve (default 10, max 100)
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {boolean} [params.paginate] whether to paginate the results (default false)
* @returns {object[]} a list of [transfer structures]{@link https://docs.ccxt.com/?id=transfer-structure}
*/
pub async fn fetch_transfers(&mut self, optional_args: &[Value]) -> Value {
let mut code = 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
}));
if (code == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" fetchTransfers() requires a code argument".into()))));
}
self.load_markets_and_sign_in().await;
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut currency: Value = self.currency(code);
let mut maxLimit: Value = Value::Int(1000);
let mut paginateparamsPaginateVariable = self.handle_option_bool_and_params(params, Value::Str("fetchTransfers".into()), Value::Str("paginate".into()), &[Value::Bool(false)]);
let mut paginate: Value = paginateparamsPaginateVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsPaginate: Value = paginateparamsPaginateVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
if is_true(&paginate) {
return self.fetch_paginated_call_dynamic(Value::Str("fetchTransfers".into()), &[Value::Null, since.clone(), limit.clone(), paramsPaginate.clone(), maxLimit]).await;
}
if (limit != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("limit".into(), crate::runtime::Math::min(&limit, &Value::Int(1000))); }
}
let mut requestUntilOptionStringparamsUntilOptionStringVariable = self.handle_until_option_string(Value::Str("end_time".into()), request, &[paramsPaginate, Value::Int(1000000)]);
let mut requestUntilOptionString: Value = requestUntilOptionStringparamsUntilOptionStringVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsUntilOptionString: Value = requestUntilOptionStringparamsUntilOptionStringVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
if (since != Value::Null) {
add_element_to_object(&mut requestUntilOptionString, &Value::Str("start_time".into()), self.number_to_string((match (&(since), &(Value::Int(1000000))) { (Value::Int(x), Value::Int(y)) => Value::Int(x * y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 * *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x * *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x * y), _ => Value::Null })));
}
let __ws_arg_13 = self.extend(requestUntilOptionString, &[paramsUntilOptionString]);
let mut response: Value = self.private_trading_post_full_v1_transfer_history(&[__ws_arg_13]).await;
//
// {
// "result": [
// {
// "tx_id": "65119836",
// "from_account_id": "0xc451b0191351ce308fdfd779d73814c910fc5ecb",
// "from_sub_account_id": "0",
// "to_account_id": "0x42c9f56f2c9da534f64b8806d64813b29c62a01d",
// "to_sub_account_id": "0",
// "currency": "USDT",
// "num_tokens": "4.998",
// "signature": {
// "signer": "0xf4fdbaf9655bfd607098f4f887aaca58c9667203",
// "r": "0x5f780b99e5e8516f85e66af49b469eeeeeee724290d7f49f1e84b25ad038fa81",
// "s": "0x66c76fdb37a25db8c6b368625d96ee91ab1ffca1786d84dc806b08d1460e97bc",
// "v": "27",
// "expiration": "1767455807929000000",
// "nonce": "45905",
// "chain_id": "0"
// },
// "event_time": "1764863808817370541",
// "transfer_type": "NON_NATIVE_BRIDGE_DEPOSIT",
// "transfer_metadata": "{\\"provider\\":\\"rhino\\",\\"direction\\":\\"deposit\\",\\"chainid\\":\\"8453\\",\\"endpoint\\":\\"0x01b89ac919ead1bd513b548962075137c683b9ab\\",\\"provider_tx_id\\":\\"0x1dff8c839f8e21b5af7e121a1ae926017e734aafe8c4ae9942756b3091793b4f\\",\\"provider_ref_id\\":\\"6931aefa5f1ab6fcf0d2f856\\"}"
// },
// ...
// ],
// "next": ""
// }
//
let mut rows: Value = self.safe_list_k(response, "result", &[Value::from(vec![])]);
let mut transfers: Value = self.parse_transfers(rows, &[currency, since, limit]);
let mut filteredResults: Value = self.filter_transfers_by_type(transfers, Value::Str("internal".into()), &[Value::Bool(false)]);
return get_value(&filteredResults, &Value::Int(1));
Value::Null
}
pub fn filter_transfers_by_type(&self, mut transfers: Value, mut transferType: Value, optional_args: &[Value]) -> Value {
let mut onlyMainAccount = get_arg(optional_args, 0, Value::Bool(true));
let mut matchedResults: Value = Value::from(vec![]);
let mut nonMatchedResults: Value = Value::from(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_723: bool = true;
while { if !__for_first_723 { i = (match (&(i), &(Value::Int(1))) { (Value::Int(x), Value::Int(y)) => Value::Int(x + y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 + *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x + *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x + y), _ => Value::Null }); } __for_first_723 = false; i.as_f64().unwrap_or(f64::NAN) < get_array_length(&transfers).as_f64().unwrap_or(f64::NAN) } {
let mut transfer: Value = get_value(&transfers, &i);
let mut transfer: Value = get_value(&transfers, &i);
if (is_true(&onlyMainAccount) && (self.safe_string_k(transfer.clone(), "fromAccount", &[]).as_str() == Some("0")) && (self.safe_string_k(transfer.clone(), "toAccount", &[]).as_str() == Some("0"))) || (!is_true(&onlyMainAccount) && ((self.safe_string_k(transfer.clone(), "fromAccount", &[]).as_str() != Some("0")) || (self.safe_string_k(transfer.clone(), "toAccount", &[]).as_str() != Some("0")))) {
let mut metadata: Value = self.safe_string_k(crate::value::get_value_k(&transfer, "info"), "transfer_metadata", &[]);
let mut parsedMetadata: Value = self.parse_json_value(metadata);
let mut direction: Value = self.safe_string_k(parsedMetadata, "direction", &[]);
if (direction.as_str() == transferType.as_str()) {
append_to_array(&mut matchedResults, transfer.clone());
} else {
append_to_array(&mut nonMatchedResults, transfer);
}
}
}
}
return Value::from(vec![matchedResults, nonMatchedResults]);
Value::Null
}
/*
* @method
* @name grvt#transfer
* @description transfer currency internally between wallets on the same account
* @see https://api-docs.grvt.io/trading_api/#transfer_1
* @param {string} code unified currency codeåå
* @param {float} amount amount to transfer
* @param {string} fromAccount account to transfer from
* @param {string} toAccount account to transfer to
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a [transfer structure]{@link https://docs.ccxt.com/?id=transfer-structure}
*/
pub async fn transfer(&mut self, mut code: Value, mut amount: Value, mut fromAccount: Value, mut toAccount: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
self.load_markets_and_sign_in().await;
let mut currency: Value = self.currency(code.clone());
let mut defaultFromAccountId: Value = self.safe_string_k(self.options.clone(), "userMainAccountId", &[]);
let mut isInternal: bool = is_true(&self.in_array(fromAccount.clone(), Value::from(vec![Value::Str("trading".into()), Value::Str("funding".into())]))) && self.in_array(toAccount.clone(), Value::from(vec![Value::Str("trading".into()), Value::Str("funding".into())])).as_bool() == Some(true);
let mut fromSubAccount: Value = fromAccount.clone();
let mut toSubAccount: Value = toAccount.clone();
let mut paramsFundingAccountId: Value = params.clone();
if isInternal {
let mut tradingAccountIdparamsTradingAccountIdVariable = self.handle_option_string_and_params(params, Value::Str("transfer".into()), Value::Str("tradingAccountId".into()), &[]);
let mut tradingAccountId: Value = tradingAccountIdparamsTradingAccountIdVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsTradingAccountId: Value = tradingAccountIdparamsTradingAccountIdVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
let mut fundingAccountIdparamsFundingVariable = self.handle_option_string_and_params(paramsTradingAccountId, Value::Str("transfer".into()), Value::Str("fundingAccountId".into()), &[]);
let mut fundingAccountId: Value = fundingAccountIdparamsFundingVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsFunding: Value = fundingAccountIdparamsFundingVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
if (tradingAccountId == Value::Null) || (fundingAccountId == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" transfer(): you should set (in the options or params) \"tradingAccountId\" and \"fundingAccountId\" (you can use \"0\" as a main funding account id)".into()))));
}
fromSubAccount = (if (fromAccount.as_str() == Some("trading")) { tradingAccountId.clone() } else { fundingAccountId.clone() });
toSubAccount = (if (toAccount.as_str() == Some("trading")) { tradingAccountId } else { fundingAccountId });
paramsFundingAccountId = paramsFunding;
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("from_account_id".to_string(), self.safe_string_k(paramsFundingAccountId.clone(), "from_account_id", &[defaultFromAccountId.clone()]));
m.insert("from_sub_account_id".to_string(), self.safe_string_k(paramsFundingAccountId.clone(), "from_sub_account_id", &[fromSubAccount.clone()]));
m.insert("to_account_id".to_string(), self.safe_string_k(paramsFundingAccountId.clone(), "to_account_id", &[defaultFromAccountId]));
m.insert("to_sub_account_id".to_string(), self.safe_string_k(paramsFundingAccountId.clone(), "to_sub_account_id", &[toSubAccount]));
m.insert("currency".to_string(), currency.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m.insert("num_tokens".to_string(), self.currency_to_precision(code, amount, &[]));
m.insert("signature".to_string(), self.default_signature());
m.insert("transfer_type".to_string(), Value::Str("STANDARD".into()));
m.insert("transfer_metadata".to_string(), Value::Null);
m
});
request = self.create_signed_request(request.clone(), Value::Str("EIP712_TRANSFER_TYPE".into()), &[currency.clone()]);
let mut response: Value = Value::Null;
let _try_result = futures::FutureExt::catch_unwind(std::panic::AssertUnwindSafe(async {
let __ws_arg_14 = self.extend(request, &[paramsFundingAccountId]);
response = self.private_trading_post_full_v1_transfer(&[__ws_arg_14]).await;
#[allow(unreachable_code)] { Value::Null }})).await;
if let Err(_try_err) = _try_result { let error: Value = panic_to_value(_try_err);
let mut msg: Value = self.exception_message(error.clone(), &[]);
let mut isFromFundingAccount: bool = fromSubAccount.as_str() == Some("funding");
if isFromFundingAccount && (Value::Int(msg.as_str().and_then(|__s| __s.find("You are not authorized")).map(|__i| __i as i64).unwrap_or(-1)).as_f64().unwrap_or(f64::NAN) >= ((0i64) as f64)) {
panic!("{}", crate::exchange_errors::permission_denied(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" transfer() failed. Ensure you use funding api-keys when trying to transfer from Funding accounts: ".into())).into()), msg)));
}
panic!("{}", error);
}
//
// {
// "result": {
// "ack": "true",
// "tx_id": "1028403"
// }
// }
//
let mut result: Value = self.safe_dict_k(response, "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_transfer(result, &[currency]);
Value::Null
}
pub fn parse_transfer(&self, mut transfer: Value, optional_args: &[Value]) -> Value {
let mut currency = get_arg(optional_args, 0, Value::Null);
//
// transfer
//
// {
// "ack": "true",
// "tx_id": "1028403"
// }
//
// fetchTransfers
//
// {
// "tx_id": "65119836",
// "from_account_id": "0xc451b0191351ce308fdfd779d73814c910fc5ecb",
// "from_sub_account_id": "0",
// "to_account_id": "0x42c9f56f2c9da534f64b8806d64813b29c62a01d",
// "to_sub_account_id": "0",
// "currency": "USDT",
// "num_tokens": "4.998",
// "signature": {
// "signer": "0xf4fdbaf9655bfd607098f4f887aaca58c9667203",
// "r": "0x5f780b99e5e8516f85e66af49b469eeeeeee724290d7f49f1e84b25ad038fa81",
// "s": "0x66c76fdb37a25db8c6b368625d96ee91ab1ffca1786d84dc806b08d1460e97bc",
// "v": "27",
// "expiration": "1767455807929000000",
// "nonce": "45905",
// "chain_id": "0"
// },
// "event_time": "1764863808817370541",
// "transfer_type": "NON_NATIVE_BRIDGE_DEPOSIT",
// "transfer_metadata": "{\\"provider\\":\\"rhino\\",\\"direction\\":\\"deposit\\",\\"chainid\\":\\"8453\\",\\"endpoint\\":\\"0x01b89ac919ead1bd513b548962075137c683b9ab\\",\\"provider_tx_id\\":\\"0x1dff8c839f8e21b5af7e121a1ae926017e734aafe8c4ae9942756b3091793b4f\\",\\"provider_ref_id\\":\\"6931aefa5f1ab6fcf0d2f856\\"}"
// }
//
let mut currencyId: Value = self.safe_string_k(transfer.clone(), "currency", &[]);
let mut code: Value = self.safe_currency_code(currencyId, &[currency]);
let mut timestamp: Value = self.safe_integer_product_k(transfer.clone(), "event_time", Value::Float(0.000001), &[]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), transfer.clone());
m.insert("id".to_string(), self.safe_string_k(transfer.clone(), "tx_id", &[]));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp));
m.insert("currency".to_string(), code);
m.insert("amount".to_string(), self.safe_number_k(transfer.clone(), "amount", &[]));
m.insert("fromAccount".to_string(), self.safe_string_k(transfer.clone(), "from_sub_account_id", &[]));
m.insert("toAccount".to_string(), self.safe_string_k(transfer, "to_sub_account_id", &[]));
m.insert("status".to_string(), Value::Null);
m
});
Value::Null
}
pub async fn load_account_infos(&mut self) -> Value {
if (self.safe_string_k(self.options.clone(), "userMainAccountId", &[]) != Value::Null) {
return Value::Bool(false);
}
let mut promises: Value = Value::from(vec![]);
append_to_array(&mut promises, self.private_trading_post_full_v1_aggregated_account_summary(&[]).await);
//
// {
// "result": {
// "main_account_id": "0xc73c0c2538fd9b833d20933ccc88fdaa74fcb0d0",
// "total_equity": "3945034.23",
// "spot_balances": [{
// "currency": "USDT",
// "balance": "123456.78",
// "index_price": "1.0000102"
// }],
// "vault_investments": [{
// "vault_id": 123456789,
// "num_lp_tokens": 1000000,
// "share_price": 1000000,
// "usd_notional_invested": 1000000
// }],
// "total_sub_account_balance": "3945034.23",
// "total_sub_account_equity": "3945034.23",
// "total_vault_investments_balance": "3945034.23",
// "total_sub_account_available_balance": "3945034.23",
// "total_usd_notional_invested": "3945034.23"
// }
// }
//
let mut accountIsUndefined: bool = self.safe_string_k(self.options.clone(), "accountId", &[]) == Value::Null;
if accountIsUndefined {
append_to_array(&mut promises, self.private_trading_post_full_v1_get_sub_accounts(&[]).await);
}
//
// {
// "sub_account_ids": ["4724219064482495","2095919380","1170592370"]
// }
//
let mut responses: Value = promise_all(&promises).await;
let mut result1: Value = self.safe_dict(responses.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null), Value::Str("result".into()), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut mainAccountId: Value = self.safe_string_k(result1, "main_account_id", &[]);
if let Value::Dict(__d) = &mut self.options { std::sync::Arc::make_mut(__d).insert("userMainAccountId".into(), mainAccountId); }
if accountIsUndefined {
let mut subAccountIds: Value = self.safe_list(responses.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null), Value::Str("sub_account_ids".into()), &[Value::from(vec![])]);
let mut length: f64 = ((subAccountIds.len() as i64) as f64);
if length < ((1i64) as f64) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" loadAccountInfos(): no sub accounts found, you might need to create an api-key in GRVT website".into()))));
}
if length > ((1i64) as f64) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" loadAccountInfos(): multiple sub accounts found, please set the exchange.options[\"accountId\"] to your preferred sub_account_id from this list: ".into())).into()), json_stringify(&subAccountIds))));
}
let mut subAccountId: Value = self.safe_string(subAccountIds, Value::Int(0), &[]);
if let Value::Dict(__d) = &mut self.options { std::sync::Arc::make_mut(__d).insert("accountId".into(), subAccountId); }
}
return Value::Bool(true);
Value::Null
}
/*
* @method
* @name grvt#withdraw
* @description make a withdrawal
* @see https://api-docs.grvt.io/trading_api/#withdrawal
* @param {string} code unified currency code
* @param {float} amount the amount to withdraw
* @param {string} address the address to withdraw to
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.tag] memo / destination tag, required for currencies in options['withdrawTagRequiredCurrencies']
* @param {string} params.network the network to withdraw on (mandatory)
* @returns {object} a [transaction structure]{@link https://docs.ccxt.com/?id=transaction-structure}
*/
pub async fn withdraw(&mut self, mut code: Value, mut amount: Value, mut address: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
self.check_address(&[address.clone()]);
self.load_markets_and_sign_in().await;
let mut defaultFromAccountId: Value = self.safe_string_k(self.options.clone(), "userMainAccountId", &[]);
let mut currency: Value = self.currency(code.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("to_eth_address".to_string(), address);
m.insert("from_account_id".to_string(), defaultFromAccountId);
m.insert("currency".to_string(), currency.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m.insert("num_tokens".to_string(), self.currency_to_precision(code.clone(), amount, &[]));
m.insert("signature".to_string(), self.default_signature());
m
});
let mut networkCodequeryVariable = self.handle_network_code_and_params(params);
let mut networkCode: Value = networkCodequeryVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut query: Value = networkCodequeryVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
let mut networkId: Value = self.network_code_to_id(networkCode, &[code]);
if (networkId == Value::Null) {
panic!("{}", crate::exchange_errors::bad_request(format!("{}{}", self.id.clone(), Value::Str(" withdraw() requires a network parameter".into()))));
}
add_element_to_object(get_value_mut(&mut request, &Value::Str("signature".into())), &Value::Str("chain_id".into()), networkId);
request = self.create_signed_request(request.clone(), Value::Str("EIP712_WITHDRAWAL_TYPE".into()), &[currency.clone()]);
let __ws_arg_15 = self.extend(request, &[query]);
let mut response: Value = self.private_trading_post_full_v1_withdrawal(&[__ws_arg_15]).await;
//
// {
// "result": {
// "ack": "true"
// }
// }
//
let mut result: Value = self.safe_dict_k(response, "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_transaction(result, &[currency]);
Value::Null
}
/*
* @method
* @name grvt#createOrder
* @description create a trade order
* @see https://api-docs.grvt.io/trading_api/#create-order
* @param {string} symbol unified symbol of the market to create an order in
* @param {string} type 'market' or 'limit'
* @param {string} side 'buy' or 'sell'
* @param {float} amount how much of currency you want to trade in units of base currency
* @param {float} [price] the price at which the order is to be fullfilled, in units of the quote currency, ignored in market orders
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {float} [params.triggerPrice] The price a trigger order is triggered at
* @param {float} [params.stopLossPrice] The price a stop loss order is triggered at
* @param {float} [params.takeProfitPrice] The price a take profit order is triggered at
* @param {string} [params.timeInForce] "GTC", "IOC", or "POST_ONLY"
* @param {bool} [params.postOnly] true or false
* @param {bool} [params.reduceOnly] Ensures that the executed order does not flip the opened position.
* @param {string} [params.clientOrderId] a unique id for the order
* @returns {object} an [order structure]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn create_order(&mut self, mut symbol: Value, mut type_var: Value, mut side: Value, mut amount: Value, optional_args: &[Value]) -> Value {
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
}));
self.load_markets_and_sign_in().await;
let mut market: Value = self.market(symbol.clone());
let mut orderLeg: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("instrument".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m.insert("size".to_string(), self.amount_to_precision(symbol.clone(), amount));
m
});
if (price != Value::Null) {
if let Value::Dict(__d) = &mut orderLeg { std::sync::Arc::make_mut(__d).insert("limit_price".into(), self.price_to_precision(symbol.clone(), price)); }
} else {
if let Value::Dict(__d) = &mut orderLeg { std::sync::Arc::make_mut(__d).insert("limit_price".into(), Value::Null); }
}
if (side.as_str() == Some("sell")) {
if let Value::Dict(__d) = &mut orderLeg { std::sync::Arc::make_mut(__d).insert("is_buying_asset".into(), Value::Bool(false)); }
} else if (side.as_str() == Some("buy")) {
if let Value::Dict(__d) = &mut orderLeg { std::sync::Arc::make_mut(__d).insert("is_buying_asset".into(), Value::Bool(true)); }
} else {
panic!("{}", crate::exchange_errors::invalid_order(format!("{}{}", self.id.clone(), Value::Str(" createOrder(): order side must be either \"buy\" or \"sell\"".into()))));
}
let mut clientOrderId: Value = self.safe_string_k(params.clone(), "clientOrderId", &[]);
if (clientOrderId == Value::Null) {
clientOrderId = Value::Str(format!("{}{}", Value::Str(format!("{}{}", to_string_val(&self.nonce()), Value::Str("000".into())).into()), to_string_val(&self.request_id())).into());
}
let mut paramsOmitted3: Value = self.omit(params, Value::from(vec![Value::Str("clientOrderId".into())]), &[]);
let mut isMarketOrder: Value = (Value::Bool(type_var.as_str() == Some("market")));
let mut subAccountId: Value = self.get_sub_account_id(paramsOmitted3.clone());
let mut isReduceOnly: Value = self.safe_bool_k(paramsOmitted3.clone(), "reduceOnly", &[Value::Bool(false)]);
let mut orderRequest: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("sub_account_id".to_string(), subAccountId);
m.insert("time_in_force".to_string(), Value::Null);
m.insert("legs".to_string(), Value::from(vec![orderLeg]));
m.insert("signature".to_string(), self.default_signature());
m.insert("metadata".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("client_order_id".to_string(), clientOrderId);
m
}));
m.insert("is_market".to_string(), isMarketOrder.clone());
m.insert("post_only".to_string(), Value::Bool(false));
m.insert("reduce_only".to_string(), isReduceOnly);
m
});
let mut timeInForce: Value = self.safe_string_upper_k(paramsOmitted3.clone(), "timeInForce", &[Value::Str("GOOD_TILL_TIME".into())]);
let mut postOnly: Value = self.is_post_only(isMarketOrder.clone(), Value::Null, &[paramsOmitted3.clone()]);
if is_true(&postOnly) {
if let Value::Dict(__d) = &mut orderRequest { std::sync::Arc::make_mut(__d).insert("post_only".into(), Value::Bool(true)); }
}
if (timeInForce == Value::Null) {
timeInForce = Value::Str("GOOD_TILL_TIME".into());
} else {
let mut tifMap: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("GTC".to_string(), Value::Str("GOOD_TILL_TIME".into()));
m.insert("FOK".to_string(), Value::Str("FILL_OR_KILL".into()));
m.insert("IOC".to_string(), Value::Str("IMMEDIATE_OR_CANCEL".into()));
m
});
timeInForce = self.safe_string(tifMap, timeInForce.clone(), &[timeInForce.clone()]);
}
if let Value::Dict(__d) = &mut orderRequest { std::sync::Arc::make_mut(__d).insert("time_in_force".into(), timeInForce.clone()); }
if !(matches!(&isMarketOrder, Value::Bool(true))) {
if is_true(&postOnly) {
timeInForce = Value::Str("POST_ONLY".into());
} else if (timeInForce.as_str() == Some("ioc")) {
timeInForce = Value::Str("IMMEDIATE_OR_CANCEL".into());
}
}
let mut paramsOmitted2: Value = self.omit(paramsOmitted3, Value::from(vec![Value::Str("reduceOnly".into()), Value::Str("postOnly".into()), Value::Str("timeInForce".into())]), &[]);
// Trigger & SL & TP
let mut triggerPricestopLossPricetakeProfitPriceparamsTriggerPricesVariable = self.handle_trigger_prices_and_params(symbol, paramsOmitted2, &[]);
let mut triggerPrice: Value = triggerPricestopLossPricetakeProfitPriceparamsTriggerPricesVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut stopLossPrice: Value = triggerPricestopLossPricetakeProfitPriceparamsTriggerPricesVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
let mut takeProfitPrice: Value = triggerPricestopLossPricetakeProfitPriceparamsTriggerPricesVariable.as_array().and_then(|__arr| __arr.get(2)).cloned().unwrap_or(Value::Null);
let mut paramsTriggerPrices: Value = triggerPricestopLossPricetakeProfitPriceparamsTriggerPricesVariable.as_array().and_then(|__arr| __arr.get(3)).cloned().unwrap_or(Value::Null);
let mut isTriggerOrder: bool = (triggerPrice != Value::Null) || (stopLossPrice != Value::Null) || (takeProfitPrice != Value::Null);
if isTriggerOrder {
// trigger price
let mut selectedPrice: Value = Value::Null;
if (triggerPrice != Value::Null) {
selectedPrice = triggerPrice;
} else if (stopLossPrice != Value::Null) {
selectedPrice = stopLossPrice.clone();
} else if (takeProfitPrice != Value::Null) {
selectedPrice = takeProfitPrice.clone();
}
// trigger type
let mut selectedType: Value = Value::Null;
let mut isBuy: bool = side.as_str() == Some("buy");
if (stopLossPrice != Value::Null) {
selectedType = (if isBuy { Value::Str("STOP_LOSS".into()) } else { Value::Str("TAKE_PROFIT".into()) });
} else if (takeProfitPrice != Value::Null) {
selectedType = (if isBuy { Value::Str("TAKE_PROFIT".into()) } else { Value::Str("STOP_LOSS".into()) });
} else {
let mut triggerDirection: Option<String> = self.safe_string_k(paramsTriggerPrices.clone(), "triggerDirection", &[]).as_str().map(str::to_owned);
if (triggerDirection.is_none()) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" createOrder() requires a triggerDirection parameter when triggerPrice is specified, must be \"ascending\" or \"descending\"".into()))));
}
if (triggerDirection.is_some()) {
if (triggerDirection.as_deref() == Some("ascending")) {
selectedType = (if isBuy { Value::Str("STOP_LOSS".into()) } else { Value::Str("TAKE_PROFIT".into()) });
} else if (triggerDirection.as_deref() == Some("descending")) {
selectedType = (if isBuy { Value::Str("TAKE_PROFIT".into()) } else { Value::Str("STOP_LOSS".into()) });
}
}
}
// trigger by
let mut triggerPriceType: Value = self.safe_string_upper_k(paramsTriggerPrices.clone(), "triggerPriceType", &[Value::Str("LAST".into())]);
add_element_to_object(get_value_mut(&mut orderRequest, &Value::Str("metadata".into())), &Value::Str("trigger".into()), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("trigger_type".to_string(), selectedType);
m.insert("tpsl".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("trigger_by".to_string(), triggerPriceType);
m.insert("trigger_price".to_string(), selectedPrice);
m.insert("close_position".to_string(), self.safe_bool_k(paramsTriggerPrices.clone(), "closePosition", &[Value::Bool(false)]));
m
}));
m
}));
}
let mut paramsTrigger: Value = paramsTriggerPrices.clone();
if isTriggerOrder {
paramsTrigger = self.omit(paramsTriggerPrices, Value::from(vec![Value::Str("triggerDirection".into()), Value::Str("triggerPriceType".into()), Value::Str("closePosition".into())]), &[]);
}
let mut eipType: Value = Value::Str("EIP712_ORDER_TYPE".into());
let mut builderFee: Value = self.safe_bool_k(paramsTrigger.clone(), "builderFee", &[self.safe_bool(self.options.clone(), Value::Str("builderFee".into()), &[Value::Bool(true)])]);
if (builderFee.as_bool() == Some(true)) {
eipType = Value::Str("EIP712_ORDER_WITH_BUILDER_TYPE".into());
if let Value::Dict(__d) = &mut orderRequest { std::sync::Arc::make_mut(__d).insert("builder".into(), self.safe_string_k(self.options.clone(), "builder", &[])); }
if let Value::Dict(__d) = &mut orderRequest { std::sync::Arc::make_mut(__d).insert("builder_fee".into(), self.safe_string_k(self.options.clone(), "builderRate", &[])); }
}
let mut paramsOmitted: Value = self.omit(paramsTrigger, Value::from(vec![Value::Str("builderFee".into())]), &[]);
let mut signedOrderRequest: Value = self.create_signed_request(orderRequest, eipType, &[]);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("order".to_string(), signedOrderRequest);
m
});
let __ws_arg_16 = self.extend(request, &[paramsOmitted]);
let mut response: Value = self.private_trading_post_full_v1_create_order(&[__ws_arg_16]).await;
//
// {
// "result": {
// "order_id": "0x00",
// "sub_account_id": "2147050003876484",
// "is_market": false,
// "time_in_force": "GOOD_TILL_TIME",
// "post_only": false,
// "reduce_only": false,
// "legs": [
// {
// "instrument": "BTC_USDT_Perp",
// "size": "0.001",
// "limit_price": "50000.0",
// "is_buying_asset": true
// }
// ],
// "signature": {
// "signer": "0xbf465e6083a43b170791ea29393f60...",
// "r": "0x161826bc2fc43e07b4c1e4aeb01b3e58901f936af10b399e...",
// "s": "0x1b6d09609430ef73cb53dd87dbe73939824409296b3673719...",
// "v": 27,
// "expiration": "1766076771082000000",
// "nonce": 1766076671,
// "chain_id": "0"
// },
// "metadata": {
// "client_order_id": "1766076671",
// "create_time": "1766076671243762741",
// "trigger": {
// "trigger_type": "UNSPECIFIED",
// "tpsl": {
// "trigger_by": "UNSPECIFIED",
// "trigger_price": "0.0",
// "close_position": false
// }
// },
// "broker": "UNSPECIFIED",
// "is_position_transfer": false,
// "allow_crossing": false
// },
// "state": {
// "status": "PENDING",
// "reject_reason": "UNSPECIFIED",
// "book_size": [
// "0.001"
// ],
// "traded_size": [
// "0.0"
// ],
// "update_time": "1766076671243762741",
// "avg_fill_price": [
// "0.0"
// ]
// },
// "builder": "0x00",
// "builder_fee": "0.0"
// }
// }
//
let mut data: Value = self.safe_dict_k(response, "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_order(data, &[market]);
Value::Null
}
pub fn convert_to_big_int_custom(&self, mut x: Value) -> Value {
return crate::runtime::parse_int(&x);
Value::Null
}
pub fn eip_message_for_order(&self, mut order: Value, mut structureType: Value) -> Value {
let __order_empty = indexmap::IndexMap::new();
let order = order.as_map().unwrap_or(&__order_empty);
let mut priceMultiplier: Value = Value::Str("1000000000".into());
let mut orderLegs: Value = (match order.get("legs") { Some(__v) if matches!(__v, Value::Arr(_)) => __v.clone(), _ => Value::from(vec![]) });
let mut legs: Value = Value::from(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_724: bool = true;
while { if !__for_first_724 { i = (match (&(i), &(Value::Int(1))) { (Value::Int(x), Value::Int(y)) => Value::Int(x + y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 + *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x + *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x + y), _ => Value::Null }); } __for_first_724 = false; i.as_f64().unwrap_or(f64::NAN) < ((orderLegs.len() as i64) as f64) } {
let mut leg: Value = orderLegs.as_array().and_then(|__arr| match &i { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null);
let mut market: Value = self.market(leg.as_map().and_then(|__m| __m.get("instrument")).cloned().unwrap_or(Value::Null));
let mut bigInt10: Value = self.convert_to_big_int_custom(Value::Str("10".into()));
let mut precisionValue: Value = self.precision_from_string(self.safe_string(market.as_map().and_then(|__m| __m.get("precision")).cloned().unwrap_or(Value::Null), Value::Str("base".into()), &[]));
let mut precisionValueStr: Value = to_string_val(&precisionValue);
let mut sizeMultiplier: Value = crate::runtime::Math::pow(&bigInt10, &self.convert_to_big_int_custom(precisionValueStr));
let mut size: Value = leg.as_map().and_then(|__m| __m.get("size")).cloned().unwrap_or(Value::Null);
let mut sizeParts: Value = split(&size, &Value::Str(".".into()));
let mut sizeDec: Value = self.safe_string(sizeParts, Value::Int(1), &[Value::Str("".into())]);
let mut sizeDecLength: Value = (match (&(Value::Int(sizeDec.len() as i64)), &(Value::Int(0))) { (Value::Int(x), Value::Int(y)) => Value::Int(x + y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 + *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x + *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x + y), _ => Value::Null }); // php tr
let mut sizeDecLengthStr: Value = to_string_val(&sizeDecLength);
let mut sizeInteger: Value = (match (((match (&(self.convert_to_big_int_custom(replace_str(&size, &Value::Str(".".into()), &Value::Str("".into())))), &(sizeMultiplier)) { (Value::Int(x), Value::Int(y)) => Value::Int(x * y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 * *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x * *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x * y), _ => Value::Null })).as_f64(), ((crate::runtime::Math::pow(&bigInt10, &self.convert_to_big_int_custom(sizeDecLengthStr)))).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null });
let mut legOrder: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("assetID".to_string(), crate::value::get_value_k(&market.as_map().and_then(|__m| __m.get("info")).cloned().unwrap_or(Value::Null), "instrument_hash"));
m.insert("contractSize".to_string(), self.parse_to_int(sizeInteger));
m.insert("isBuyingContract".to_string(), leg.as_map().and_then(|__m| __m.get("is_buying_asset")).cloned().unwrap_or(Value::Null));
m
});
let mut limitPrice: Value = self.safe_string_k(leg.clone(), "limit_price", &[]);
if (self.omit_zero(limitPrice) != Value::Null) {
let mut price: Value = leg.as_map().and_then(|__m| __m.get("limit_price")).cloned().unwrap_or(Value::Null);
let mut limitParts: Value = split(&price, &Value::Str(".".into()));
let mut limitDec: Value = self.safe_string(limitParts, Value::Int(1), &[Value::Str("".into())]);
let mut limitDecLength: Value = (match (&(Value::Int(limitDec.len() as i64)), &(Value::Int(0))) { (Value::Int(x), Value::Int(y)) => Value::Int(x + y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 + *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x + *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x + y), _ => Value::Null }); // php tr
let mut limitDecLengthStr: Value = to_string_val(&limitDecLength);
let mut powerNum: Value = (if (limitDecLengthStr.as_str() == Some("0")) { Value::Int(0) } else { self.convert_to_big_int_custom(limitDecLengthStr) });
let mut priceInteger: Value = ((match (((match (&(self.convert_to_big_int_custom(replace_str(&price, &Value::Str(".".into()), &Value::Str("".into())))), &(self.convert_to_big_int_custom(priceMultiplier.clone()))) { (Value::Int(x), Value::Int(y)) => Value::Int(x * y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 * *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x * *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x * y), _ => Value::Null })).as_f64(), ((crate::runtime::Math::pow(&bigInt10, &powerNum))).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
if let Value::Dict(__d) = &mut legOrder { std::sync::Arc::make_mut(__d).insert("limitPrice".into(), self.parse_to_int(priceInteger)); }
} else {
if let Value::Dict(__d) = &mut legOrder { std::sync::Arc::make_mut(__d).insert("limitPrice".into(), Value::Int(0)); }; // should be zero to validate type-check
}
append_to_array(&mut legs, legOrder);
}
}
let mut returnValue: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("subAccountID".to_string(), order.get("sub_account_id").cloned().unwrap_or(Value::Null));
m.insert("isMarket".to_string(), order.get("is_market").cloned().unwrap_or(Value::Null));
m.insert("timeInForce".to_string(), self.time_in_force_to_int(order.get("time_in_force").cloned().unwrap_or(Value::Null)));
m.insert("postOnly".to_string(), order.get("post_only").cloned().unwrap_or(Value::Null));
m.insert("reduceOnly".to_string(), order.get("reduce_only").cloned().unwrap_or(Value::Null));
m.insert("legs".to_string(), legs);
m.insert("nonce".to_string(), crate::value::get_value_k(&order.get("signature").cloned().unwrap_or(Value::Null), "nonce"));
m.insert("expiration".to_string(), crate::value::get_value_k(&order.get("signature").cloned().unwrap_or(Value::Null), "expiration"));
m
});
if (structureType.as_str() == Some("EIP712_ORDER_WITH_BUILDER_TYPE")) && matches!(self.safe_bool_k(self.options.clone(), "builderFee", &[Value::Bool(true)]), Value::Bool(true)) {
if let Value::Dict(__d) = &mut returnValue { std::sync::Arc::make_mut(__d).insert("builder".into(), order.get("builder").cloned().unwrap_or(Value::Null)); }
if let Value::Dict(__d) = &mut returnValue { std::sync::Arc::make_mut(__d).insert("builderFee".into(), self.parse_to_int((match (&(self.convert_to_big_int_custom(self.fee_amount_multiplier())), &(crate::runtime::parse_float(&order.get("builder_fee").cloned().unwrap_or(Value::Null)))) { (Value::Int(x), Value::Int(y)) => Value::Int(x * y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 * *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x * *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x * y), _ => Value::Null }))); }; // the order is matter for Multiply in go, b must be float64 otherwise the value would be 0
}
return returnValue;
Value::Null
}
/*
* @method
* @name grvt#fetchMyTrades
* @description fetch all trades made by the user
* @see https://api-docs.grvt.io/trading_api/#fill-history
* @param {string} [symbol] unified market symbol
* @param {int} [since] the earliest time in ms to fetch trades for
* @param {int} [limit] the maximum number of trade structures to retrieve
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {int} [params.until] timestamp in ms of the latest item
* @param {boolean} [params.paginate] default false, when true will automatically paginate by calling this endpoint multiple times. See in the docs all the [available parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
* @returns {Trade[]} a list of [trade structures]{@link https://docs.ccxt.com/?id=trade-structure}
*/
pub async fn fetch_my_trades(&mut self, optional_args: &[Value]) -> Value {
let mut symbol = 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
}));
self.load_markets_and_sign_in().await;
let mut paginateparamsPaginateVariable = self.handle_option_bool_and_params(params, Value::Str("fetchMyTrades".into()), Value::Str("paginate".into()), &[Value::Bool(false)]);
let mut paginate: Value = paginateparamsPaginateVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsPaginate: Value = paginateparamsPaginateVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
if is_true(&paginate) {
return self.fetch_paginated_call_dynamic(Value::Str("fetchMyTrades".into()), &[symbol.clone(), since.clone(), limit.clone(), paramsPaginate.clone()]).await;
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("sub_account_id".to_string(), self.get_sub_account_id(paramsPaginate.clone()));
m
});
let mut market: Value = Value::Null;
if (symbol != Value::Null) {
market = self.market(symbol);
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("base".into(), Value::from(vec![])); }
crate::runtime::append_to_object_array(&mut request, &Value::Str("base".into()), market.as_map().and_then(|__m| __m.get("baseId")).cloned().unwrap_or(Value::Null));
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("quote".into(), Value::from(vec![])); }
crate::runtime::append_to_object_array(&mut request, &Value::Str("quote".into()), market.as_map().and_then(|__m| __m.get("quoteId")).cloned().unwrap_or(Value::Null));
}
if (limit != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("limit".into(), crate::runtime::Math::min(&limit, &Value::Int(1000))); }
}
let mut requestUntilOptionStringparamsUntilOptionStringVariable = self.handle_until_option_string(Value::Str("end_time".into()), request, &[paramsPaginate, Value::Int(1000000)]);
let mut requestUntilOptionString: Value = requestUntilOptionStringparamsUntilOptionStringVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsUntilOptionString: Value = requestUntilOptionStringparamsUntilOptionStringVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
if (since != Value::Null) {
add_element_to_object(&mut requestUntilOptionString, &Value::Str("start_time".into()), self.number_to_string((match (&(since), &(Value::Int(1000000))) { (Value::Int(x), Value::Int(y)) => Value::Int(x * y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 * *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x * *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x * y), _ => Value::Null })));
}
let __ws_arg_17 = self.extend(requestUntilOptionString, &[paramsUntilOptionString]);
let mut response: Value = self.private_trading_post_full_v1_fill_history(&[__ws_arg_17]).await;
//
// {
// "result": [
// {
// "event_time": "1764945709702747558",
// "sub_account_id": "2147050003876484",
// "instrument": "BTC_USDT_Perp",
// "is_buyer": true,
// "is_taker": false,
// "size": "0.001",
// "price": "90000.0",
// "mark_price": "90050.164063298",
// "index_price": "90089.803654938",
// "interest_rate": "0.0",
// "forward_price": "0.0",
// "realized_pnl": "0.0",
// "fee": "-0.00009",
// "fee_rate": "0.0",
// "trade_id": "65424692-2",
// "order_id": "0x01010105034cddc7000000006621285c",
// "venue": "ORDERBOOK",
// "client_order_id": "1375879248",
// "signer": "0x42c9f56f2c9da534f64b8806d64813b29c62a01d",
// "broker": "UNSPECIFIED",
// "is_rpi": false
// },
// ...
// ],
// "next": ""
// }
//
let mut result: Value = self.safe_list_k(response, "result", &[Value::from(vec![])]);
return self.parse_trades(result, &[Value::Null, since, limit]);
Value::Null
}
/*
* @method
* @name grvt#fetchPositions
* @description fetch all open positions
* @see https://api-docs.grvt.io/trading_api/#positions-request
* @param {string[]|undefined} symbols list of unified market symbols
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object[]} a list of [position structures]{@link https://docs.ccxt.com/?id=position-structure}
*/
pub async fn fetch_positions(&mut self, optional_args: &[Value]) -> Value {
let mut symbols = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
self.load_markets_and_sign_in().await;
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("sub_account_id".to_string(), self.get_sub_account_id(params.clone()));
m
});
let mut symbolsNormalized: Value = self.market_symbols(&[symbols]);
if (symbolsNormalized != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("base".into(), Value::from(vec![])); }
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("quote".into(), Value::from(vec![])); }
{
let mut i: Value = Value::Int(0);
let mut __for_first_725: bool = true;
while { if !__for_first_725 { i = (match (&(i), &(Value::Int(1))) { (Value::Int(x), Value::Int(y)) => Value::Int(x + y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 + *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x + *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x + y), _ => Value::Null }); } __for_first_725 = false; i.as_f64().unwrap_or(f64::NAN) < ((symbolsNormalized.len() as i64) as f64) } {
let mut symbol: Value = symbolsNormalized.as_array().and_then(|__arr| match &i { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null);
let mut market: Value = self.market(symbol);
if (market.as_map().and_then(|__m| __m.get("contract")).cloned().unwrap_or(Value::Null).as_bool() != Some(true)) {
panic!("{}", crate::exchange_errors::bad_request(format!("{}{}", self.id.clone(), Value::Str(" fetchPositions() supports contract markets only".into()))));
}
crate::runtime::append_to_object_array(&mut request, &Value::Str("base".into()), market.as_map().and_then(|__m| __m.get("baseId")).cloned().unwrap_or(Value::Null));
crate::runtime::append_to_object_array(&mut request, &Value::Str("quote".into()), market.as_map().and_then(|__m| __m.get("quoteId")).cloned().unwrap_or(Value::Null));
}
}
}
let __ws_arg_18 = self.extend(request, &[params]);
let mut response: Value = self.private_trading_post_full_v1_positions(&[__ws_arg_18]).await;
//
// {
// "result": [
// {
// "event_time": "1765258069092857642",
// "sub_account_id": "2147050003876484",
// "instrument": "BTC_USDT_Perp",
// "size": "0.001",
// "notional": "89.8169",
// "entry_price": "90000.0",
// "exit_price": "0.0",
// "mark_price": "89816.900008979",
// "unrealized_pnl": "-0.183099",
// "realized_pnl": "0.0",
// "total_pnl": "-0.183099",
// "roi": "-0.2034",
// "quote_index_price": "1.00017885",
// "est_liquidation_price": "77951.450008979",
// "leverage": "28.0",
// "cumulative_fee": "-0.00009",
// "cumulative_realized_funding_payment": "0.033862"
// }
// ]
// }
//
let mut result: Value = self.safe_list_k(response, "result", &[Value::from(vec![])]);
return self.parse_positions(result, &[symbolsNormalized]);
Value::Null
}
pub fn parse_position(&self, mut position: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// {
// "event_time": "1765258069092857642",
// "sub_account_id": "2147050003876484",
// "instrument": "BTC_USDT_Perp",
// "size": "0.001",
// "notional": "89.8169",
// "entry_price": "90000.0",
// "exit_price": "0.0",
// "mark_price": "89816.900008979",
// "unrealized_pnl": "-0.183099",
// "realized_pnl": "0.0",
// "total_pnl": "-0.183099",
// "roi": "-0.2034",
// "quote_index_price": "1.00017885",
// "est_liquidation_price": "77951.450008979",
// "leverage": "28.0",
// "cumulative_fee": "-0.00009",
// "cumulative_realized_funding_payment": "0.033862"
// }
//
let mut marketId: Value = self.safe_string_k(position.clone(), "instrument", &[]);
let mut timestamp: Value = self.safe_integer_product_k(position.clone(), "event_time", Value::Float(0.000001), &[]);
let mut sizeRaw: Value = self.safe_string_k(position.clone(), "size", &[]);
let mut isLong: Value = (crate::precise::Precise::stringGe(&sizeRaw, &Value::Str("0".into())));
let mut side: Value = Value::Str("short".into());
if is_true(&isLong) {
side = Value::Str("long".into());
}
// isolated_balance is the wallet balance reserved for the isolated position
let mut marginMode: Value = self.safe_string_lower_k(position.clone(), "margin_type", &[]);
let mut positionMargin: Value = Value::Null;
if (marginMode.as_str() == Some("isolated")) {
positionMargin = self.safe_number_k(position.clone(), "isolated_balance", &[]);
}
return self.safe_position(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), position.clone());
m.insert("id".to_string(), Value::Null);
m.insert("symbol".to_string(), self.safe_symbol(marketId, &[market]));
m.insert("notional".to_string(), self.parse_number(crate::precise::Precise::stringAbs(&self.safe_string_k(position.clone(), "notional", &[])), &[]));
m.insert("marginMode".to_string(), marginMode);
m.insert("liquidationPrice".to_string(), self.safe_number_k(position.clone(), "est_liquidation_price", &[]));
m.insert("entryPrice".to_string(), self.safe_number_k(position.clone(), "entry_price", &[]));
m.insert("unrealizedPnl".to_string(), self.safe_number_k(position.clone(), "unrealized_pnl", &[]));
m.insert("realizedPnl".to_string(), self.safe_number_k(position.clone(), "realized_pnl", &[]));
m.insert("percentage".to_string(), Value::Null);
m.insert("contracts".to_string(), self.parse_number(crate::precise::Precise::stringAbs(&sizeRaw), &[]));
m.insert("markPrice".to_string(), self.safe_number_k(position.clone(), "mark_price", &[]));
m.insert("lastPrice".to_string(), Value::Null);
m.insert("side".to_string(), side);
m.insert("hedged".to_string(), Value::Null);
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp));
m.insert("lastUpdateTimestamp".to_string(), self.safe_integer_k(position.clone(), "lastUpdateTime", &[]));
m.insert("maintenanceMargin".to_string(), self.safe_number2(position.clone(), Value::Str("isolated_mm".into()), Value::Str("maintenanceMargin".into()), &[]));
m.insert("maintenanceMarginPercentage".to_string(), Value::Null);
m.insert("positionMargin".to_string(), positionMargin);
m.insert("collateral".to_string(), Value::Null);
m.insert("initialMargin".to_string(), self.safe_number2(position.clone(), Value::Str("isolated_im".into()), Value::Str("initialMargin".into()), &[]));
m.insert("initialMarginPercentage".to_string(), Value::Null);
m.insert("leverage".to_string(), self.safe_number_k(position, "leverage", &[]));
m.insert("marginRatio".to_string(), Value::Null);
m.insert("stopLossPrice".to_string(), Value::Null);
m.insert("takeProfitPrice".to_string(), Value::Null);
m
}));
Value::Null
}
/*
* @method
* @name grvt#fetchLeverages
* @description fetch the set leverage for all contract markets
* @see https://api-docs.grvt.io/trading_api/#get-all-initial-leverage
* @param {string[]} [symbols] a list of unified market symbols
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a list of [leverage structures]{@link https://docs.ccxt.com/?id=leverage-structure}
*/
pub async fn fetch_leverages(&mut self, optional_args: &[Value]) -> Value {
let mut symbols = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
self.load_markets_and_sign_in().await;
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("sub_account_id".to_string(), self.get_sub_account_id(params.clone()));
m
});
let __ws_arg_19 = self.extend(request, &[params]);
let mut response: Value = self.private_trading_post_full_v1_get_all_initial_leverage(&[__ws_arg_19]).await;
//
// {
// "results": [
// {
// "instrument": "AAVE_USDT_Perp",
// "leverage": "10.0",
// "min_leverage": "1.0",
// "max_leverage": "50.0",
// "margin_type": "CROSS"
// },
//
let mut results: Value = self.safe_list_k(response, "results", &[Value::from(vec![])]);
return self.parse_leverages(results, &[symbols]);
Value::Null
}
/*
* @method
* @name grvt#setLeverage
* @description set the level of leverage for a market
* @see https://api-docs.grvt.io/trading_api/#set-initial-leverage
* @param {float} leverage the rate of leverage
* @param {string} symbol unified market symbol
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} response from the exchange
*/
pub async fn set_leverage(&mut self, mut leverage: Value, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (symbol == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" setLeverage() requires a symbol argument".into()))));
}
self.load_markets_and_sign_in().await;
let mut market: Value = self.market(symbol);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("sub_account_id".to_string(), self.get_sub_account_id(params.clone()));
m.insert("instrument".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m.insert("leverage".to_string(), self.number_to_string(leverage));
m
});
let __ws_arg_20 = self.extend(request, &[params]);
let mut response: Value = self.private_trading_post_full_v1_set_initial_leverage(&[__ws_arg_20]).await;
return self.parse_leverage(response, &[market]);
Value::Null
}
pub fn parse_leverage(&self, mut leverage: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// setLeverage
//
// {
// "success": true
// }
//
// fetchLeverages
//
// {
// "instrument": "AAVE_USDT_Perp",
// "leverage": "10.0",
// "min_leverage": "1.0",
// "max_leverage": "50.0",
// "margin_type": "CROSS"
// }
//
let mut marketId: Value = self.safe_string_k(leverage.clone(), "instrument", &[]);
let mut leverageValue: Value = self.safe_number_k(leverage.clone(), "leverage", &[]);
let mut marginType: Value = self.safe_string_lower_k(leverage.clone(), "margin_type", &[]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), leverage);
m.insert("symbol".to_string(), self.safe_symbol(marketId, &[market]));
m.insert("marginMode".to_string(), marginType);
m.insert("longLeverage".to_string(), leverageValue.clone());
m.insert("shortLeverage".to_string(), leverageValue);
m
});
Value::Null
}
/*
* @method
* @name grvt#fetchMarginModes
* @description fetches margin mode of the user
* @see https://api-docs.grvt.io/trading_api/#get-all-initial-leverage
* @param {string[]} symbols unified market symbols
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a list of [margin mode structures]{@link https://docs.ccxt.com/?id=margin-mode-structure}
*/
pub async fn fetch_margin_modes(&mut self, optional_args: &[Value]) -> Value {
let mut symbols = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
self.load_markets_and_sign_in().await;
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("sub_account_id".to_string(), self.get_sub_account_id(params.clone()));
m
});
let __ws_arg_21 = self.extend(request, &[params]);
let mut response: Value = self.private_trading_post_full_v1_get_all_initial_leverage(&[__ws_arg_21]).await;
//
// {
// "results": [
// {
// "instrument": "AAVE_USDT_Perp",
// "leverage": "10.0",
// "min_leverage": "1.0",
// "max_leverage": "50.0",
// "margin_type": "CROSS"
// },
//
let mut results: Value = self.safe_list_k(response, "results", &[Value::from(vec![])]);
return self.parse_leverages(results, &[symbols]);
Value::Null
}
pub fn parse_margin_mode(&self, mut marginMode: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// fetchMarginModes
//
// {
// "instrument": "AAVE_USDT_Perp",
// "leverage": "10.0",
// "min_leverage": "1.0",
// "max_leverage": "50.0",
// "margin_type": "CROSS"
// },
//
let mut marketId: Value = self.safe_string_k(marginMode.clone(), "symbol", &[]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), marginMode.clone());
m.insert("symbol".to_string(), self.safe_symbol(marketId, &[market]));
m.insert("marginMode".to_string(), self.safe_string_lower_k(marginMode, "margin_type", &[]));
m
});
Value::Null
}
/*
* @method
* @name grvt#fetchFundingHistory
* @description fetch the history of funding payments paid and received on this account
* @see https://api-docs.grvt.io/trading_api/#funding-payment-history
* @param {string} [symbol] unified market symbol
* @param {int} [since] the earliest time in ms to fetch funding history for
* @param {int} [limit] the maximum number of funding history structures to retrieve
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {int} [params.until] timestamp in ms of the latest item
* @param {boolean} [params.paginate] default false, when true will automatically paginate by calling this endpoint multiple times. See in the docs all the [available parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
* @returns {object} a [funding history structure]{@link https://docs.ccxt.com/?id=funding-history-structure}
*/
pub async fn fetch_funding_history(&mut self, optional_args: &[Value]) -> Value {
let mut symbol = 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
}));
self.load_markets_and_sign_in().await;
let mut paginateparamsPaginateVariable = self.handle_option_bool_and_params(params, Value::Str("fetchFundingHistory".into()), Value::Str("paginate".into()), &[Value::Bool(false)]);
let mut paginate: Value = paginateparamsPaginateVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsPaginate: Value = paginateparamsPaginateVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
if is_true(&paginate) {
return self.fetch_paginated_call_dynamic(Value::Str("fetchFundingHistory".into()), &[symbol.clone(), since.clone(), limit.clone(), paramsPaginate.clone(), Value::Int(1000)]).await;
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("sub_account_id".to_string(), self.get_sub_account_id(paramsPaginate.clone()));
m
});
let mut market: Value = Value::Null;
if (symbol != Value::Null) {
market = self.market(symbol);
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("base".into(), Value::from(vec![])); }
crate::runtime::append_to_object_array(&mut request, &Value::Str("base".into()), market.as_map().and_then(|__m| __m.get("baseId")).cloned().unwrap_or(Value::Null));
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("quote".into(), Value::from(vec![])); }
crate::runtime::append_to_object_array(&mut request, &Value::Str("quote".into()), market.as_map().and_then(|__m| __m.get("quoteId")).cloned().unwrap_or(Value::Null));
}
if (limit != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("limit".into(), crate::runtime::Math::min(&limit, &Value::Int(1000))); }
}
let mut requestUntilOptionStringparamsUntilOptionStringVariable = self.handle_until_option_string(Value::Str("end_time".into()), request, &[paramsPaginate, Value::Int(1000000)]);
let mut requestUntilOptionString: Value = requestUntilOptionStringparamsUntilOptionStringVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsUntilOptionString: Value = requestUntilOptionStringparamsUntilOptionStringVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
if (since != Value::Null) {
add_element_to_object(&mut requestUntilOptionString, &Value::Str("start_time".into()), self.number_to_string((match (&(since), &(Value::Int(1000000))) { (Value::Int(x), Value::Int(y)) => Value::Int(x * y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 * *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x * *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x * y), _ => Value::Null })));
}
let __ws_arg_22 = self.extend(requestUntilOptionString, &[paramsUntilOptionString]);
let mut response: Value = self.private_trading_post_full_v1_funding_payment_history(&[__ws_arg_22]).await;
//
// {
// "result": [
// {
// "event_time": "1765267200004987902",
// "sub_account_id": "2147050003876484",
// "instrument": "BTC_USDT_Perp",
// "currency": "USDT",
// "amount": "-0.004522",
// "tx_id": "66625184"
// },
// ..
// ],
// "next": ""
// }
//
let mut result: Value = self.safe_list_k(response, "result", &[Value::from(vec![])]);
return self.parse_incomes(result, &[market, since, limit]);
Value::Null
}
pub fn parse_income(&self, mut income: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// {
// "event_time": "1765267200004987902",
// "sub_account_id": "2147050003876484",
// "instrument": "BTC_USDT_Perp",
// "currency": "USDT",
// "amount": "-0.004522",
// "tx_id": "66625184"
// }
//
let mut marketId: Value = self.safe_string_k(income.clone(), "instrument", &[]);
let mut currencyId: Value = self.safe_string_k(income.clone(), "currency", &[]);
let mut timestamp: Value = self.safe_integer_product_k(income.clone(), "event_time", Value::Float(0.000001), &[]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), income.clone());
m.insert("symbol".to_string(), self.safe_symbol(marketId, &[market]));
m.insert("code".to_string(), self.safe_currency_code(currencyId, &[]));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp));
m.insert("id".to_string(), self.safe_string_k(income.clone(), "tx_id", &[]));
m.insert("amount".to_string(), self.safe_number_k(income, "amount", &[]));
m
});
Value::Null
}
/*
* @method
* @name grvt#fetchOrders
* @description fetches information on multiple orders made by the user
* @see https://api-docs.grvt.io/trading_api/#order-history
* @param {string} symbol unified market symbol of the market orders were made in
* @param {int} [since] the earliest time in ms to fetch orders for
* @param {int} [limit] the maximum number of order structures to retrieve
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {int} [params.until] timestamp in ms of the latest item
* @returns {Order[]} a list of [order structures]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn fetch_orders(&mut self, optional_args: &[Value]) -> Value {
let mut symbol = 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
}));
self.load_markets_and_sign_in().await;
let mut subAccountId: Value = self.get_sub_account_id(params.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("sub_account_id".to_string(), subAccountId);
m
});
let mut market: Value = Value::Null;
if (symbol != Value::Null) {
market = self.market(symbol);
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("base".into(), Value::from(vec![])); }
crate::runtime::append_to_object_array(&mut request, &Value::Str("base".into()), market.as_map().and_then(|__m| __m.get("baseId")).cloned().unwrap_or(Value::Null));
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("quote".into(), Value::from(vec![])); }
crate::runtime::append_to_object_array(&mut request, &Value::Str("quote".into()), market.as_map().and_then(|__m| __m.get("quoteId")).cloned().unwrap_or(Value::Null));
}
if (limit != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("limit".into(), crate::runtime::Math::min(&limit, &Value::Int(1000))); }
}
let mut requestUntilOptionStringparamsUntilOptionStringVariable = self.handle_until_option_string(Value::Str("end_time".into()), request, &[params, Value::Int(1000000)]);
let mut requestUntilOptionString: Value = requestUntilOptionStringparamsUntilOptionStringVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsUntilOptionString: Value = requestUntilOptionStringparamsUntilOptionStringVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
if (since != Value::Null) {
add_element_to_object(&mut requestUntilOptionString, &Value::Str("start_time".into()), self.number_to_string((match (&(since), &(Value::Int(1000000))) { (Value::Int(x), Value::Int(y)) => Value::Int(x * y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 * *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x * *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x * y), _ => Value::Null })));
}
let __ws_arg_23 = self.extend(requestUntilOptionString, &[paramsUntilOptionString]);
let mut response: Value = self.private_trading_post_full_v1_order_history(&[__ws_arg_23]).await;
//
// {
// "result": [
// {
// "order_id": "0x01010105034cddc7000000006621285c",
// "sub_account_id": "2147050003876484",
// "is_market": false,
// "time_in_force": "GOOD_TILL_TIME",
// "post_only": false,
// "reduce_only": false,
// "legs": [
// {
// "instrument": "BTC_USDT_Perp",
// "size": "0.001",
// "limit_price": "90000.0",
// "is_buying_asset": true
// }
// ],
// "signature": {
// "signer": "0x42c9f56f2c9da534f64b8806d64813b29c62a01d",
// "r": "0x2d567b0a04525baf0bbd792db3bb3a28c1bcc5e95936f6dc2515a28ad8529313",
// "s": "0x0bc2468d96c819c8de005aa7bebfb58eecb34dd7a1bae1e81e74c7b8bc4cddc7",
// "v": "27",
// "expiration": "1767455222801000000",
// "nonce": "1375879248",
// "chain_id": "0"
// },
// "metadata": {
// "client_order_id": "1375879248",
// "create_time": "1764863234474424590",
// "trigger": {
// "trigger_type": "UNSPECIFIED",
// "tpsl": {
// "trigger_by": "UNSPECIFIED",
// "trigger_price": "0.0",
// "close_position": false
// }
// },
// "broker": "UNSPECIFIED",
// "is_position_transfer": false,
// "allow_crossing": false
// },
// "state": {
// "status": "FILLED",
// "reject_reason": "UNSPECIFIED",
// "book_size": [
// "0.0"
// ],
// "traded_size": [
// "0.001"
// ],
// "update_time": "1764945709704912003",
// "avg_fill_price": [
// "90000.0"
// ]
// }
// },
// ...
// ],
// "next": ""
// }
//
let mut result: Value = self.safe_list_k(response, "result", &[Value::from(vec![])]);
return self.parse_orders(result, &[market, since, limit]);
Value::Null
}
/*
* @method
* @name grvt#fetchOpenOrders
* @description fetch all unfilled currently open orders
* @see https://api-docs.grvt.io/trading_api/#open-orders
* @param {string} [symbol] unified market symbol
* @param {int} [since] the earliest time in ms to fetch orders for
* @param {int} [limit] the maximum number of order structures to retrieve
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {Order[]} a list of [order structures]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn fetch_open_orders(&mut self, optional_args: &[Value]) -> Value {
let mut symbol = 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
}));
self.load_markets_and_sign_in().await;
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("sub_account_id".to_string(), self.get_sub_account_id(params.clone()));
m
});
let __ws_arg_24 = self.extend(request, &[params]);
let mut response: Value = self.private_trading_post_full_v1_open_orders(&[__ws_arg_24]).await;
//
// {
// "result": [
// {
// "order_id": "0x0101010503e693410000000069530a7d",
// "sub_account_id": "2147050003876484",
// "is_market": false,
// "time_in_force": "GOOD_TILL_TIME",
// "post_only": false,
// "reduce_only": false,
// "legs": [
// {
// "instrument": "BTC_USDT_Perp",
// "size": "0.002",
// "limit_price": "88123.0",
// "is_buying_asset": true
// }
// ],
// "signature": {
// "signer": "0x0982ebb82523fd20d1347d59f5a989ed84caa4b5",
// "r": "0x22b13e5bc7c8d6793db9d0adf6a51340437292baf83aa4f89a01a3c0c1fef4a8",
// "s": "0x46ecd483126c388cc933022979a9636670f64af3773d04a84ecbeac423e69341",
// "v": "28",
// "expiration": "1767871961406000000",
// "nonce": "588129369",
// "chain_id": "0"
// },
// "metadata": {
// "client_order_id": "588129369",
// "create_time": "1765279966899943792",
// "trigger": {
// "trigger_type": "UNSPECIFIED",
// "tpsl": {
// "trigger_by": "UNSPECIFIED",
// "trigger_price": "0.0",
// "close_position": false
// }
// },
// "broker": "UNSPECIFIED",
// "is_position_transfer": false,
// "allow_crossing": false
// },
// "state": {
// "status": "OPEN",
// "reject_reason": "UNSPECIFIED",
// "book_size": [
// "0.002"
// ],
// "traded_size": [
// "0.0"
// ],
// "update_time": "1765279966899943792",
// "avg_fill_price": [
// "0.0"
// ]
// }
// }
// ]
// }
//
let mut result: Value = self.safe_list_k(response, "result", &[Value::from(vec![])]);
return self.parse_orders(result, &[Value::Null, since, limit]);
Value::Null
}
/*
* @method
* @name grvt#fetchOrder
* @description fetches information on an order made by the user
* @see https://api-docs.grvt.io/trading_api/#get-order
* @param {string} id the order id
* @param {string} symbol unified symbol of the market the order was made in
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.clientOrderId] client order id
* @returns {object} An [order structure]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn fetch_order(&mut self, mut id: Value, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
self.load_markets_and_sign_in().await;
let mut subAccountId: Value = self.get_sub_account_id(params.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("sub_account_id".to_string(), subAccountId);
m
});
let mut clientOrderId: Value = self.safe_string2(params.clone(), Value::Str("clientOrderId".into()), Value::Str("client_order_id".into()), &[]);
if (clientOrderId != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("client_order_id".into(), clientOrderId.clone()); }
} else {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("order_id".into(), id); }
}
let mut paramsOmitted: Value = (if (clientOrderId != Value::Null) { self.omit(params.clone(), Value::Str("clientOrderId".into()), &[Value::Str("client_order_id".into())]) } else { params });
let __ws_arg_25 = self.extend(request, &[paramsOmitted]);
let mut response: Value = self.private_trading_post_full_v1_order(&[__ws_arg_25]).await;
//
// {
// "result": {
// "order_id": "0x01010105034cddc7000000006621285c",
// "sub_account_id": "2147050003876484",
// "is_market": false,
// "time_in_force": "GOOD_TILL_TIME",
// "post_only": false,
// "reduce_only": false,
// "legs": [
// {
// "instrument": "BTC_USDT_Perp",
// "size": "0.001",
// "limit_price": "90000.0",
// "is_buying_asset": true
// }
// ],
// "signature": {
// "signer": "0x42c9f56f2c9da534f64b8806d64813b29c62a01d",
// "r": "0x2d567b0a04525baf0bbd792db3bb3a28c1bcc5e95936f6dc2515a28ad8529313",
// "s": "0x0bc2468d96c819c8de005aa7bebfb58eecb34dd7a1bae1e81e74c7b8bc4cddc7",
// "v": "27",
// "expiration": "1767455222801000000",
// "nonce": "1375879248",
// "chain_id": "0"
// },
// "metadata": {
// "client_order_id": "1375879248",
// "create_time": "1764863234474424590",
// "trigger": {
// "trigger_type": "UNSPECIFIED",
// "tpsl": {
// "trigger_by": "UNSPECIFIED",
// "trigger_price": "0.0",
// "close_position": false
// }
// },
// "broker": "UNSPECIFIED",
// "is_position_transfer": false,
// "allow_crossing": false
// },
// "state": {
// "status": "FILLED",
// "reject_reason": "UNSPECIFIED",
// "book_size": [
// "0.0"
// ],
// "traded_size": [
// "0.001"
// ],
// "update_time": "1764945709704912003",
// "avg_fill_price": [
// "90000.0"
// ]
// }
// }
// }
//
let mut result: Value = self.safe_dict_k(response, "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_order(result, &[]);
Value::Null
}
pub fn parse_order(&self, mut order: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// fetchOrders, fetchOpenOrders, fetchOrder, createOrder
//
// {
// "order_id": "0x0101010503e693410000000069530a7d",
// "sub_account_id": "2147050003876484",
// "is_market": false,
// "time_in_force": "GOOD_TILL_TIME",
// "post_only": false,
// "reduce_only": false,
// "legs": [
// {
// "instrument": "BTC_USDT_Perp",
// "size": "0.002",
// "limit_price": "88123.0",
// "is_buying_asset": true
// }
// ],
// "signature": {
// "signer": "0x0982ebb82523fd20d1347d59f5a989ed84caa4b5",
// "r": "0x22b13e5bc7c8d6793db9d0adf6a51340437292baf83aa4f89a01a3c0c1fef4a8",
// "s": "0x46ecd483126c388cc933022979a9636670f64af3773d04a84ecbeac423e69341",
// "v": "28",
// "expiration": "1767871961406000000",
// "nonce": "588129369",
// "chain_id": "0"
// },
// "metadata": {
// "client_order_id": "588129369",
// "create_time": "1765279966899943792",
// "trigger": {
// "trigger_type": "UNSPECIFIED",
// "tpsl": {
// "trigger_by": "UNSPECIFIED",
// "trigger_price": "0.0",
// "close_position": false
// }
// },
// "broker": "UNSPECIFIED",
// "is_position_transfer": false,
// "allow_crossing": false
// },
// "state": {
// "status": "OPEN",
// "reject_reason": "UNSPECIFIED",
// "book_size": [
// "0.002"
// ],
// "traded_size": [
// "0.0"
// ],
// "update_time": "1765279966899943792",
// "avg_fill_price": [
// "0.0"
// ]
// },
// "builder": "0x00",
// "builder_fee": "0.0"
// }
//
// cancelOrder, cancelAllOrders
//
// {
// "ack": true
// }
//
if (matches!(&order, Value::Dict(__d) if __d.contains_key("ack"))) {
return self.safe_order(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), order.clone());
m.insert("id".to_string(), Value::Null);
m
}), &[]);
}
let mut isMarket: Value = self.safe_bool_k(order.clone(), "is_market", &[]);
let mut orderType: Value = Value::Str("limit".into());
if (isMarket.as_bool() == Some(true)) {
orderType = Value::Str("market".into());
}
let mut isPostOnly: Value = self.safe_bool_k(order.clone(), "post_only", &[]);
let mut isReduceOnly: Value = self.safe_bool_k(order.clone(), "reduce_only", &[]);
let mut timeInForceRaw: Value = self.safe_string_k(order.clone(), "time_in_force", &[]);
let mut timeInForce: Value = (if (isPostOnly.as_bool() == Some(true)) { Value::Str("PO".into()) } else { self.parse_time_in_force(timeInForceRaw).map(|__s| Value::Str(__s.into())).unwrap_or(Value::Null) });
let mut size: Value = Value::Null;
let mut side: Value = Value::Null;
let mut price: Value = Value::Null;
let mut filled: Value = Value::Null;
let mut avgPrice: Value = Value::Null;
let mut legs: Value = self.safe_list_k(order.clone(), "legs", &[Value::from(vec![])]);
let mut metadata: Value = self.safe_dict_k(order.clone(), "metadata", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut stateObj: Value = self.safe_dict_k(order.clone(), "state", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut filledAmounts: Value = self.safe_list_k(stateObj.clone(), "traded_size", &[Value::from(vec![])]);
let mut avgPrices: Value = self.safe_list_k(stateObj.clone(), "avg_fill_price", &[Value::from(vec![])]);
let mut primaryOrderIndex: Value = Value::Int(0);
let mut firstLeg: Value = self.safe_dict(legs, primaryOrderIndex.clone(), &[]);
let mut legMarketId: Value = self.safe_string_k(firstLeg.clone(), "instrument", &[]);
let mut marketResolved: Value = (if (firstLeg != Value::Null) { self.safe_market(&[legMarketId, market.clone()]) } else { market });
if (firstLeg != Value::Null) {
size = self.safe_string_k(firstLeg.clone(), "size", &[]);
let mut isBuyingAsset: Value = self.safe_bool_k(firstLeg.clone(), "is_buying_asset", &[Value::Bool(false)]);
side = (if isBuyingAsset.as_bool() == Some(true) { Value::Str("buy".into()) } else { Value::Str("sell".into()) });
price = self.safe_string_k(firstLeg, "limit_price", &[]);
filled = self.safe_string(filledAmounts, primaryOrderIndex.clone(), &[]);
avgPrice = self.safe_string(avgPrices, primaryOrderIndex, &[]);
}
let mut timestamp: Value = self.safe_integer_product_k(metadata.clone(), "create_time", Value::Float(0.000001), &[]);
return self.safe_order(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), self.safe_string_k(order.clone(), "order_id", &[]));
m.insert("clientOrderId".to_string(), self.safe_string_k(metadata, "client_order_id", &[]));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp));
m.insert("lastTradeTimestamp".to_string(), Value::Null);
m.insert("lastUpdateTimestamp".to_string(), self.safe_integer_product_k(stateObj.clone(), "update_time", Value::Float(0.000001), &[]));
m.insert("status".to_string(), self.parse_order_status(self.safe_string_k(stateObj, "status", &[])));
m.insert("symbol".to_string(), self.safe_string_k(marketResolved.clone(), "symbol", &[]));
m.insert("type".to_string(), orderType);
m.insert("timeInForce".to_string(), timeInForce);
m.insert("postOnly".to_string(), isPostOnly);
m.insert("side".to_string(), side);
m.insert("price".to_string(), price);
m.insert("triggerPrice".to_string(), Value::Null);
m.insert("cost".to_string(), Value::Null);
m.insert("average".to_string(), avgPrice);
m.insert("amount".to_string(), size);
m.insert("filled".to_string(), filled);
m.insert("remaining".to_string(), Value::Null);
m.insert("trades".to_string(), Value::Null);
m.insert("fees".to_string(), Value::Null);
m.insert("reduceOnly".to_string(), isReduceOnly);
m.insert("info".to_string(), order);
m
}), &[marketResolved]);
Value::Null
}
pub fn parse_time_in_force(&self, mut type_var: Value) -> Option<String> {
let mut types: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("GOOD_TILL_TIME".to_string(), Value::Str("GTC".into()));
m.insert("IMMEDIATE_OR_CANCEL".to_string(), Value::Str("IOC".into()));
m.insert("FILL_OR_KILL".to_string(), Value::Str("FOK".into()));
m.insert("ALL_OR_NONE".to_string(), Value::Str("ALL_OR_NONE".into()));
m.insert("RETAIL_PRICE_IMPROVEMENT".to_string(), Value::Str("RETAIL_PRICE_IMPROVEMENT".into()));
m
});
return self.safe_string_upper(types, type_var.clone(), &[type_var.clone()]).as_str().map(str::to_owned);
}
pub fn time_in_force_to_int(&self, mut timeInForce: Value) -> Value {
let mut timeInForces: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("GOOD_TILL_TIME".to_string(), Value::Int(1));
m.insert("ALL_OR_NONE".to_string(), Value::Int(2));
m.insert("IMMEDIATE_OR_CANCEL".to_string(), Value::Int(3));
m.insert("FILL_OR_KILL".to_string(), Value::Int(4));
m.insert("RETAIL_PRICE_IMPROVEMENT".to_string(), Value::Int(5));
m
});
return self.safe_integer(timeInForces, timeInForce, &[Value::Int(0)]);
Value::Null
}
pub fn parse_order_status(&self, mut status: Value) -> Value {
let mut statuses: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("PENDING".to_string(), Value::Str("pending".into()));
m.insert("OPEN".to_string(), Value::Str("open".into()));
m.insert("FILLED".to_string(), Value::Str("closed".into()));
m.insert("REJECTED".to_string(), Value::Str("rejected".into()));
m.insert("CANCELLED".to_string(), Value::Str("canceled".into()));
m
});
return self.safe_string(statuses, status.clone(), &[status.clone()]);
Value::Null
}
/*
* @method
* @name grvt#cancelAllOrders
* @description cancel all open orders in a market
* @see https://api-docs.grvt.io/trading_api/#cancel-all-orders
* @param {string} [symbol] unified market symbol, only orders in the market of this symbol are cancelled when symbol is not undefined
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object[]} a list of [order structures]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn cancel_all_orders(&mut self, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
self.load_markets_and_sign_in().await;
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("sub_account_id".to_string(), self.get_sub_account_id(params.clone()));
m
});
if (symbol != Value::Null) {
let mut market: Value = self.market(symbol);
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("base".into(), Value::from(vec![])); }
crate::runtime::append_to_object_array(&mut request, &Value::Str("base".into()), market.as_map().and_then(|__m| __m.get("baseId")).cloned().unwrap_or(Value::Null));
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("quote".into(), Value::from(vec![])); }
crate::runtime::append_to_object_array(&mut request, &Value::Str("quote".into()), market.as_map().and_then(|__m| __m.get("quoteId")).cloned().unwrap_or(Value::Null));
}
let __ws_arg_26 = self.extend(request, &[params]);
let mut response: Value = self.private_trading_post_full_v1_cancel_all_orders(&[__ws_arg_26]).await;
//
// {
// "result": {
// "ack": true
// }
// }
//
let mut result: Value = self.safe_dict_k(response, "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_orders(Value::from(vec![result]), &[]);
Value::Null
}
/*
* @method
* @name grvt#cancelOrder
* @description cancels an open order
* @see https://api-docs.grvt.io/trading_api/#cancel-order
* @param {string} id order id
* @param {string} [symbol] unified symbol of the market the order was made in
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.clientOrderId] client order id
* @returns {object} An [order structure]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn cancel_order(&mut self, mut id: Value, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
self.load_markets_and_sign_in().await;
let mut subAccoubntId: Value = self.get_sub_account_id(params.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("sub_account_id".to_string(), subAccoubntId);
m
});
let mut clientOrderId: Value = self.safe_string2(params.clone(), Value::Str("clientOrderId".into()), Value::Str("client_order_id".into()), &[]);
if (clientOrderId != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("client_order_id".into(), clientOrderId.clone()); }
} else {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("order_id".into(), id); }
}
let mut paramsOmitted: Value = (if (clientOrderId != Value::Null) { self.omit(params.clone(), Value::Str("clientOrderId".into()), &[]) } else { params });
let __ws_arg_27 = self.extend(request, &[paramsOmitted]);
let mut response: Value = self.private_trading_post_full_v1_cancel_order(&[__ws_arg_27]).await;
//
// {
// "result": {
// "ack": true
// }
// }
//
let mut result: Value = self.safe_dict_k(response, "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_order(result, &[]);
Value::Null
}
pub fn eip_domain_data(&self) -> Value {
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("name".to_string(), Value::Str("GRVT Exchange".into()));
m.insert("version".to_string(), Value::Str("0".into()));
m.insert("chainId".to_string(), (if is_true(&self.isSandboxModeEnabled) { Value::Int(326) } else { Value::Int(325) }));
m
});
Value::Null
}
pub fn fee_amount_multiplier(&self) -> Value {
return self.convert_to_big_int_custom(Value::Str("10000".into()));
Value::Null
}
pub fn create_signed_request(&self, mut request: Value, mut structureType: Value, optional_args: &[Value]) -> Value {
let mut currencyObj = get_arg(optional_args, 0, Value::Null);
let mut signerAddress = get_arg(optional_args, 1, Value::Null);
let mut messageData: Value = Value::Null;
if (structureType.as_str() == Some("EIP712_TRANSFER_TYPE")) {
let mut amountMultiplier: Value = self.convert_to_big_int_custom(Value::Str("1000000".into()));
let mut amountInt: Value = multiply(&request.as_map().and_then(|__m| __m.get("num_tokens")).cloned().unwrap_or(Value::Null), &amountMultiplier);
if (currencyObj == Value::Null) {
panic!("{}", crate::exchange_errors::exchange_error(format!("{}{}", self.id.clone(), Value::Str(" createSignedRequest() missing currencyObj".into()))));
}
messageData = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("fromAccount".to_string(), request.as_map().and_then(|__m| __m.get("from_account_id")).cloned().unwrap_or(Value::Null));
m.insert("fromSubAccount".to_string(), request.as_map().and_then(|__m| __m.get("from_sub_account_id")).cloned().unwrap_or(Value::Null));
m.insert("toAccount".to_string(), request.as_map().and_then(|__m| __m.get("to_account_id")).cloned().unwrap_or(Value::Null));
m.insert("toSubAccount".to_string(), request.as_map().and_then(|__m| __m.get("to_sub_account_id")).cloned().unwrap_or(Value::Null));
m.insert("tokenCurrency".to_string(), currencyObj.as_map().and_then(|__m| __m.get("numericId")).cloned().unwrap_or(Value::Null));
m.insert("numTokens".to_string(), self.parse_to_int(amountInt));
m.insert("nonce".to_string(), crate::value::get_value_k(&request.as_map().and_then(|__m| __m.get("signature")).cloned().unwrap_or(Value::Null), "nonce"));
m.insert("expiration".to_string(), crate::value::get_value_k(&request.as_map().and_then(|__m| __m.get("signature")).cloned().unwrap_or(Value::Null), "expiration"));
m
});
} else if (structureType.as_str() == Some("EIP712_WITHDRAWAL_TYPE")) {
let mut amountMultiplier: Value = self.convert_to_big_int_custom(Value::Str("1000000".into()));
if (currencyObj == Value::Null) {
panic!("{}", crate::exchange_errors::exchange_error(format!("{}{}", self.id.clone(), Value::Str(" createSignedRequest() missing currencyObj".into()))));
}
messageData = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("fromAccount".to_string(), request.as_map().and_then(|__m| __m.get("from_account_id")).cloned().unwrap_or(Value::Null));
m.insert("toEthAddress".to_string(), request.as_map().and_then(|__m| __m.get("to_eth_address")).cloned().unwrap_or(Value::Null));
m.insert("tokenCurrency".to_string(), currencyObj.as_map().and_then(|__m| __m.get("numericId")).cloned().unwrap_or(Value::Null));
m.insert("numTokens".to_string(), self.parse_to_int(multiply(&request.as_map().and_then(|__m| __m.get("num_tokens")).cloned().unwrap_or(Value::Null), &amountMultiplier)));
m.insert("nonce".to_string(), crate::value::get_value_k(&request.as_map().and_then(|__m| __m.get("signature")).cloned().unwrap_or(Value::Null), "nonce"));
m.insert("expiration".to_string(), crate::value::get_value_k(&request.as_map().and_then(|__m| __m.get("signature")).cloned().unwrap_or(Value::Null), "expiration"));
m
});
} else if (structureType.as_str() == Some("EIP712_ORDER_TYPE")) || (structureType.as_str() == Some("EIP712_ORDER_WITH_BUILDER_TYPE")) {
messageData = self.eip_message_for_order(request.clone(), structureType.clone());
} else if (structureType.as_str() == Some("EIP712_BUILDER_APPROVAL_TYPE")) {
let mut amountMultiplier: Value = self.convert_to_big_int_custom(self.fee_amount_multiplier());
messageData = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("mainAccountID".to_string(), request.as_map().and_then(|__m| __m.get("main_account_id")).cloned().unwrap_or(Value::Null));
m.insert("builderAccountID".to_string(), request.as_map().and_then(|__m| __m.get("builder_account_id")).cloned().unwrap_or(Value::Null));
m.insert("maxFutureFeeRate".to_string(), self.parse_to_int((match (&(crate::runtime::parse_float(&request.as_map().and_then(|__m| __m.get("max_futures_fee_rate")).cloned().unwrap_or(Value::Null))), &(amountMultiplier)) { (Value::Int(x), Value::Int(y)) => Value::Int(x * y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 * *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x * *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x * y), _ => Value::Null })));
m.insert("maxSpotFeeRate".to_string(), self.parse_to_int((match (&(crate::runtime::parse_float(&request.as_map().and_then(|__m| __m.get("max_spot_fee_rate")).cloned().unwrap_or(Value::Null))), &(amountMultiplier)) { (Value::Int(x), Value::Int(y)) => Value::Int(x * y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 * *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x * *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x * y), _ => Value::Null })));
m.insert("nonce".to_string(), crate::value::get_value_k(&request.as_map().and_then(|__m| __m.get("signature")).cloned().unwrap_or(Value::Null), "nonce"));
m.insert("expiration".to_string(), crate::value::get_value_k(&request.as_map().and_then(|__m| __m.get("signature")).cloned().unwrap_or(Value::Null), "expiration"));
m
});
} else if (structureType.as_str() == Some("EIP712_WALLETLOGIN_TYPE")) {
messageData = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("signer".to_string(), request.as_map().and_then(|__m| __m.get("address")).cloned().unwrap_or(Value::Null));
m.insert("nonce".to_string(), crate::value::get_value_k(&request.as_map().and_then(|__m| __m.get("signature")).cloned().unwrap_or(Value::Null), "nonce"));
m.insert("expiration".to_string(), crate::value::get_value_k(&request.as_map().and_then(|__m| __m.get("signature")).cloned().unwrap_or(Value::Null), "expiration"));
m
});
}
let mut domainData: Value = self.eip_domain_data();
let mut definitions: Value = self.eip_definitions();
let mut ethEncodedMessage: Value = self.eth_encode_structured_data(domainData, definitions.as_map().and_then(|__m| structureType.as_str().and_then(|__k| __m.get(__k))).cloned().unwrap_or(Value::Null), messageData);
let mut ethEncodedMessageHashed: Value = Value::Str(format!("{}{}", Value::Str("0x".into()), self.hash(ethEncodedMessage, Value::Str("keccak".into()), &[Value::Str("hex".into())])).into());
let mut usesPrivKey: Value = self.uses_private_key(); // py transpiler needs this line separated
let mut secretOrPrivkey: Value = (if is_true(&usesPrivKey) { self.privateKey.clone() } else { self.secret.clone() });
let mut privateKeyWithoutZero: Value = self.remove0x_prefix(secretOrPrivkey);
let mut signature: Value = ecdsa(self.remove0x_prefix(ethEncodedMessageHashed), privateKeyWithoutZero.clone(), Value::Str("secp256k1".into()), Value::Null);
add_element_to_object(get_value_mut(&mut request, &Value::Str("signature".into())), &Value::Str("r".into()), self.format_signature_rs(signature.as_map().and_then(|__m| __m.get("r")).cloned().unwrap_or(Value::Null)));
add_element_to_object(get_value_mut(&mut request, &Value::Str("signature".into())), &Value::Str("s".into()), self.format_signature_rs(signature.as_map().and_then(|__m| __m.get("s")).cloned().unwrap_or(Value::Null)));
add_element_to_object(get_value_mut(&mut request, &Value::Str("signature".into())), &Value::Str("v".into()), self.sum(&[Value::Int(27), signature.as_map().and_then(|__m| __m.get("v")).cloned().unwrap_or(Value::Null)]));
add_element_to_object(get_value_mut(&mut request, &Value::Str("signature".into())), &Value::Str("signer".into()), (if (signerAddress == Value::Null) { self.eth_get_address_from_private_key(Value::Str(format!("{}{}", Value::Str("0x".into()), privateKeyWithoutZero).into()), &[]) } else { signerAddress }));
return request;
Value::Null
}
pub fn format_signature_rs(&self, mut value: Value) -> Value {
let mut padded: Value = pad_start(&value, &Value::Int(64), &Value::Str("0".into()));
if (starts_with(&padded, &Value::Str("0x".into()))) {
return padded;
} else {
return Value::Str(format!("{}{}", Value::Str("0x".into()), padded).into());
}
Value::Null
}
pub fn default_signature(&self) -> Value {
let mut expiration: Value = (match (&((match (&(self.milliseconds()), &(Value::Int(1000000))) { (Value::Int(x), Value::Int(y)) => Value::Int(x * y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 * *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x * *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x * y), _ => Value::Null })), &((match (&((match (&(Value::Int(1000000)), &(self.safe_integer_k(self.options.clone(), "expirationSeconds", &[Value::Int(30)]))) { (Value::Int(x), Value::Int(y)) => Value::Int(x * y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 * *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x * *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x * y), _ => Value::Null })), &(Value::Int(1000))) { (Value::Int(x), Value::Int(y)) => Value::Int(x * y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 * *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x * *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x * y), _ => Value::Null }))) { (Value::Int(x), Value::Int(y)) => Value::Int(x + y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 + *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x + *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x + y), _ => Value::Null });
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("signer".to_string(), Value::Str("".into()));
m.insert("r".to_string(), Value::Str("".into()));
m.insert("s".to_string(), Value::Str("".into()));
m.insert("v".to_string(), Value::Int(0));
m.insert("expiration".to_string(), to_string_val(&expiration));
m.insert("nonce".to_string(), self.nonce());
m.insert("chain_id".to_string(), (if is_true(&self.isSandboxModeEnabled) { Value::Str("326".into()) } else { Value::Str("325".into()) }));
m
});
Value::Null
}
pub fn handle_until_option_string(&self, mut key: Value, mut request: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut multiplier = get_arg(optional_args, 1, Value::Int(1));
let mut until: Value = self.safe_integer2(params.clone(), Value::Str("until".into()), Value::Str("till".into()), &[]);
if (until != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert(crate::runtime::stringify_param(&key), self.number_to_string(self.parse_to_int((match (&(until), &(multiplier)) { (Value::Int(x), Value::Int(y)) => Value::Int(x * y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 * *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x * *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x * y), _ => Value::Null })))); }
return Value::from(vec![request.clone(), self.omit(params.clone(), Value::from(vec![Value::Str("until".into()), Value::Str("till".into())]), &[])]);
}
return Value::from(vec![request, params]);
Value::Null
}
pub fn request_id(&self) -> Value {
let mut requestId: Value = self.sum(&[self.safe_integer_k(self.options.clone(), "requestId", &[Value::Int(0)]), Value::Int(1)]);
if let Value::Dict(__d) = &mut self.options.clone() { std::sync::Arc::make_mut(__d).insert("requestId".into(), requestId.clone()); }
return requestId;
Value::Null
}
pub fn sign(&self, mut path: Value, optional_args: &[Value]) -> Value {
let mut api = get_arg(optional_args, 0, Value::from(vec![Value::Str("public".into())]));
let mut method = get_arg(optional_args, 1, Value::Str("GET".into()));
let mut params = get_arg(optional_args, 2, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let __api_empty = Vec::new();
let api = api.as_array().unwrap_or(&__api_empty);
let mut requestHeaders: Value = Value::Null;
let mut requestBody: Value = Value::Null;
let mut requestPath: Value = path;
let mut query: Value = self.omit(params.clone(), self.extract_params(requestPath.clone()), &[]);
let mut apiName: Value = api.get(0).cloned().unwrap_or(Value::Null);
let mut apiUrl: Value = self.safe_string(self.urls.as_map().and_then(|__m| __m.get("api")).cloned().unwrap_or(Value::Null), apiName.clone(), &[]);
if (apiUrl == Value::Null) {
panic!("{}", crate::exchange_errors::exchange_error(format!("{}{}", self.id.clone(), Value::Str(" sign() has no API URL for this endpoint".into()))));
}
let mut url: Value = add(&apiUrl, &requestPath);
let mut queryString: Value = Value::Str("".into());
if (method.as_str() == Some("GET")) {
if ((object_keys(&query).len() as i64) as f64) > ((0i64) as f64) {
queryString = self.urlencode(query.clone(), &[]);
url = Value::Str(format!("{}{}", url, Value::Str(format!("{}{}", Value::Str("?".into()), queryString).into())).into());
}
} else if (method.as_str() == Some("POST")) {
// the venue rejects json POSTs without an explicit content type with 1003 malformed syntax,
// the private branch below sets its own headers, this covers the public market-data endpoints
requestHeaders = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("Content-Type".to_string(), Value::Str("application/json".into()));
m
});
// an empty params dict must serialize as an empty json object, not an empty json array,
// php json_encode would produce [] here which the venue rejects with the same 1003 error
let mut paramsKeys: Value = object_keys(¶ms);
let mut paramsKeysLength: f64 = ((paramsKeys.len() as i64) as f64);
if (paramsKeysLength == 0.0) {
requestBody = Value::Str("{}".into());
} else {
requestBody = json_stringify(¶ms);
}
}
let mut isPrivate: bool = starts_with(&apiName, &Value::Str("private".into()));
if (isPrivate) {
self.check_required_credentials(&[]);
if (queryString.as_str() != Some("")) {
requestPath = Value::Str(format!("{}{}", add(&requestPath, &Value::Str("?".into())), queryString).into());
}
requestHeaders = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("Content-Type".to_string(), Value::Str("application/json".into()));
m
});
if (is_equal(&Value::Bool(ends_with(&requestPath, &Value::Str("auth/api_key/login".into()))), &Value::Bool(true))) || (is_equal(&Value::Bool(ends_with(&requestPath, &Value::Str("auth/wallet/login".into()))), &Value::Bool(true))) {
add_element_to_object(&mut requestHeaders, &Value::Str("Cookie".into()), Value::Str("rm=true;".into()));
} else {
let mut accountId: Value = self.safe_string_k(self.options.clone(), "AuthAccountId", &[]);
let mut cookieValue: Value = self.safe_string_k(self.options.clone(), "AuthCookieValue", &[]);
if (cookieValue == Value::Null) || (accountId == Value::Null) {
panic!("{}", crate::exchange_errors::authentication_error(format!("{}{}", self.id.clone(), Value::Str(" : at first, you need to authenticate with exchange using signIn() method.".into()))));
}
add_element_to_object(&mut requestHeaders, &Value::Str("Cookie".into()), cookieValue);
add_element_to_object(&mut requestHeaders, &Value::Str("X-Grvt-Account-Id".into()), accountId);
}
}
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("url".to_string(), url);
m.insert("method".to_string(), method);
m.insert("body".to_string(), requestBody);
m.insert("headers".to_string(), requestHeaders);
m
});
Value::Null
}
pub fn handle_errors(&self, mut code: Value, mut reason: Value, mut url: Value, mut method: Value, mut headers: Value, mut body: Value, mut response: Value, mut requestHeaders: Value, mut requestBody: Value) -> Value {
if (ends_with(&url, &Value::Str("auth/api_key/login".into()))) || (ends_with(&url, &Value::Str("auth/wallet/login".into()))) {
let mut accountId: Value = self.safe_string2(headers.clone(), Value::Str("X-Grvt-Account-Id".into()), Value::Str("x-grvt-account-id".into()), &[]);
if let Value::Dict(__d) = &mut self.options.clone() { std::sync::Arc::make_mut(__d).insert("AuthAccountId".into(), accountId); }
let mut cookie: Value = self.safe_string2(headers, Value::Str("Set-Cookie".into()), Value::Str("set-cookie".into()), &[]);
if (cookie != Value::Null) {
let mut cookieValue: Value = split(&cookie, &Value::Str(";".into())).as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
if let Value::Dict(__d) = &mut self.options.clone() { std::sync::Arc::make_mut(__d).insert("AuthCookieValue".into(), cookieValue); }
}
if (self.safe_string_k(self.options.clone(), "AuthCookieValue", &[]) == Value::Null) || (self.safe_string_k(self.options.clone(), "AuthAccountId", &[]) == Value::Null) {
panic!("{}", crate::exchange_errors::authentication_error(format!("{}{}", self.id.clone(), Value::Str(" signIn() failed to receive auth-cookie or account-id".into()))));
}
} else {
let mut errorCode: Value = self.safe_string_k(response.clone(), "code", &[]);
if (errorCode != Value::Null) {
let mut feedback: Value = Value::Str(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" ".into())).into()), body).into());
self.throw_exactly_matched_exception(self.exceptions.as_map().and_then(|__m| __m.get("exact")).cloned().unwrap_or(Value::Null), errorCode, feedback.clone());
panic!("{}", crate::exchange_errors::exchange_error(feedback));
} else {
let mut message: Value = self.safe_string_k(response.clone(), "message", &[]);
if (message != Value::Null) {
let mut feedback: Value = Value::Str(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" ".into())).into()), body).into());
self.throw_broadly_matched_exception(self.exceptions.as_map().and_then(|__m| __m.get("broad")).cloned().unwrap_or(Value::Null), message, feedback.clone());
panic!("{}", crate::exchange_errors::exchange_error(feedback));
} else {
let mut status: Option<String> = self.safe_string_k(response, "status", &[]).as_str().map(str::to_owned);
if (status.is_some()) && (status.as_deref() != Some("success")) {
let mut feedback: Value = Value::Str(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" ".into())).into()), body).into());
panic!("{}", crate::exchange_errors::exchange_error(feedback));
}
}
}
}
return Value::Null;
Value::Null
}
}