// 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;
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);
<Self as crate::exchange_generated::ExchangeBase>::after_construct(self);
}
/// 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.clone()])
}
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.clone()])
}
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.clone()])
}
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.clone()])
}
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.clone()])
}
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.clone()])
}
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.clone()])
}
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.clone()])
}
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.clone()])
}
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.clone()])
}
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.clone()])
}
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.clone(), method.clone(), params.clone(), headers.clone(), body.clone()])
}
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.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"cancel_order" => self.cancel_order(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).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.get(4..).unwrap_or(&[]).to_vec()[..]).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.get(2..).unwrap_or(&[]).to_vec()[..]),
"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.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_currencies" => self.fetch_currencies(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_deposits" => self.fetch_deposits(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_funding_history" => self.fetch_funding_history(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_funding_rate_history" => self.fetch_funding_rate_history(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_leverages" => self.fetch_leverages(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_margin_modes" => self.fetch_margin_modes(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_markets" => self.fetch_markets(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_my_trades" => self.fetch_my_trades(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_ohlcv" => self.fetch_ohlcv(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_open_orders" => self.fetch_open_orders(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_order" => self.fetch_order(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_order_book" => self.fetch_order_book(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_orders" => self.fetch_orders(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_positions" => self.fetch_positions(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_ticker" => self.fetch_ticker(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_trades" => self.fetch_trades(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_transfers" => self.fetch_transfers(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_withdrawals" => self.fetch_withdrawals(&args.get(0..).unwrap_or(&[]).to_vec()[..]).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.get(2..).unwrap_or(&[]).to_vec()[..]),
"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.get(2).cloned().unwrap_or(crate::Value::Null), &args.get(3..).unwrap_or(&[]).to_vec()[..]),
"initialize_client" => self.initialize_client(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"internal_fetch_transfers" => self.internal_fetch_transfers(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).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.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_income" => self.parse_income(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_leverage" => self.parse_leverage(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_margin_mode" => self.parse_margin_mode(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"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.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_order" => self.parse_order(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"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.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_ticker" => self.parse_ticker(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_time_in_force" => self.parse_time_in_force(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_trade" => self.parse_trade(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_transaction" => self.parse_transaction(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_transfer" => self.parse_transfer(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"request_id" => self.request_id(),
"set_leverage" => self.set_leverage(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"sign" => self.sign(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"sign_in" => self.sign_in(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"sign_in_with_api_key" => self.sign_in_with_api_key(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"sign_in_with_private_key" => self.sign_in_with_private_key(&args.get(0..).unwrap_or(&[]).to_vec()[..]).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.get(4..).unwrap_or(&[]).to_vec()[..]).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.get(3..).unwrap_or(&[]).to_vec()[..]).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".to_string()));
m.insert("name".to_string(), Value::Str("GRVT".to_string()));
m.insert("countries".to_string(), Value::List(vec![Value::Str("SG".to_string())]));
m.insert("rateLimit".to_string(), Value::Int(10));
m.insert("certified".to_string(), Value::Bool(false));
m.insert("version".to_string(), Value::Str("v1".to_string()));
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".to_string()));
m.insert("3m".to_string(), Value::Str("CI_3_M".to_string()));
m.insert("5m".to_string(), Value::Str("CI_5_M".to_string()));
m.insert("15m".to_string(), Value::Str("CI_15_M".to_string()));
m.insert("30m".to_string(), Value::Str("CI_30_M".to_string()));
m.insert("1h".to_string(), Value::Str("CI_1_H".to_string()));
m.insert("2h".to_string(), Value::Str("CI_2_H".to_string()));
m.insert("4h".to_string(), Value::Str("CI_4_H".to_string()));
m.insert("6h".to_string(), Value::Str("CI_6_H".to_string()));
m.insert("8h".to_string(), Value::Str("CI_8_H".to_string()));
m.insert("12h".to_string(), Value::Str("CI_12_H".to_string()));
m.insert("1d".to_string(), Value::Str("CI_1_D".to_string()));
m.insert("3d".to_string(), Value::Str("CI_3_D".to_string()));
m.insert("5d".to_string(), Value::Str("CI_5_D".to_string()));
m.insert("1w".to_string(), Value::Str("CI_1_W".to_string()));
m.insert("2w".to_string(), Value::Str("CI_2_W".to_string()));
m.insert("3w".to_string(), Value::Str("CI_3_W".to_string()));
m.insert("4w".to_string(), Value::Str("CI_4_W".to_string()));
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".to_string()));
m.insert("api".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("privateEdge".to_string(), Value::Str("https://edge.grvt.io/".to_string()));
m.insert("privateTrading".to_string(), Value::Str("https://trades.grvt.io/".to_string()));
m.insert("publicMarket".to_string(), Value::Str("https://market-data.grvt.io/".to_string()));
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/".to_string()));
m.insert("privateTrading".to_string(), Value::Str("https://trades.testnet.grvt.io/".to_string()));
m.insert("publicMarket".to_string(), Value::Str("https://market-data.testnet.grvt.io/".to_string()));
m
}));
m.insert("www".to_string(), Value::Str("https://grvt.io".to_string()));
m.insert("referral".to_string(), Value::Str("https://grvt.io/?ref=WBLS9D1".to_string()));
m.insert("doc".to_string(), Value::List(vec![Value::Str("https://api-docs.grvt.io/".to_string())]));
m.insert("fees".to_string(), Value::Str("https://help.grvt.io/en/articles/9614699-how-does-grvt-s-fee-model-work".to_string()));
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("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
}));
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
}));
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
}));
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".to_string()));
m.insert("AVAXC".to_string(), Value::Str("43114".to_string()));
m.insert("BASE".to_string(), Value::Str("8453".to_string()));
m.insert("BSC".to_string(), Value::Str("56".to_string()));
m.insert("ETH".to_string(), Value::Str("1".to_string()));
m.insert("ERC20".to_string(), Value::Str("1".to_string()));
m.insert("OP".to_string(), Value::Str("10".to_string()));
m.insert("SOL".to_string(), Value::Str("900".to_string()));
m.insert("TRX".to_string(), Value::Str("728126428".to_string()));
m.insert("ZKSYNCERA".to_string(), Value::Str("324".to_string()));
m.insert("KAIA".to_string(), Value::Str("8217".to_string()));
m
}));
m.insert("networksById".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("1".to_string(), Value::Str("ERC20".to_string()));
m
}));
m.insert("builderFee".to_string(), Value::Bool(true));
m.insert("builder".to_string(), Value::Str("0x21d2a053495994b1132a38cd1171acec40c6741e".to_string()));
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".to_string()));
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".to_string()).clone());
m.insert("1001".to_string(), Value::Str("PermissionDenied".to_string()).clone());
m.insert("1002".to_string(), Value::Str("OperationFailed".to_string()).clone());
m.insert("1003".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("1004".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("1005".to_string(), Value::Str("OperationFailed".to_string()).clone());
m.insert("1006".to_string(), Value::Str("RateLimitExceeded".to_string()).clone());
m.insert("1008".to_string(), Value::Str("PermissionDenied".to_string()).clone());
m.insert("1009".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("1012".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("1400".to_string(), Value::Str("PermissionDenied".to_string()).clone());
m.insert("2000".to_string(), Value::Str("PermissionDenied".to_string()).clone());
m.insert("2001".to_string(), Value::Str("InvalidNonce".to_string()).clone());
m.insert("2002".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("2003".to_string(), Value::Str("PermissionDenied".to_string()).clone());
m.insert("2004".to_string(), Value::Str("InvalidNonce".to_string()).clone());
m.insert("2005".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("2006".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("2007".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("2008".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("2010".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("2011".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("2012".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("2020".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("2021".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("2030".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("2031".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("2032".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("2040".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("2041".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("2042".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("2050".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("2051".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("2060".to_string(), Value::Str("BadSymbol".to_string()).clone());
m.insert("2061".to_string(), Value::Str("BadSymbol".to_string()).clone());
m.insert("2062".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("2063".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("2064".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("2065".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("2070".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("2080".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m.insert("2081".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("2082".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("2083".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("2090".to_string(), Value::Str("RateLimitExceeded".to_string()).clone());
m.insert("2100".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("2101".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("2102".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("2103".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("2104".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("2105".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("2107".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("2108".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("2110".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("2111".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("2112".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("2113".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("2114".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("2115".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("2116".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("2117".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("2300".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("2301".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("2400".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("2401".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("2402".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("3000".to_string(), Value::Str("BadSymbol".to_string()).clone());
m.insert("3004".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("3005".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("3006".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("3021".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("3031".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("4000".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m.insert("4002".to_string(), Value::Str("OperationFailed".to_string()).clone());
m.insert("4010".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("5000".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("5001".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("5002".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("5003".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("5004".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("5005".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("6000".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("6100".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("7000".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("7001".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m.insert("7002".to_string(), Value::Str("OperationFailed".to_string()).clone());
m.insert("7003".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("7004".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("7005".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m.insert("7006".to_string(), Value::Str("OperationFailed".to_string()).clone());
m.insert("7007".to_string(), Value::Str("PermissionDenied".to_string()).clone());
m.insert("7100".to_string(), Value::Str("OperationFailed".to_string()).clone());
m.insert("7101".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("7102".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("7103".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("7201".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("7450".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("7451".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("7452".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("7453".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("7454".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("7455".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("7500".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("7501".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("7502".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("7503".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("7504".to_string(), Value::Str("OperationRejected".to_string()).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::List(vec![Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("name".to_string(), Value::Str("subAccountID".to_string()));
m.insert("type".to_string(), Value::Str("uint64".to_string()));
m
}), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("name".to_string(), Value::Str("isMarket".to_string()));
m.insert("type".to_string(), Value::Str("bool".to_string()));
m
}), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("name".to_string(), Value::Str("timeInForce".to_string()));
m.insert("type".to_string(), Value::Str("uint8".to_string()));
m
}), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("name".to_string(), Value::Str("postOnly".to_string()));
m.insert("type".to_string(), Value::Str("bool".to_string()));
m
}), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("name".to_string(), Value::Str("reduceOnly".to_string()));
m.insert("type".to_string(), Value::Str("bool".to_string()));
m
}), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("name".to_string(), Value::Str("legs".to_string()));
m.insert("type".to_string(), Value::Str("OrderLeg[]".to_string()));
m
}), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("name".to_string(), Value::Str("nonce".to_string()));
m.insert("type".to_string(), Value::Str("uint32".to_string()));
m
}), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("name".to_string(), Value::Str("expiration".to_string()));
m.insert("type".to_string(), Value::Str("int64".to_string()));
m
})]));
m.insert("OrderLeg".to_string(), Value::List(vec![Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("name".to_string(), Value::Str("assetID".to_string()));
m.insert("type".to_string(), Value::Str("uint256".to_string()));
m
}), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("name".to_string(), Value::Str("contractSize".to_string()));
m.insert("type".to_string(), Value::Str("uint64".to_string()));
m
}), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("name".to_string(), Value::Str("limitPrice".to_string()));
m.insert("type".to_string(), Value::Str("uint64".to_string()));
m
}), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("name".to_string(), Value::Str("isBuyingContract".to_string()));
m.insert("type".to_string(), Value::Str("bool".to_string()));
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::List(vec![Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("name".to_string(), Value::Str("subAccountID".to_string()));
m.insert("type".to_string(), Value::Str("uint64".to_string()));
m
}), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("name".to_string(), Value::Str("isMarket".to_string()));
m.insert("type".to_string(), Value::Str("bool".to_string()));
m
}), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("name".to_string(), Value::Str("timeInForce".to_string()));
m.insert("type".to_string(), Value::Str("uint8".to_string()));
m
}), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("name".to_string(), Value::Str("postOnly".to_string()));
m.insert("type".to_string(), Value::Str("bool".to_string()));
m
}), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("name".to_string(), Value::Str("reduceOnly".to_string()));
m.insert("type".to_string(), Value::Str("bool".to_string()));
m
}), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("name".to_string(), Value::Str("legs".to_string()));
m.insert("type".to_string(), Value::Str("OrderLeg[]".to_string()));
m
}), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("name".to_string(), Value::Str("builder".to_string()));
m.insert("type".to_string(), Value::Str("address".to_string()));
m
}), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("name".to_string(), Value::Str("builderFee".to_string()));
m.insert("type".to_string(), Value::Str("uint32".to_string()));
m
}), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("name".to_string(), Value::Str("nonce".to_string()));
m.insert("type".to_string(), Value::Str("uint32".to_string()));
m
}), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("name".to_string(), Value::Str("expiration".to_string()));
m.insert("type".to_string(), Value::Str("int64".to_string()));
m
})]));
m.insert("OrderLeg".to_string(), Value::List(vec![Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("name".to_string(), Value::Str("assetID".to_string()));
m.insert("type".to_string(), Value::Str("uint256".to_string()));
m
}), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("name".to_string(), Value::Str("contractSize".to_string()));
m.insert("type".to_string(), Value::Str("uint64".to_string()));
m
}), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("name".to_string(), Value::Str("limitPrice".to_string()));
m.insert("type".to_string(), Value::Str("uint64".to_string()));
m
}), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("name".to_string(), Value::Str("isBuyingContract".to_string()));
m.insert("type".to_string(), Value::Str("bool".to_string()));
m
})]));
m
}));
m.insert("EIP712_TRANSFER_TYPE".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("Transfer".to_string(), Value::List(vec![Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("name".to_string(), Value::Str("fromAccount".to_string()));
m.insert("type".to_string(), Value::Str("address".to_string()));
m
}), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("name".to_string(), Value::Str("fromSubAccount".to_string()));
m.insert("type".to_string(), Value::Str("uint64".to_string()));
m
}), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("name".to_string(), Value::Str("toAccount".to_string()));
m.insert("type".to_string(), Value::Str("address".to_string()));
m
}), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("name".to_string(), Value::Str("toSubAccount".to_string()));
m.insert("type".to_string(), Value::Str("uint64".to_string()));
m
}), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("name".to_string(), Value::Str("tokenCurrency".to_string()));
m.insert("type".to_string(), Value::Str("uint8".to_string()));
m
}), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("name".to_string(), Value::Str("numTokens".to_string()));
m.insert("type".to_string(), Value::Str("uint64".to_string()));
m
}), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("name".to_string(), Value::Str("nonce".to_string()));
m.insert("type".to_string(), Value::Str("uint32".to_string()));
m
}), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("name".to_string(), Value::Str("expiration".to_string()));
m.insert("type".to_string(), Value::Str("int64".to_string()));
m
})]));
m
}));
m.insert("EIP712_WITHDRAWAL_TYPE".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("Withdrawal".to_string(), Value::List(vec![Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("name".to_string(), Value::Str("fromAccount".to_string()));
m.insert("type".to_string(), Value::Str("address".to_string()));
m
}), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("name".to_string(), Value::Str("toEthAddress".to_string()));
m.insert("type".to_string(), Value::Str("address".to_string()));
m
}), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("name".to_string(), Value::Str("tokenCurrency".to_string()));
m.insert("type".to_string(), Value::Str("uint8".to_string()));
m
}), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("name".to_string(), Value::Str("numTokens".to_string()));
m.insert("type".to_string(), Value::Str("uint64".to_string()));
m
}), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("name".to_string(), Value::Str("nonce".to_string()));
m.insert("type".to_string(), Value::Str("uint32".to_string()));
m
}), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("name".to_string(), Value::Str("expiration".to_string()));
m.insert("type".to_string(), Value::Str("int64".to_string()));
m
})]));
m
}));
m.insert("EIP712_BUILDER_APPROVAL_TYPE".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("AuthorizeBuilder".to_string(), Value::List(vec![Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("name".to_string(), Value::Str("mainAccountID".to_string()));
m.insert("type".to_string(), Value::Str("address".to_string()));
m
}), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("name".to_string(), Value::Str("builderAccountID".to_string()));
m.insert("type".to_string(), Value::Str("address".to_string()));
m
}), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("name".to_string(), Value::Str("maxFutureFeeRate".to_string()));
m.insert("type".to_string(), Value::Str("uint32".to_string()));
m
}), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("name".to_string(), Value::Str("maxSpotFeeRate".to_string()));
m.insert("type".to_string(), Value::Str("uint32".to_string()));
m
}), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("name".to_string(), Value::Str("nonce".to_string()));
m.insert("type".to_string(), Value::Str("uint32".to_string()));
m
}), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("name".to_string(), Value::Str("expiration".to_string()));
m.insert("type".to_string(), Value::Str("int64".to_string()));
m
})]));
m
}));
m.insert("EIP712_WALLETLOGIN_TYPE".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("WalletLogin".to_string(), Value::List(vec![Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("name".to_string(), Value::Str("signer".to_string()));
m.insert("type".to_string(), Value::Str("address".to_string()));
m
}), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("name".to_string(), Value::Str("nonce".to_string()));
m.insert("type".to_string(), Value::Str("uint32".to_string()));
m
}), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("name".to_string(), Value::Str("expiration".to_string()));
m.insert("type".to_string(), Value::Str("int64".to_string()));
m
})]));
m
}));
m
});
Value::Null
}
pub fn uses_private_key(&self) -> Value {
let mut privateKeyDefined: Value = Value::Bool(!is_equal(&self.privateKey, &Value::Null) && !is_equal(&self.privateKey, &Value::Str("".to_string())));
let mut apiKeyDefined: bool = !is_equal(&self.apiKey, &Value::Null) && !is_equal(&self.apiKey, &Value::Str("".to_string()));
if is_true(&privateKeyDefined) && is_true(&apiKeyDefined) {
panic!("{}", crate::exchange_errors::exchange_error(Value::Str("You should provide either \"privateKey\" or \"apikey & secret\"".to_string())));
}
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 is_equal(&self.privateKey, &Value::Null) || is_equal(&self.privateKey, &Value::Str("".to_string())) {
panic!("{}", crate::exchange_errors::permission_denied(Value::Str("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".to_string())));
}
self.sign_in_with_private_key(&[params.clone()]).await;
self.initialize_client(&[params.clone()]).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 !is_equal(&expires, &Value::Null) && is_greater_than(&expires, &add(&now, &Value::Int(10000))) {
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.clone(), &[params.clone()]);
let mut response: Value = self.private_edge_post_auth_api_key_login(&[__ws_arg_0]).await;
//
// {
// "location": "",
// "status": "success"
// }
//
add_element_to_object(&mut self.options, &Value::Str("signInExpiration".to_string()), add(&now, &Value::Int(86400000))); // 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 !is_equal(&expires, &Value::Null) && is_greater_than(&expires, &add(&now, &Value::Int(10000))) {
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.clone());
m.insert("signature".to_string(), self.default_signature());
m
});
request = self.create_signed_request(request.clone(), Value::Str("EIP712_WALLETLOGIN_TYPE".to_string()), &[]);
let __ws_arg_1 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_edge_post_auth_wallet_login(&[__ws_arg_1]).await;
//
// {
// "location": "",
// "status": "success"
// }
//
add_element_to_object(&mut self.options, &Value::Str("signInExpiration".to_string()), add(&now, &Value::Int(86400000))); // 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".to_string()), &[Value::Bool(true)])]); // we shouldn't omit here
if !is_equal(&builderFee, &Value::Bool(true)) {
return Value::Bool(false);
}
let mut approvedBuilderFee: Value = self.safe_bool_k(self.options.clone(), "approvedBuilderFee", &[Value::Bool(false)]);
if is_equal(&approvedBuilderFee, &Value::Bool(true)) {
return Value::Bool(true);
}
let mut results: Value = promise_all(&Value::List(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 = get_value(&results, &Value::Int(0));
let mut approvedBuilder: Value = self.safe_list_k(currentBuilders.clone(), "results", &[Value::List(vec![])]);
let mut length: Value = get_array_length(&approvedBuilder);
let mut found: bool = false;
{
let mut i: Value = Value::Int(0);
let mut __for_first_715: bool = true;
while { if !__for_first_715 { i = add(&i, &Value::Int(1)); } __for_first_715 = false; is_less_than(&i, &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.clone(), "builder_account_id", &[]);
if is_equal(&builderAccountId, &self.safe_string_k(self.options.clone(), "builder", &[])) {
found = true;
break;
}
}
}
if is_true(&found) {
add_element_to_object(&mut self.options, &Value::Str("approvedBuilderFee".to_string()), 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.clone());
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".to_string()), &[]);
let __ws_arg_2 = self.extend(request.clone(), &[params.clone()]);
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.clone(), "ack", &[]);
if !is_equal(&ack, &Value::Bool(true)) {
panic!("{}", crate::exchange_errors::exchange_error(add(&Value::Str("Builder authorization failed, ".to_string()), &self.json(authResponse.clone()))));
}
add_element_to_object(&mut self.options, &Value::Str("approvedBuilderFee".to_string()), Value::Bool(true));
#[allow(unreachable_code)] { Value::Null }})).await;
if let Err(_try_err) = _try_result { let e: Value = panic_to_value(_try_err);
add_element_to_object(&mut self.options, &Value::Str("builderFee".to_string()), 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.clone()]).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::List(vec![marketsPromise.clone()]);
if !is_true(&self.is_empty_string(self.apiKey.clone())) || !is_true(&self.is_empty_string(self.privateKey.clone())) {
append_to_array(&mut promises, self.sign_in(&[]).await);
}
let mut results: Value = promise_all(&promises).await;
let mut response: Value = get_value(&results, &Value::Int(0));
let mut result: Value = self.safe_list_k(response.clone(), "result", &[Value::List(vec![])]);
return self.parse_markets(result.clone());
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(), &[]);
let mut settle: Value = self.safe_currency_code(settleId.clone(), &[]);
let mut symbol: Value = add(&add(&add(&add(&base, &Value::Str("/".to_string())), "e), &Value::Str(":".to_string())), &settle);
let mut type_var: Value = Value::Null;
let mut typeRaw: Value = self.safe_string_k(market.clone(), "kind", &[]);
if is_equal(&typeRaw, &Value::Str("PERPETUAL".to_string())) {
type_var = Value::Str("swap".to_string());
}
let mut isSpot: Value = Value::Bool(is_equal(&type_var, &Value::Str("spot".to_string())));
let mut isSwap: Value = Value::Bool(is_equal(&type_var, &Value::Str("swap".to_string())));
let mut isFuture: Value = Value::Bool(is_equal(&type_var, &Value::Str("future".to_string())));
let mut isContract: Value = Value::Bool(is_true(&isSwap) || is_true(&isFuture));
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), marketId.clone());
m.insert("symbol".to_string(), symbol.clone());
m.insert("base".to_string(), base.clone());
m.insert("quote".to_string(), quote.clone());
m.insert("settle".to_string(), settle.clone());
m.insert("baseId".to_string(), baseId.clone());
m.insert("quoteId".to_string(), quoteId.clone());
m.insert("settleId".to_string(), settleId.clone());
m.insert("type".to_string(), type_var.clone());
m.insert("spot".to_string(), isSpot.clone());
m.insert("margin".to_string(), Value::Bool(false));
m.insert("swap".to_string(), isSwap.clone());
m.insert("future".to_string(), isFuture.clone());
m.insert("option".to_string(), Value::Bool(false));
m.insert("active".to_string(), Value::Null);
m.insert("contract".to_string(), isContract.clone());
m.insert("linear".to_string(), ternary(is_true(&isSwap), Value::Bool(true), Value::Null));
m.insert("inverse".to_string(), ternary(is_true(&isSwap), Value::Bool(false), Value::Null));
m.insert("contractSize".to_string(), self.parse_number(Value::Str("1".to_string()), &[]));
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(market.clone(), Value::Str("create_time".to_string()), Value::Float(0.000001), &[]));
m.insert("info".to_string(), market.clone());
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("".to_string()));
m
}); // workaround for php [] empty arr
let mut response: Value = self.public_market_post_full_v1_currency(&[request.clone()]).await;
//
// {
// "result": [
// {
// "id": "4",
// "symbol": "ETH",
// "balance_decimals": "9",
// "quantity_multiplier": "1000000000"
// },
// ..
//
let mut responseResult: Value = self.safe_list_k(response.clone(), "result", &[Value::List(vec![])]);
return self.parse_currencies(responseResult.clone());
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.clone());
m.insert("code".to_string(), code.clone());
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".to_string()));
m.insert("networks".to_string(), Value::Null);
m.insert("numericId".to_string(), self.safe_integer_k(rawCurrency.clone(), "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 is_equal(&self.markets, &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.clone()));
m
});
let __ws_arg_3 = self.extend(request.clone(), &[params.clone()]);
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.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_ticker(result.clone(), &[market.clone()]);
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(ticker.clone(), Value::Str("event_time".to_string()), 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.clone(), &[market.clone()]));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
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.clone(), "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 is_equal(&self.markets, &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.clone()));
m
});
if is_equal(&limit, &Value::Null) {
limit = Value::Int(100);
}
if is_less_than_or_equal(&limit, &Value::Int(500)) {
add_element_to_object(&mut request, &Value::Str("depth".to_string()), self.find_nearest_ceiling(Value::List(vec![Value::Int(10), Value::Int(50), Value::Int(100), Value::Int(500)]), limit.clone()));
}
let __ws_arg_4 = self.extend(request.clone(), &[params.clone()]);
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.clone(), "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.clone(), self.safe_symbol(marketId.clone(), &[]), &[timestamp.clone(), Value::Str("bids".to_string()), Value::Str("asks".to_string()), Value::Str("price".to_string()), Value::Str("size".to_string())]);
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 is_equal(&self.markets, &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(), get_value(&market, &Value::Str("id".to_string())));
m
});
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), crate::runtime::Math::min(&limit, &Value::Int(1000)));
}
{ let __destr_tmp = self.handle_until_option_string(Value::Str("end_time".to_string()), request.clone(), params.clone(), &[Value::Int(1000000)]); request = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if !is_equal(&since, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("start_time".to_string()), self.number_to_string(multiply(&since, &Value::Int(1000000))));
}
let __ws_arg_5 = self.extend(request.clone(), &[params.clone()]);
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.clone(), "result", &[Value::List(vec![])]);
return self.parse_trades(result.clone(), &[market.clone(), since.clone(), limit.clone()]);
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", &[]);
market = self.safe_market(&[marketId.clone(), market.clone()]);
let mut timestamp: Value = self.safe_integer_product(trade.clone(), Value::Str("event_time".to_string()), 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 !is_equal(&isTakerBuyer, &Value::Null) {
side = ternary(is_true(&isTakerBuyer), Value::Str("buy".to_string()), Value::Str("sell".to_string()));
takerOrMaker = Value::Str("taker".to_string());
} else {
let mut isTaker: bool = is_equal(&self.safe_bool_k(trade.clone(), "is_taker", &[]), &Value::Bool(true));
let mut isBuyer: bool = is_equal(&self.safe_bool_k(trade.clone(), "is_buyer", &[]), &Value::Bool(true));
takerOrMaker = ternary(is_true(&isTaker), Value::Str("taker".to_string()), Value::Str("maker".to_string()));
side = ternary(is_true(&isBuyer), Value::Str("buy".to_string()), Value::Str("sell".to_string()));
}
let mut fee: Value = Value::Null;
let mut feeString: Value = self.safe_string_k(trade.clone(), "fee", &[]);
if !is_equal(&feeString, &Value::Null) {
fee = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), self.parse_number(feeString.clone(), &[]));
m.insert("currency".to_string(), get_value(&market, &Value::Str("quote".to_string())));
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.clone()));
m.insert("symbol".to_string(), get_value(&market, &Value::Str("symbol".to_string())));
m.insert("side".to_string(), side.clone());
m.insert("takerOrMaker".to_string(), takerOrMaker.clone());
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.clone());
m.insert("order".to_string(), self.safe_string_k(trade.clone(), "order_id", &[]));
m
}), &[market.clone()]);
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".to_string()));
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut maxLimit: Value = Value::Int(1000);
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut paginate: Value = Value::Bool(false);
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchOHLCV".to_string()), Value::Str("paginate".to_string()), &[Value::Bool(false)]); paginate = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_true(&paginate) {
return self.fetch_paginated_call_deterministic(Value::Str("fetchOHLCV".to_string()), &[symbol.clone(), since.clone(), limit.clone(), timeframe.clone(), params.clone(), maxLimit.clone()]).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(), get_value(&market, &Value::Str("id".to_string())));
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".to_string()));
m.insert("mark".to_string(), Value::Str("MARK".to_string()));
m.insert("index".to_string(), Value::Str("INDEX".to_string()));
m
});
let mut selectedPriceType: Value = self.safe_string_k(params.clone(), "priceType", &[Value::Str("last".to_string())]);
add_element_to_object(&mut request, &Value::Str("type".to_string()), self.safe_string(priceTypeMap.clone(), selectedPriceType.clone(), &[]));
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), crate::runtime::Math::min(&limit, &Value::Int(1000)));
}
{ let __destr_tmp = self.handle_until_option_string(Value::Str("end_time".to_string()), request.clone(), params.clone(), &[Value::Int(1000000)]); request = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if !is_equal(&since, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("start_time".to_string()), self.number_to_string(multiply(&since, &Value::Int(1000000))));
}
let __ws_arg_6 = self.extend(request.clone(), &[params.clone()]);
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.clone(), "result", &[Value::List(vec![])]);
return self.parse_ohlc_vs(candles.clone(), &[market.clone(), timeframe.clone(), since.clone(), limit.clone()]);
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::List(vec![self.safe_integer_product(ohlcv.clone(), Value::Str("open_time".to_string()), 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.clone(), "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 is_equal(&symbol, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" fetchFundingRateHistory() requires a symbol argument".to_string()))));
}
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut paginate: Value = Value::Bool(false);
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchFundingRateHistory".to_string()), Value::Str("paginate".to_string()), &[]); paginate = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_true(&paginate) {
return self.fetch_paginated_call_deterministic(Value::Str("fetchFundingRateHistory".to_string()), &[symbol.clone(), since.clone(), limit.clone(), Value::Str("8h".to_string()), params.clone()]).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(), get_value(&market, &Value::Str("id".to_string())));
m
});
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), crate::runtime::Math::min(&limit, &Value::Int(1000)));
}
{ let __destr_tmp = self.handle_until_option_string(Value::Str("end_time".to_string()), request.clone(), params.clone(), &[Value::Int(1000000)]); request = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if !is_equal(&since, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("start_time".to_string()), self.number_to_string(multiply(&since, &Value::Int(1000000))));
}
let __ws_arg_7 = self.extend(request.clone(), &[params.clone()]);
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.clone(), "result", &[Value::List(vec![])]);
return self.parse_funding_rate_histories(result.clone(), &[market.clone()]);
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(rawItem.clone(), Value::Str("funding_time".to_string()), 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.clone());
m.insert("symbol".to_string(), self.safe_symbol(marketId.clone(), &[market.clone()]));
m.insert("fundingRate".to_string(), self.parse_number(crate::precise::Precise::stringDiv(&rate, &Value::Str("100".to_string())), &[]));
m.insert("timestamp".to_string(), ts.clone());
m.insert("datetime".to_string(), self.iso8601(ts.clone()));
m
});
Value::Null
}
pub fn get_sub_account_id(&self, mut params: Value) -> Value {
let mut subAccountId: Value = Value::Null;
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("getSubAccountId".to_string()), Value::Str("accountId".to_string()), &[]); subAccountId = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_equal(&subAccountId, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" you should set \"accountId\" in options or params, which can be found in the grvt dashboard, under Api-Keys page".to_string()))));
}
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.clone(), &[params.clone()]);
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.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_balance(result.clone());
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(response.clone(), Value::Str("event_time".to_string()), 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.clone()));
m
});
let mut spotBalances: Value = self.safe_list_k(response.clone(), "spot_balances", &[Value::List(vec![])]);
let mut availableBalance: Value = self.safe_string_k(response.clone(), "available_balance", &[]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_716: bool = true;
while { if !__for_first_716 { i = add(&i, &Value::Int(1)); } __for_first_716 = false; is_less_than(&i, &get_array_length(&spotBalances)) } {
let mut balance: Value = get_value(&spotBalances, &i);
let mut balance: Value = get_value(&spotBalances, &i);
let mut currencyId: Value = self.safe_string_k(balance.clone(), "currency", &[]);
let mut code: Value = self.safe_currency_code(currencyId.clone(), &[]);
let mut account: Value = self.account();
add_element_to_object(&mut account, &Value::Str("total".to_string()), self.safe_string_k(balance.clone(), "balance", &[]));
add_element_to_object(&mut account, &Value::Str("free".to_string()), availableBalance.clone()); // todo: revise after API team clarification
if !is_equal(&code, &Value::Null) {
add_element_to_object(&mut result, &code, account.clone());
}
}
}
return self.safe_balance(result.clone());
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 !is_equal(&code, &Value::Null) {
currency = self.currency(code.clone());
add_element_to_object(&mut request, &Value::Str("currency".to_string()), Value::List(vec![get_value(¤cy, &Value::Str("code".to_string()))]));
}
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), crate::runtime::Math::min(&limit, &Value::Int(1000)));
}
{ let __destr_tmp = self.handle_until_option_string(Value::Str("end_time".to_string()), request.clone(), params.clone(), &[Value::Int(1000000)]); request = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if !is_equal(&since, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("start_time".to_string()), self.number_to_string(multiply(&since, &Value::Int(1000000))));
}
let mut useTransfersEndpoint: Value = self.safe_bool_k(self.options.clone(), "useTransfersEndpointForDepositsWithdrawals", &[Value::Bool(true)]);
if is_equal(&useTransfersEndpoint, &Value::Bool(true)) {
let __ws_arg_9 = self.extend(request.clone(), &[params.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.clone(), Value::Str("deposit".to_string()), &[Value::Bool(true)]);
let mut transactions: Value = self.get_list_from_object_values(get_value(&filteredResults, &Value::Int(0)), Value::Str("info".to_string()));
return self.parse_transactions(transactions.clone(), &[currency.clone(), since.clone(), limit.clone()]);
} else {
let __ws_arg_10 = self.extend(request.clone(), &[params.clone()]);
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.clone(), "result", &[Value::List(vec![])]);
return self.parse_transactions(result.clone(), &[currency.clone(), since.clone(), limit.clone()]);
}
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 is_equal(&code, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("currency".to_string()), Value::Null);
} else {
currency = self.currency(code.clone());
add_element_to_object(&mut request, &Value::Str("currency".to_string()), Value::List(vec![get_value(¤cy, &Value::Str("code".to_string()))]));
}
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), crate::runtime::Math::min(&limit, &Value::Int(1000)));
}
{ let __destr_tmp = self.handle_until_option_string(Value::Str("end_time".to_string()), request.clone(), params.clone(), &[Value::Int(1000000)]); request = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if !is_equal(&since, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("start_time".to_string()), self.number_to_string(multiply(&since, &Value::Int(1000000))));
}
let mut useTransfersEndpoint: Value = self.safe_bool_k(self.options.clone(), "useTransfersEndpointForDepositsWithdrawals", &[Value::Bool(true)]);
if is_equal(&useTransfersEndpoint, &Value::Bool(true)) {
let __ws_arg_11 = self.extend(request.clone(), &[params.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.clone(), Value::Str("withdrawal".to_string()), &[Value::Bool(true)]);
let mut transactions: Value = self.get_list_from_object_values(get_value(&filteredResults, &Value::Int(0)), Value::Str("info".to_string()));
return self.parse_transactions(transactions.clone(), &[currency.clone(), since.clone(), limit.clone()]);
} else {
let __ws_arg_12 = self.extend(request.clone(), &[params.clone()]);
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.clone(), "result", &[Value::List(vec![])]);
return self.parse_transactions(result.clone(), &[currency.clone(), since.clone(), limit.clone()]);
}
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.clone()]).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.clone(), "result", &[Value::List(vec![])]);
let mut transfers: Value = self.parse_transfers(rows.clone(), &[currency.clone(), since.clone(), limit.clone()]);
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.clone(), &[currency.clone()]);
if is_true(&Value::Bool(in_op(&transaction, &Value::Str("transfer_metadata".to_string())))) {
let mut metaData: Value = self.omit_zero(self.safe_string_k(transaction.clone(), "transfer_metadata", &[]));
if !is_equal(&metaData, &Value::Null) {
let mut parsedMeta: Value = self.parse_json_value(metaData.clone());
direction = self.safe_string_lower(parsedMeta.clone(), Value::Str("direction".to_string()), &[]);
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 is_equal(&direction, &Value::Str("withdrawal".to_string())) {
addressTo = self.safe_string_k(parsedMeta.clone(), "endpoint", &[]);
} else if is_equal(&direction, &Value::Str("deposit".to_string())) {
addressFrom = self.safe_string_k(parsedMeta.clone(), "endpoint", &[]);
}
}
}
let mut timestamp: Value = self.safe_integer_product2(transaction.clone(), Value::Str("event_time".to_string()), Value::Str("initiated_time".to_string()), 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.clone());
m.insert("type".to_string(), direction.clone());
m.insert("currency".to_string(), code.clone());
m.insert("network".to_string(), networkCode.clone());
m.insert("amount".to_string(), self.safe_number_k(transaction.clone(), "num_tokens", &[]));
m.insert("status".to_string(), Value::Null);
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("address".to_string(), Value::Null);
m.insert("addressFrom".to_string(), addressFrom.clone());
m.insert("addressTo".to_string(), addressTo.clone());
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 is_equal(&code, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" fetchTransfers() requires a code argument".to_string()))));
}
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.clone());
let mut maxLimit: Value = Value::Int(1000);
let mut paginate: Value = Value::Bool(false);
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchTransfers".to_string()), Value::Str("paginate".to_string()), &[Value::Bool(false)]); paginate = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_true(&paginate) {
return self.fetch_paginated_call_dynamic(Value::Str("fetchTransfers".to_string()), &[Value::Null, since.clone(), limit.clone(), params.clone(), maxLimit.clone()]).await;
}
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), crate::runtime::Math::min(&limit, &Value::Int(1000)));
}
{ let __destr_tmp = self.handle_until_option_string(Value::Str("end_time".to_string()), request.clone(), params.clone(), &[Value::Int(1000000)]); request = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if !is_equal(&since, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("start_time".to_string()), self.number_to_string(multiply(&since, &Value::Int(1000000))));
}
let __ws_arg_13 = self.extend(request.clone(), &[params.clone()]);
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.clone(), "result", &[Value::List(vec![])]);
let mut transfers: Value = self.parse_transfers(rows.clone(), &[currency.clone(), since.clone(), limit.clone()]);
let mut filteredResults: Value = self.filter_transfers_by_type(transfers.clone(), Value::Str("internal".to_string()), &[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::List(vec![]);
let mut nonMatchedResults: Value = Value::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_717: bool = true;
while { if !__for_first_717 { i = add(&i, &Value::Int(1)); } __for_first_717 = false; is_less_than(&i, &get_array_length(&transfers)) } {
let mut transfer: Value = get_value(&transfers, &i);
let mut transfer: Value = get_value(&transfers, &i);
if is_true(&(is_true(&onlyMainAccount) && is_equal(&get_value(&transfer, &Value::Str("fromAccount".to_string())), &Value::Str("0".to_string())) && is_equal(&get_value(&transfer, &Value::Str("toAccount".to_string())), &Value::Str("0".to_string())))) || is_true(&(!is_true(&onlyMainAccount) && is_true(&(!is_equal(&get_value(&transfer, &Value::Str("fromAccount".to_string())), &Value::Str("0".to_string())) || !is_equal(&get_value(&transfer, &Value::Str("toAccount".to_string())), &Value::Str("0".to_string())))))) {
let mut metadata: Value = self.safe_string(get_value(&transfer, &Value::Str("info".to_string())), Value::Str("transfer_metadata".to_string()), &[]);
let mut parsedMetadata: Value = self.parse_json_value(metadata.clone());
let mut direction: Value = self.safe_string_k(parsedMetadata.clone(), "direction", &[]);
if is_equal(&direction, &transferType) {
append_to_array(&mut matchedResults, transfer.clone());
} else {
append_to_array(&mut nonMatchedResults, transfer.clone());
}
}
}
}
return Value::List(vec![matchedResults.clone(), nonMatchedResults.clone()]);
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", &[]);
if is_true(&self.in_array(fromAccount.clone(), Value::List(vec![Value::Str("trading".to_string()), Value::Str("funding".to_string())]))) && is_true(&self.in_array(toAccount.clone(), Value::List(vec![Value::Str("trading".to_string()), Value::Str("funding".to_string())]))) {
let mut tradingAccountId: Value = Value::Null;
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("transfer".to_string()), Value::Str("tradingAccountId".to_string()), &[]); tradingAccountId = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut fundingAccountId: Value = Value::Null;
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("transfer".to_string()), Value::Str("fundingAccountId".to_string()), &[]); fundingAccountId = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_equal(&tradingAccountId, &Value::Null) || is_equal(&fundingAccountId, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" transfer(): you should set (in the options or params) \"tradingAccountId\" and \"fundingAccountId\" (you can use \"0\" as a main funding account id)".to_string()))));
}
fromAccount = ternary(is_true(&(is_equal(&fromAccount, &Value::Str("trading".to_string())))), tradingAccountId.clone(), fundingAccountId.clone());
toAccount = ternary(is_true(&(is_equal(&toAccount, &Value::Str("trading".to_string())))), tradingAccountId.clone(), fundingAccountId.clone());
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("from_account_id".to_string(), self.safe_string_k(params.clone(), "from_account_id", &[defaultFromAccountId.clone()]));
m.insert("from_sub_account_id".to_string(), self.safe_string_k(params.clone(), "from_sub_account_id", &[fromAccount.clone()]));
m.insert("to_account_id".to_string(), self.safe_string_k(params.clone(), "to_account_id", &[defaultFromAccountId.clone()]));
m.insert("to_sub_account_id".to_string(), self.safe_string_k(params.clone(), "to_sub_account_id", &[toAccount.clone()]));
m.insert("currency".to_string(), get_value(¤cy, &Value::Str("id".to_string())));
m.insert("num_tokens".to_string(), self.currency_to_precision(code.clone(), amount.clone(), &[]));
m.insert("signature".to_string(), self.default_signature());
m.insert("transfer_type".to_string(), Value::Str("STANDARD".to_string()));
m.insert("transfer_metadata".to_string(), Value::Null);
m
});
request = self.create_signed_request(request.clone(), Value::Str("EIP712_TRANSFER_TYPE".to_string()), &[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.clone(), &[params.clone()]);
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 = is_equal(&fromAccount, &Value::Str("funding".to_string()));
if is_true(&isFromFundingAccount) && is_true(&(is_greater_than_or_equal(&get_index_of(&msg, &Value::Str("You are not authorized".to_string())), &Value::Int(0)))) {
panic!("{}", crate::exchange_errors::permission_denied(add(&add(&self.id, &Value::Str(" transfer() failed. Ensure you use funding api-keys when trying to transfer from Funding accounts: ".to_string())), &msg)));
}
panic!("{}", error);
}
//
// {
// "result": {
// "ack": "true",
// "tx_id": "1028403"
// }
// }
//
let mut result: Value = self.safe_dict_k(response.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_transfer(result.clone(), &[currency.clone()]);
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.clone(), &[currency.clone()]);
let mut timestamp: Value = self.safe_integer_product(transfer.clone(), Value::Str("event_time".to_string()), 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.clone()));
m.insert("currency".to_string(), code.clone());
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.clone(), "to_sub_account_id", &[]));
m.insert("status".to_string(), Value::Null);
m
});
Value::Null
}
pub async fn load_account_infos(&mut self) -> Value {
if !is_equal(&self.safe_string_k(self.options.clone(), "userMainAccountId", &[]), &Value::Null) {
return Value::Bool(false);
}
let mut promises: Value = Value::List(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 = is_equal(&self.safe_string_k(self.options.clone(), "accountId", &[]), &Value::Null);
if is_true(&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(get_value(&responses, &Value::Int(0)), Value::Str("result".to_string()), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut mainAccountId: Value = self.safe_string_k(result1.clone(), "main_account_id", &[]);
add_element_to_object(&mut self.options, &Value::Str("userMainAccountId".to_string()), mainAccountId.clone());
if is_true(&accountIsUndefined) {
let mut subAccountIds: Value = self.safe_list(get_value(&responses, &Value::Int(1)), Value::Str("sub_account_ids".to_string()), &[Value::List(vec![])]);
let mut length: Value = get_array_length(&subAccountIds);
if is_less_than(&length, &Value::Int(1)) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" loadAccountInfos(): no sub accounts found, you might need to create an api-key in GRVT website".to_string()))));
}
if is_greater_than(&length, &Value::Int(1)) {
panic!("{}", crate::exchange_errors::arguments_required(add(&add(&self.id, &Value::Str(" loadAccountInfos(): multiple sub accounts found, please set the exchange.options[\"accountId\"] to your preferred sub_account_id from this list: ".to_string())), &self.json(subAccountIds.clone()))));
}
let mut subAccountId: Value = self.safe_string(subAccountIds.clone(), Value::Int(0), &[]);
add_element_to_object(&mut self.options, &Value::Str("accountId".to_string()), subAccountId.clone());
}
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 {string} tag
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @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 tag = 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.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.clone());
m.insert("from_account_id".to_string(), defaultFromAccountId.clone());
m.insert("currency".to_string(), get_value(¤cy, &Value::Str("id".to_string())));
m.insert("num_tokens".to_string(), self.currency_to_precision(code.clone(), amount.clone(), &[]));
m.insert("signature".to_string(), self.default_signature());
m
});
let mut networkCodequeryVariable = self.handle_network_code_and_params(params.clone());
let mut networkCode: Value = get_value(&networkCodequeryVariable, &Value::Int(0));
let mut query: Value = get_value(&networkCodequeryVariable, &Value::Int(1));
let mut networkId: Value = self.network_code_to_id(networkCode.clone(), &[code.clone()]);
if is_equal(&networkId, &Value::Null) {
panic!("{}", crate::exchange_errors::bad_request(add(&self.id, &Value::Str(" withdraw() requires a network parameter".to_string()))));
}
add_element_to_object(get_value_mut(&mut request, &Value::Str("signature".to_string())), &Value::Str("chain_id".to_string()), networkId.clone());
request = self.create_signed_request(request.clone(), Value::Str("EIP712_WITHDRAWAL_TYPE".to_string()), &[currency.clone()]);
let __ws_arg_15 = self.extend(request.clone(), &[query.clone()]);
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.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_transaction(result.clone(), &[currency.clone()]);
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(), get_value(&market, &Value::Str("id".to_string())));
m.insert("size".to_string(), self.amount_to_precision(symbol.clone(), amount.clone()));
m
});
if !is_equal(&price, &Value::Null) {
add_element_to_object(&mut orderLeg, &Value::Str("limit_price".to_string()), self.price_to_precision(symbol.clone(), price.clone()));
} else {
add_element_to_object(&mut orderLeg, &Value::Str("limit_price".to_string()), Value::Null);
}
if is_equal(&side, &Value::Str("sell".to_string())) {
add_element_to_object(&mut orderLeg, &Value::Str("is_buying_asset".to_string()), Value::Bool(false));
} else if is_equal(&side, &Value::Str("buy".to_string())) {
add_element_to_object(&mut orderLeg, &Value::Str("is_buying_asset".to_string()), Value::Bool(true));
} else {
panic!("{}", crate::exchange_errors::invalid_order(add(&self.id, &Value::Str(" createOrder(): order side must be either \"buy\" or \"sell\"".to_string()))));
}
let mut clientOrderId: Value = self.safe_string_k(params.clone(), "clientOrderId", &[]);
if is_equal(&clientOrderId, &Value::Null) {
clientOrderId = add(&add(&to_string_val(&self.nonce()), &Value::Str("000".to_string())), &to_string_val(&self.request_id()));
}
params = self.omit(params.clone(), Value::List(vec![Value::Str("clientOrderId".to_string())]), &[]);
let mut isMarketOrder: Value = Value::Bool(is_equal(&type_var, &Value::Str("market".to_string())));
let mut subAccountId: Value = self.get_sub_account_id(params.clone());
let mut isReduceOnly: Value = self.safe_bool_k(params.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.clone());
m.insert("time_in_force".to_string(), Value::Null);
m.insert("legs".to_string(), Value::List(vec![orderLeg.clone()]));
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.clone());
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.clone());
m
});
let mut timeInForce: Value = self.safe_string_upper(params.clone(), Value::Str("timeInForce".to_string()), &[Value::Str("GOOD_TILL_TIME".to_string())]);
let mut postOnly: Value = self.is_post_only(isMarketOrder.clone(), Value::Null, &[params.clone()]);
if is_true(&postOnly) {
add_element_to_object(&mut orderRequest, &Value::Str("post_only".to_string()), Value::Bool(true));
}
if is_equal(&timeInForce, &Value::Null) {
timeInForce = Value::Str("GOOD_TILL_TIME".to_string());
} else {
let mut tifMap: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("GTC".to_string(), Value::Str("GOOD_TILL_TIME".to_string()));
m.insert("FOK".to_string(), Value::Str("FILL_OR_KILL".to_string()));
m.insert("IOC".to_string(), Value::Str("IMMEDIATE_OR_CANCEL".to_string()));
m
});
timeInForce = self.safe_string(tifMap.clone(), timeInForce.clone(), &[timeInForce.clone()]);
}
add_element_to_object(&mut orderRequest, &Value::Str("time_in_force".to_string()), timeInForce.clone());
if !is_true(&isMarketOrder) {
if is_true(&postOnly) {
timeInForce = Value::Str("POST_ONLY".to_string());
} else if is_equal(&timeInForce, &Value::Str("ioc".to_string())) {
timeInForce = Value::Str("IMMEDIATE_OR_CANCEL".to_string());
}
}
params = self.omit(params.clone(), Value::List(vec![Value::Str("reduceOnly".to_string()), Value::Str("postOnly".to_string()), Value::Str("timeInForce".to_string())]), &[]);
// Trigger & SL & TP
let mut triggerPrice: Value = Value::Null;
let mut stopLossPrice: Value = Value::Null;
let mut takeProfitPrice: Value = Value::Null;
{ let __destr_tmp = self.handle_trigger_prices_and_params(symbol.clone(), params.clone(), &[]); triggerPrice = get_value(&__destr_tmp, &Value::Int(0)); stopLossPrice = get_value(&__destr_tmp, &Value::Int(1)); takeProfitPrice = get_value(&__destr_tmp, &Value::Int(2)); params = get_value(&__destr_tmp, &Value::Int(3)); }
if !is_equal(&triggerPrice, &Value::Null) || !is_equal(&stopLossPrice, &Value::Null) || !is_equal(&takeProfitPrice, &Value::Null) {
// trigger price
let mut selectedPrice: Value = Value::Null;
if !is_equal(&triggerPrice, &Value::Null) {
selectedPrice = triggerPrice.clone();
} else if !is_equal(&stopLossPrice, &Value::Null) {
selectedPrice = stopLossPrice.clone();
} else if !is_equal(&takeProfitPrice, &Value::Null) {
selectedPrice = takeProfitPrice.clone();
}
// trigger type
let mut selectedType: Value = Value::Null;
let mut isBuy: bool = is_equal(&side, &Value::Str("buy".to_string()));
if !is_equal(&stopLossPrice, &Value::Null) {
selectedType = ternary(is_true(&isBuy), Value::Str("STOP_LOSS".to_string()), Value::Str("TAKE_PROFIT".to_string()));
} else if !is_equal(&takeProfitPrice, &Value::Null) {
selectedType = ternary(is_true(&isBuy), Value::Str("TAKE_PROFIT".to_string()), Value::Str("STOP_LOSS".to_string()));
} else {
let mut triggerDirection: Value = self.safe_string_k(params.clone(), "triggerDirection", &[]);
if is_equal(&triggerDirection, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" createOrder() requires a triggerDirection parameter when triggerPrice is specified, must be \"ascending\" or \"descending\"".to_string()))));
}
if !is_equal(&triggerDirection, &Value::Null) {
if is_equal(&triggerDirection, &Value::Str("ascending".to_string())) {
selectedType = ternary(is_true(&isBuy), Value::Str("STOP_LOSS".to_string()), Value::Str("TAKE_PROFIT".to_string()));
} else if is_equal(&triggerDirection, &Value::Str("descending".to_string())) {
selectedType = ternary(is_true(&isBuy), Value::Str("TAKE_PROFIT".to_string()), Value::Str("STOP_LOSS".to_string()));
}
}
}
// trigger by
let mut triggerPriceType: Value = self.safe_string_upper(params.clone(), Value::Str("triggerPriceType".to_string()), &[Value::Str("LAST".to_string())]);
add_element_to_object(get_value_mut(&mut orderRequest, &Value::Str("metadata".to_string())), &Value::Str("trigger".to_string()), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("trigger_type".to_string(), selectedType.clone());
m.insert("tpsl".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("trigger_by".to_string(), triggerPriceType.clone());
m.insert("trigger_price".to_string(), selectedPrice.clone());
m.insert("close_position".to_string(), self.safe_bool_k(params.clone(), "closePosition", &[Value::Bool(false)]));
m
}));
m
}));
params = self.omit(params.clone(), Value::List(vec![Value::Str("triggerDirection".to_string()), Value::Str("triggerPriceType".to_string()), Value::Str("closePosition".to_string())]), &[]);
}
let mut eipType: Value = Value::Str("EIP712_ORDER_TYPE".to_string());
let mut builderFee: Value = self.safe_bool_k(params.clone(), "builderFee", &[self.safe_bool(self.options.clone(), Value::Str("builderFee".to_string()), &[Value::Bool(true)])]);
if is_equal(&builderFee, &Value::Bool(true)) {
eipType = Value::Str("EIP712_ORDER_WITH_BUILDER_TYPE".to_string());
add_element_to_object(&mut orderRequest, &Value::Str("builder".to_string()), self.safe_string_k(self.options.clone(), "builder", &[]));
add_element_to_object(&mut orderRequest, &Value::Str("builder_fee".to_string()), self.safe_string_k(self.options.clone(), "builderRate", &[]));
}
params = self.omit(params.clone(), Value::List(vec![Value::Str("builderFee".to_string())]), &[]);
let mut signedOrderRequest: Value = self.create_signed_request(orderRequest.clone(), eipType.clone(), &[]);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("order".to_string(), signedOrderRequest.clone());
m
});
let __ws_arg_16 = self.extend(request.clone(), &[params.clone()]);
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.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_order(data.clone(), &[market.clone()]);
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 mut priceMultiplier: Value = Value::Str("1000000000".to_string());
let mut orderLegs: Value = self.safe_list_k(order.clone(), "legs", &[Value::List(vec![])]);
let mut legs: Value = Value::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_718: bool = true;
while { if !__for_first_718 { i = add(&i, &Value::Int(1)); } __for_first_718 = false; is_less_than(&i, &get_array_length(&orderLegs)) } {
let mut leg: Value = get_value(&orderLegs, &i);
let mut leg: Value = get_value(&orderLegs, &i);
let mut market: Value = self.market(get_value(&leg, &Value::Str("instrument".to_string())));
let mut bigInt10: Value = self.convert_to_big_int_custom(Value::Str("10".to_string()));
let mut precisionValue: Value = self.precision_from_string(self.safe_string(get_value(&market, &Value::Str("precision".to_string())), Value::Str("base".to_string()), &[]));
let mut precisionValueStr: Value = to_string_val(&precisionValue);
let mut sizeMultiplier: Value = crate::runtime::Math::pow(&bigInt10, &self.convert_to_big_int_custom(precisionValueStr.clone()));
let mut size: Value = get_value(&leg, &Value::Str("size".to_string()));
let mut sizeParts: Value = split(&size, &Value::Str(".".to_string()));
let mut sizeDec: Value = self.safe_string(sizeParts.clone(), Value::Int(1), &[Value::Str("".to_string())]);
let mut sizeDecLength: Value = add(&get_array_length(&sizeDec), &Value::Int(0)); // php tr
let mut sizeDecLengthStr: Value = to_string_val(&sizeDecLength);
let mut sizeInteger: Value = divide(&multiply(&self.convert_to_big_int_custom(replace_str(&size, &Value::Str(".".to_string()), &Value::Str("".to_string()))), &sizeMultiplier), &(crate::runtime::Math::pow(&bigInt10, &self.convert_to_big_int_custom(sizeDecLengthStr.clone()))));
let mut legOrder: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("assetID".to_string(), get_value(&get_value(&market, &Value::Str("info".to_string())), &Value::Str("instrument_hash".to_string())));
m.insert("contractSize".to_string(), self.parse_to_int(sizeInteger.clone()));
m.insert("isBuyingContract".to_string(), get_value(&leg, &Value::Str("is_buying_asset".to_string())));
m
});
let mut limitPrice: Value = self.safe_string_k(leg.clone(), "limit_price", &[]);
if !is_equal(&self.omit_zero(limitPrice.clone()), &Value::Null) {
let mut price: Value = get_value(&leg, &Value::Str("limit_price".to_string()));
let mut limitParts: Value = split(&price, &Value::Str(".".to_string()));
let mut limitDec: Value = self.safe_string(limitParts.clone(), Value::Int(1), &[Value::Str("".to_string())]);
let mut limitDecLength: Value = add(&get_array_length(&limitDec), &Value::Int(0)); // php tr
let mut limitDecLengthStr: Value = to_string_val(&limitDecLength);
let mut powerNum: Value = ternary(is_true(&(is_equal(&limitDecLengthStr, &Value::Str("0".to_string())))), Value::Int(0), self.convert_to_big_int_custom(limitDecLengthStr.clone()));
let mut priceInteger: Value = (divide(&multiply(&self.convert_to_big_int_custom(replace_str(&price, &Value::Str(".".to_string()), &Value::Str("".to_string()))), &self.convert_to_big_int_custom(priceMultiplier.clone())), &(crate::runtime::Math::pow(&bigInt10, &powerNum))));
add_element_to_object(&mut legOrder, &Value::Str("limitPrice".to_string()), self.parse_to_int(priceInteger.clone()));
} else {
add_element_to_object(&mut legOrder, &Value::Str("limitPrice".to_string()), Value::Int(0)); // should be zero to validate type-check
}
append_to_array(&mut legs, legOrder.clone());
}
}
let mut returnValue: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("subAccountID".to_string(), get_value(&order, &Value::Str("sub_account_id".to_string())));
m.insert("isMarket".to_string(), get_value(&order, &Value::Str("is_market".to_string())));
m.insert("timeInForce".to_string(), self.time_in_force_to_int(get_value(&order, &Value::Str("time_in_force".to_string()))));
m.insert("postOnly".to_string(), get_value(&order, &Value::Str("post_only".to_string())));
m.insert("reduceOnly".to_string(), get_value(&order, &Value::Str("reduce_only".to_string())));
m.insert("legs".to_string(), legs.clone());
m.insert("nonce".to_string(), get_value(&get_value(&order, &Value::Str("signature".to_string())), &Value::Str("nonce".to_string())));
m.insert("expiration".to_string(), get_value(&get_value(&order, &Value::Str("signature".to_string())), &Value::Str("expiration".to_string())));
m
});
if is_equal(&structureType, &Value::Str("EIP712_ORDER_WITH_BUILDER_TYPE".to_string())) && is_true(&self.safe_bool_k(self.options.clone(), "builderFee", &[Value::Bool(true)])) {
add_element_to_object(&mut returnValue, &Value::Str("builder".to_string()), get_value(&order, &Value::Str("builder".to_string())));
add_element_to_object(&mut returnValue, &Value::Str("builderFee".to_string()), self.parse_to_int(multiply(&self.convert_to_big_int_custom(self.fee_amount_multiplier()), &crate::runtime::parse_float(&get_value(&order, &Value::Str("builder_fee".to_string())))))); // 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 paginate: Value = Value::Bool(false);
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchMyTrades".to_string()), Value::Str("paginate".to_string()), &[]); paginate = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_true(&paginate) {
return self.fetch_paginated_call_dynamic(Value::Str("fetchMyTrades".to_string()), &[symbol.clone(), since.clone(), limit.clone(), params.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(params.clone()));
m
});
let mut market: Value = Value::Null;
if !is_equal(&symbol, &Value::Null) {
market = self.market(symbol.clone());
add_element_to_object(&mut request, &Value::Str("base".to_string()), Value::List(vec![]));
crate::runtime::append_to_object_array(&mut request, &Value::Str("base".to_string()), get_value(&market, &Value::Str("baseId".to_string())));
add_element_to_object(&mut request, &Value::Str("quote".to_string()), Value::List(vec![]));
crate::runtime::append_to_object_array(&mut request, &Value::Str("quote".to_string()), get_value(&market, &Value::Str("quoteId".to_string())));
}
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), crate::runtime::Math::min(&limit, &Value::Int(1000)));
}
{ let __destr_tmp = self.handle_until_option_string(Value::Str("end_time".to_string()), request.clone(), params.clone(), &[Value::Int(1000000)]); request = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if !is_equal(&since, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("start_time".to_string()), self.number_to_string(multiply(&since, &Value::Int(1000000))));
}
let __ws_arg_17 = self.extend(request.clone(), &[params.clone()]);
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.clone(), "result", &[Value::List(vec![])]);
return self.parse_trades(result.clone(), &[Value::Null, since.clone(), limit.clone()]);
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
});
if !is_equal(&symbols, &Value::Null) {
symbols = self.market_symbols(&[symbols.clone()]);
add_element_to_object(&mut request, &Value::Str("base".to_string()), Value::List(vec![]));
add_element_to_object(&mut request, &Value::Str("quote".to_string()), Value::List(vec![]));
{
let mut i: Value = Value::Int(0);
let mut __for_first_719: bool = true;
while { if !__for_first_719 { i = add(&i, &Value::Int(1)); } __for_first_719 = false; is_less_than(&i, &get_array_length(&symbols)) } {
let mut symbol: Value = get_value(&symbols, &i);
let mut symbol: Value = get_value(&symbols, &i);
let mut market: Value = self.market(symbol.clone());
if !is_equal(&get_value(&market, &Value::Str("contract".to_string())), &Value::Bool(true)) {
panic!("{}", crate::exchange_errors::bad_request(add(&self.id, &Value::Str(" fetchPositions() supports contract markets only".to_string()))));
}
crate::runtime::append_to_object_array(&mut request, &Value::Str("base".to_string()), get_value(&market, &Value::Str("baseId".to_string())));
crate::runtime::append_to_object_array(&mut request, &Value::Str("quote".to_string()), get_value(&market, &Value::Str("quoteId".to_string())));
}
}
}
let __ws_arg_18 = self.extend(request.clone(), &[params.clone()]);
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.clone(), "result", &[Value::List(vec![])]);
return self.parse_positions(result.clone(), &[symbols.clone()]);
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(position.clone(), Value::Str("event_time".to_string()), 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".to_string())));
let mut side: Value = ternary(is_true(&isLong), Value::Str("long".to_string()), Value::Str("short".to_string()));
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.clone(), &[market.clone()]));
m.insert("notional".to_string(), self.parse_number(crate::precise::Precise::stringAbs(&self.safe_string_k(position.clone(), "notional", &[])), &[]));
m.insert("marginMode".to_string(), Value::Null);
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.clone());
m.insert("hedged".to_string(), Value::Null);
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("lastUpdateTimestamp".to_string(), self.safe_integer_k(position.clone(), "lastUpdateTime", &[]));
m.insert("maintenanceMargin".to_string(), self.safe_number_k(position.clone(), "maintenanceMargin", &[]));
m.insert("maintenanceMarginPercentage".to_string(), Value::Null);
m.insert("collateral".to_string(), Value::Null);
m.insert("initialMargin".to_string(), self.safe_number_k(position.clone(), "initialMargin", &[]));
m.insert("initialMarginPercentage".to_string(), Value::Null);
m.insert("leverage".to_string(), self.safe_number_k(position.clone(), "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.clone(), &[params.clone()]);
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.clone(), "results", &[Value::List(vec![])]);
return self.parse_leverages(results.clone(), &[symbols.clone()]);
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 is_equal(&symbol, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" setLeverage() requires a symbol argument".to_string()))));
}
self.load_markets_and_sign_in().await;
let mut market: Value = self.market(symbol.clone());
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(), get_value(&market, &Value::Str("id".to_string())));
m.insert("leverage".to_string(), self.number_to_string(leverage.clone()));
m
});
let __ws_arg_20 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_trading_post_full_v1_set_initial_leverage(&[__ws_arg_20]).await;
return self.parse_leverage(response.clone(), &[market.clone()]);
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(leverage.clone(), Value::Str("margin_type".to_string()), &[]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), leverage.clone());
m.insert("symbol".to_string(), self.safe_symbol(marketId.clone(), &[market.clone()]));
m.insert("marginMode".to_string(), marginType.clone());
m.insert("longLeverage".to_string(), leverageValue.clone());
m.insert("shortLeverage".to_string(), leverageValue.clone());
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.clone(), &[params.clone()]);
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.clone(), "results", &[Value::List(vec![])]);
return self.parse_leverages(results.clone(), &[symbols.clone()]);
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.clone(), &[market.clone()]));
m.insert("marginMode".to_string(), self.safe_string_lower(marginMode.clone(), Value::Str("margin_type".to_string()), &[]));
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 paginate: Value = Value::Bool(false);
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchFundingHistory".to_string()), Value::Str("paginate".to_string()), &[]); paginate = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_true(&paginate) {
return self.fetch_paginated_call_dynamic(Value::Str("fetchFundingHistory".to_string()), &[symbol.clone(), since.clone(), limit.clone(), params.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(params.clone()));
m
});
let mut market: Value = Value::Null;
if !is_equal(&symbol, &Value::Null) {
market = self.market(symbol.clone());
add_element_to_object(&mut request, &Value::Str("base".to_string()), Value::List(vec![]));
crate::runtime::append_to_object_array(&mut request, &Value::Str("base".to_string()), get_value(&market, &Value::Str("baseId".to_string())));
add_element_to_object(&mut request, &Value::Str("quote".to_string()), Value::List(vec![]));
crate::runtime::append_to_object_array(&mut request, &Value::Str("quote".to_string()), get_value(&market, &Value::Str("quoteId".to_string())));
}
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), crate::runtime::Math::min(&limit, &Value::Int(1000)));
}
{ let __destr_tmp = self.handle_until_option_string(Value::Str("end_time".to_string()), request.clone(), params.clone(), &[Value::Int(1000000)]); request = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if !is_equal(&since, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("start_time".to_string()), self.number_to_string(multiply(&since, &Value::Int(1000000))));
}
let __ws_arg_22 = self.extend(request.clone(), &[params.clone()]);
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.clone(), "result", &[Value::List(vec![])]);
return self.parse_incomes(result.clone(), &[market.clone(), since.clone(), limit.clone()]);
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(income.clone(), Value::Str("event_time".to_string()), 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.clone(), &[market.clone()]));
m.insert("code".to_string(), self.safe_currency_code(currencyId.clone(), &[]));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("id".to_string(), self.safe_string_k(income.clone(), "tx_id", &[]));
m.insert("amount".to_string(), self.safe_number_k(income.clone(), "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.clone());
m
});
let mut market: Value = Value::Null;
if !is_equal(&symbol, &Value::Null) {
market = self.market(symbol.clone());
add_element_to_object(&mut request, &Value::Str("base".to_string()), Value::List(vec![]));
crate::runtime::append_to_object_array(&mut request, &Value::Str("base".to_string()), get_value(&market, &Value::Str("baseId".to_string())));
add_element_to_object(&mut request, &Value::Str("quote".to_string()), Value::List(vec![]));
crate::runtime::append_to_object_array(&mut request, &Value::Str("quote".to_string()), get_value(&market, &Value::Str("quoteId".to_string())));
}
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), crate::runtime::Math::min(&limit, &Value::Int(1000)));
}
{ let __destr_tmp = self.handle_until_option_string(Value::Str("end_time".to_string()), request.clone(), params.clone(), &[Value::Int(1000000)]); request = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if !is_equal(&since, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("start_time".to_string()), self.number_to_string(multiply(&since, &Value::Int(1000000))));
}
let __ws_arg_23 = self.extend(request.clone(), &[params.clone()]);
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.clone(), "result", &[Value::List(vec![])]);
return self.parse_orders(result.clone(), &[market.clone(), since.clone(), limit.clone()]);
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.clone(), &[params.clone()]);
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.clone(), "result", &[Value::List(vec![])]);
return self.parse_orders(result.clone(), &[Value::Null, since.clone(), limit.clone()]);
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.clone());
m
});
let mut clientOrderId: Value = self.safe_string2(params.clone(), Value::Str("clientOrderId".to_string()), Value::Str("client_order_id".to_string()), &[]);
if !is_equal(&clientOrderId, &Value::Null) {
params = self.omit(params.clone(), Value::Str("clientOrderId".to_string()), &[Value::Str("client_order_id".to_string())]);
add_element_to_object(&mut request, &Value::Str("client_order_id".to_string()), clientOrderId.clone());
} else {
add_element_to_object(&mut request, &Value::Str("order_id".to_string()), id.clone());
}
let __ws_arg_25 = self.extend(request.clone(), &[params.clone()]);
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.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_order(result.clone(), &[]);
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 is_true(&Value::Bool(in_op(&order, &Value::Str("ack".to_string())))) {
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 = ternary(is_true(&(is_equal(&isMarket, &Value::Bool(true)))), Value::Str("market".to_string()), Value::Str("limit".to_string()));
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 = ternary(is_true(&(is_equal(&isPostOnly, &Value::Bool(true)))), Value::Str("PO".to_string()), self.parse_time_in_force(timeInForceRaw.clone()));
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::List(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::List(vec![])]);
let mut avgPrices: Value = self.safe_list_k(stateObj.clone(), "avg_fill_price", &[Value::List(vec![])]);
let mut primaryOrderIndex: Value = Value::Int(0);
let mut firstLeg: Value = self.safe_dict(legs.clone(), primaryOrderIndex.clone(), &[]);
if !is_equal(&firstLeg, &Value::Null) {
let mut marketId: Value = self.safe_string_k(firstLeg.clone(), "instrument", &[]);
market = self.safe_market(&[marketId.clone(), market.clone()]);
size = self.safe_string_k(firstLeg.clone(), "size", &[]);
let mut isBuyingAsset: bool = is_equal(&self.safe_bool_k(firstLeg.clone(), "is_buying_asset", &[]), &Value::Bool(true));
side = ternary(is_true(&isBuyingAsset), Value::Str("buy".to_string()), Value::Str("sell".to_string()));
price = self.safe_string_k(firstLeg.clone(), "limit_price", &[]);
filled = self.safe_string(filledAmounts.clone(), primaryOrderIndex.clone(), &[]);
avgPrice = self.safe_string(avgPrices.clone(), primaryOrderIndex.clone(), &[]);
}
let mut timestamp: Value = self.safe_integer_product(metadata.clone(), Value::Str("create_time".to_string()), Value::Float(0.000001), &[]);
// const triggerDetails = this.safeDict (metadata, 'trigger', {});
let mut legsLength: Value = get_array_length(&legs);
return self.safe_order(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("isMultiLeg".to_string(), Value::Bool((is_greater_than(&legsLength, &Value::Int(1)))));
m.insert("id".to_string(), self.safe_string_k(order.clone(), "order_id", &[]));
m.insert("clientOrderId".to_string(), self.safe_string_k(metadata.clone(), "client_order_id", &[]));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("lastTradeTimeStamp".to_string(), Value::Null);
m.insert("lastUpdateTimestamp".to_string(), self.safe_integer_product(stateObj.clone(), Value::Str("update_time".to_string()), Value::Float(0.000001), &[]));
m.insert("status".to_string(), self.parse_order_status(self.safe_string_k(stateObj.clone(), "status", &[])));
m.insert("symbol".to_string(), self.safe_string_k(market.clone(), "symbol", &[]));
m.insert("type".to_string(), orderType.clone());
m.insert("timeInForce".to_string(), timeInForce.clone());
m.insert("postOnly".to_string(), isPostOnly.clone());
m.insert("side".to_string(), side.clone());
m.insert("price".to_string(), price.clone());
m.insert("triggerPrice".to_string(), Value::Null);
m.insert("cost".to_string(), Value::Null);
m.insert("average".to_string(), avgPrice.clone());
m.insert("amount".to_string(), size.clone());
m.insert("filled".to_string(), filled.clone());
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.clone());
m.insert("info".to_string(), order.clone());
m
}), &[market.clone()]);
Value::Null
}
pub fn parse_time_in_force(&self, mut type_var: Value) -> Value {
let mut types: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("GOOD_TILL_TIME".to_string(), Value::Str("GTC".to_string()));
m.insert("IMMEDIATE_OR_CANCEL".to_string(), Value::Str("IOC".to_string()));
m.insert("FILL_OR_KILL".to_string(), Value::Str("FOK".to_string()));
m.insert("ALL_OR_NONE".to_string(), Value::Str("ALL_OR_NONE".to_string()));
m.insert("RETAIL_PRICE_IMPROVEMENT".to_string(), Value::Str("RETAIL_PRICE_IMPROVEMENT".to_string()));
m
});
return self.safe_string_upper(types.clone(), type_var.clone(), &[type_var.clone()]);
Value::Null
}
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.clone(), timeInForce.clone(), &[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".to_string()));
m.insert("OPEN".to_string(), Value::Str("open".to_string()));
m.insert("FILLED".to_string(), Value::Str("closed".to_string()));
m.insert("REJECTED".to_string(), Value::Str("rejected".to_string()));
m.insert("CANCELLED".to_string(), Value::Str("canceled".to_string()));
m
});
return self.safe_string(statuses.clone(), 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 !is_equal(&symbol, &Value::Null) {
let mut market: Value = self.market(symbol.clone());
add_element_to_object(&mut request, &Value::Str("base".to_string()), Value::List(vec![]));
crate::runtime::append_to_object_array(&mut request, &Value::Str("base".to_string()), get_value(&market, &Value::Str("baseId".to_string())));
add_element_to_object(&mut request, &Value::Str("quote".to_string()), Value::List(vec![]));
crate::runtime::append_to_object_array(&mut request, &Value::Str("quote".to_string()), get_value(&market, &Value::Str("quoteId".to_string())));
}
let __ws_arg_26 = self.extend(request.clone(), &[params.clone()]);
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.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_orders(Value::List(vec![result.clone()]), &[]);
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.clone());
m
});
let mut clientOrderId: Value = self.safe_string2(params.clone(), Value::Str("clientOrderId".to_string()), Value::Str("client_order_id".to_string()), &[]);
if !is_equal(&clientOrderId, &Value::Null) {
params = self.omit(params.clone(), Value::Str("clientOrderId".to_string()), &[]);
add_element_to_object(&mut request, &Value::Str("client_order_id".to_string()), clientOrderId.clone());
} else {
add_element_to_object(&mut request, &Value::Str("order_id".to_string()), id.clone());
}
let __ws_arg_27 = self.extend(request.clone(), &[params.clone()]);
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.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_order(result.clone(), &[]);
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".to_string()));
m.insert("version".to_string(), Value::Str("0".to_string()));
m.insert("chainId".to_string(), ternary(is_true(&self.isSandboxModeEnabled), Value::Int(326), Value::Int(325)));
m
});
Value::Null
}
pub fn fee_amount_multiplier(&self) -> Value {
return self.convert_to_big_int_custom(Value::Str("10000".to_string()));
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 is_equal(&structureType, &Value::Str("EIP712_TRANSFER_TYPE".to_string())) {
let mut amountMultiplier: Value = self.convert_to_big_int_custom(Value::Str("1000000".to_string()));
let mut amountInt: Value = multiply(&get_value(&request, &Value::Str("num_tokens".to_string())), &amountMultiplier);
if is_equal(¤cyObj, &Value::Null) {
panic!("{}", crate::exchange_errors::exchange_error(add(&self.id, &Value::Str(" createSignedRequest() missing currencyObj".to_string()))));
}
messageData = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("fromAccount".to_string(), get_value(&request, &Value::Str("from_account_id".to_string())));
m.insert("fromSubAccount".to_string(), get_value(&request, &Value::Str("from_sub_account_id".to_string())));
m.insert("toAccount".to_string(), get_value(&request, &Value::Str("to_account_id".to_string())));
m.insert("toSubAccount".to_string(), get_value(&request, &Value::Str("to_sub_account_id".to_string())));
m.insert("tokenCurrency".to_string(), get_value(¤cyObj, &Value::Str("numericId".to_string())));
m.insert("numTokens".to_string(), self.parse_to_int(amountInt.clone()));
m.insert("nonce".to_string(), get_value(&get_value(&request, &Value::Str("signature".to_string())), &Value::Str("nonce".to_string())));
m.insert("expiration".to_string(), get_value(&get_value(&request, &Value::Str("signature".to_string())), &Value::Str("expiration".to_string())));
m
});
} else if is_equal(&structureType, &Value::Str("EIP712_WITHDRAWAL_TYPE".to_string())) {
let mut amountMultiplier: Value = self.convert_to_big_int_custom(Value::Str("1000000".to_string()));
if is_equal(¤cyObj, &Value::Null) {
panic!("{}", crate::exchange_errors::exchange_error(add(&self.id, &Value::Str(" createSignedRequest() missing currencyObj".to_string()))));
}
messageData = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("fromAccount".to_string(), get_value(&request, &Value::Str("from_account_id".to_string())));
m.insert("toEthAddress".to_string(), get_value(&request, &Value::Str("to_eth_address".to_string())));
m.insert("tokenCurrency".to_string(), get_value(¤cyObj, &Value::Str("numericId".to_string())));
m.insert("numTokens".to_string(), self.parse_to_int(multiply(&get_value(&request, &Value::Str("num_tokens".to_string())), &amountMultiplier)));
m.insert("nonce".to_string(), get_value(&get_value(&request, &Value::Str("signature".to_string())), &Value::Str("nonce".to_string())));
m.insert("expiration".to_string(), get_value(&get_value(&request, &Value::Str("signature".to_string())), &Value::Str("expiration".to_string())));
m
});
} else if is_equal(&structureType, &Value::Str("EIP712_ORDER_TYPE".to_string())) || is_equal(&structureType, &Value::Str("EIP712_ORDER_WITH_BUILDER_TYPE".to_string())) {
messageData = self.eip_message_for_order(request.clone(), structureType.clone());
} else if is_equal(&structureType, &Value::Str("EIP712_BUILDER_APPROVAL_TYPE".to_string())) {
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(), get_value(&request, &Value::Str("main_account_id".to_string())));
m.insert("builderAccountID".to_string(), get_value(&request, &Value::Str("builder_account_id".to_string())));
m.insert("maxFutureFeeRate".to_string(), self.parse_to_int(multiply(&crate::runtime::parse_float(&get_value(&request, &Value::Str("max_futures_fee_rate".to_string()))), &amountMultiplier)));
m.insert("maxSpotFeeRate".to_string(), self.parse_to_int(multiply(&crate::runtime::parse_float(&get_value(&request, &Value::Str("max_spot_fee_rate".to_string()))), &amountMultiplier)));
m.insert("nonce".to_string(), get_value(&get_value(&request, &Value::Str("signature".to_string())), &Value::Str("nonce".to_string())));
m.insert("expiration".to_string(), get_value(&get_value(&request, &Value::Str("signature".to_string())), &Value::Str("expiration".to_string())));
m
});
} else if is_equal(&structureType, &Value::Str("EIP712_WALLETLOGIN_TYPE".to_string())) {
messageData = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("signer".to_string(), get_value(&request, &Value::Str("address".to_string())));
m.insert("nonce".to_string(), get_value(&get_value(&request, &Value::Str("signature".to_string())), &Value::Str("nonce".to_string())));
m.insert("expiration".to_string(), get_value(&get_value(&request, &Value::Str("signature".to_string())), &Value::Str("expiration".to_string())));
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.clone(), get_value(&definitions, &structureType), messageData.clone());
let mut ethEncodedMessageHashed: Value = add(&Value::Str("0x".to_string()), &self.hash(ethEncodedMessage.clone(), Value::Str("keccak".to_string()), &[Value::Str("hex".to_string())]));
let mut usesPrivKey: Value = self.uses_private_key(); // py transpiler needs this line separated
let mut secretOrPrivkey: Value = ternary(is_true(&usesPrivKey), self.privateKey.clone(), self.secret.clone());
let mut privateKeyWithoutZero: Value = self.remove0x_prefix(secretOrPrivkey.clone());
let mut signature: Value = ecdsa(self.remove0x_prefix(ethEncodedMessageHashed.clone()), privateKeyWithoutZero.clone(), Value::Str("secp256k1".to_string()), Value::Null);
add_element_to_object(get_value_mut(&mut request, &Value::Str("signature".to_string())), &Value::Str("r".to_string()), self.format_signature_rs(get_value(&signature, &Value::Str("r".to_string()))));
add_element_to_object(get_value_mut(&mut request, &Value::Str("signature".to_string())), &Value::Str("s".to_string()), self.format_signature_rs(get_value(&signature, &Value::Str("s".to_string()))));
add_element_to_object(get_value_mut(&mut request, &Value::Str("signature".to_string())), &Value::Str("v".to_string()), self.sum(&[Value::Int(27), get_value(&signature, &Value::Str("v".to_string()))]));
add_element_to_object(get_value_mut(&mut request, &Value::Str("signature".to_string())), &Value::Str("signer".to_string()), ternary(is_true(&(is_equal(&signerAddress, &Value::Null))), self.eth_get_address_from_private_key(add(&Value::Str("0x".to_string()), &privateKeyWithoutZero), &[]), signerAddress.clone()));
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".to_string()));
if is_true(&Value::Bool(starts_with(&padded, &Value::Str("0x".to_string())))) {
return padded;
} else {
return add(&Value::Str("0x".to_string()), &padded);
}
Value::Null
}
pub fn default_signature(&self) -> Value {
let mut expiration: Value = add(&multiply(&self.milliseconds(), &Value::Int(1000000)), &multiply(&multiply(&Value::Int(1000000), &self.safe_integer_k(self.options.clone(), "expirationSeconds", &[Value::Int(30)])), &Value::Int(1000)));
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("signer".to_string(), Value::Str("".to_string()));
m.insert("r".to_string(), Value::Str("".to_string()));
m.insert("s".to_string(), Value::Str("".to_string()));
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(), ternary(is_true(&self.isSandboxModeEnabled), Value::Str("326".to_string()), Value::Str("325".to_string())));
m
});
Value::Null
}
pub fn handle_until_option_string(&self, mut key: Value, mut request: Value, mut params: Value, optional_args: &[Value]) -> Value {
let mut multiplier = get_arg(optional_args, 0, Value::Int(1));
let mut until: Value = self.safe_integer2(params.clone(), Value::Str("until".to_string()), Value::Str("till".to_string()), &[]);
if !is_equal(&until, &Value::Null) {
add_element_to_object(&mut request, &key, self.number_to_string(self.parse_to_int(multiply(&until, &multiplier))));
params = self.omit(params.clone(), Value::List(vec![Value::Str("until".to_string()), Value::Str("till".to_string())]), &[]);
}
return Value::List(vec![request.clone(), params.clone()]);
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)]);
add_element_to_object(&mut self.options.clone(), &Value::Str("requestId".to_string()), 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::Str("public".to_string()));
let mut method = get_arg(optional_args, 1, Value::Str("GET".to_string()));
let mut params = get_arg(optional_args, 2, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut headers = get_arg(optional_args, 3, Value::Null);
let mut body = get_arg(optional_args, 4, Value::Null);
let mut query: Value = self.omit(params.clone(), self.extract_params(path.clone()), &[]);
let mut url: Value = add(&get_value(&get_value(&self.urls, &Value::Str("api".to_string())), &api), &path);
let mut queryString: Value = Value::Str("".to_string());
if is_equal(&method, &Value::Str("GET".to_string())) {
if is_greater_than(&get_array_length(&object_keys(&query)), &Value::Int(0)) {
queryString = self.urlencode(query.clone(), &[]);
url = add(&url, &add(&Value::Str("?".to_string()), &queryString));
}
} else if is_equal(&method, &Value::Str("POST".to_string())) {
// 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
headers = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("Content-Type".to_string(), Value::Str("application/json".to_string()));
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: Value = get_array_length(¶msKeys);
if is_equal(¶msKeysLength, &Value::Int(0)) {
body = Value::Str("{}".to_string());
} else {
body = self.json(params.clone());
}
}
let mut isPrivate: Value = Value::Bool(starts_with(&api, &Value::Str("private".to_string())));
if is_equal(&isPrivate, &Value::Bool(true)) {
self.check_required_credentials(&[]);
if !is_equal(&queryString, &Value::Str("".to_string())) {
path = add(&add(&path, &Value::Str("?".to_string())), &queryString);
}
headers = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("Content-Type".to_string(), Value::Str("application/json".to_string()));
m
});
if is_true(&(is_equal(&Value::Bool(ends_with(&path, &Value::Str("auth/api_key/login".to_string()))), &Value::Bool(true)))) || is_true(&(is_equal(&Value::Bool(ends_with(&path, &Value::Str("auth/wallet/login".to_string()))), &Value::Bool(true)))) {
add_element_to_object(&mut headers, &Value::Str("Cookie".to_string()), Value::Str("rm=true;".to_string()));
} 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 is_equal(&cookieValue, &Value::Null) || is_equal(&accountId, &Value::Null) {
panic!("{}", crate::exchange_errors::authentication_error(add(&self.id, &Value::Str(" : at first, you need to authenticate with exchange using signIn() method.".to_string()))));
}
add_element_to_object(&mut headers, &Value::Str("Cookie".to_string()), cookieValue.clone());
add_element_to_object(&mut headers, &Value::Str("X-Grvt-Account-Id".to_string()), accountId.clone());
}
}
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("url".to_string(), url.clone());
m.insert("method".to_string(), method.clone());
m.insert("body".to_string(), body.clone());
m.insert("headers".to_string(), headers.clone());
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 is_true(&Value::Bool(ends_with(&url, &Value::Str("auth/api_key/login".to_string())))) || is_true(&Value::Bool(ends_with(&url, &Value::Str("auth/wallet/login".to_string())))) {
let mut accountId: Value = self.safe_string2(headers.clone(), Value::Str("X-Grvt-Account-Id".to_string()), Value::Str("x-grvt-account-id".to_string()), &[]);
add_element_to_object(&mut self.options.clone(), &Value::Str("AuthAccountId".to_string()), accountId.clone());
let mut cookie: Value = self.safe_string2(headers.clone(), Value::Str("Set-Cookie".to_string()), Value::Str("set-cookie".to_string()), &[]);
if !is_equal(&cookie, &Value::Null) {
let mut cookieValue: Value = get_value(&split(&cookie, &Value::Str(";".to_string())), &Value::Int(0));
add_element_to_object(&mut self.options.clone(), &Value::Str("AuthCookieValue".to_string()), cookieValue.clone());
}
if is_equal(&get_value(&self.options, &Value::Str("AuthCookieValue".to_string())), &Value::Null) || is_equal(&get_value(&self.options, &Value::Str("AuthAccountId".to_string())), &Value::Null) {
panic!("{}", crate::exchange_errors::authentication_error(add(&self.id, &Value::Str(" signIn() failed to receive auth-cookie or account-id".to_string()))));
}
} else {
let mut errorCode: Value = self.safe_string_k(response.clone(), "code", &[]);
if !is_equal(&errorCode, &Value::Null) {
let mut feedback: Value = add(&add(&self.id, &Value::Str(" ".to_string())), &body);
self.throw_exactly_matched_exception(get_value(&self.exceptions, &Value::Str("exact".to_string())), errorCode.clone(), feedback.clone());
panic!("{}", crate::exchange_errors::exchange_error(feedback));
} else {
let mut message: Value = self.safe_string_k(response.clone(), "message", &[]);
if !is_equal(&message, &Value::Null) {
let mut feedback: Value = add(&add(&self.id, &Value::Str(" ".to_string())), &body);
self.throw_broadly_matched_exception(get_value(&self.exceptions, &Value::Str("broad".to_string())), message.clone(), feedback.clone());
panic!("{}", crate::exchange_errors::exchange_error(feedback));
} else {
let mut status: Value = self.safe_string_k(response.clone(), "status", &[]);
if !is_equal(&status, &Value::Null) && !is_equal(&status, &Value::Str("success".to_string())) {
let mut feedback: Value = add(&add(&self.id, &Value::Str(" ".to_string())), &body);
panic!("{}", crate::exchange_errors::exchange_error(feedback));
}
}
}
}
return Value::Null;
Value::Null
}
}