// 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 LighterCore {
pub exchange: crate::exchange::Exchange,
}
impl LighterCore {
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 = LighterCore::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 LighterCore {
fn parse_ticker(&self, ticker: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on LighterCore.
LighterCore::parse_ticker(self, ticker, &[market.clone()])
}
fn parse_trade(&self, trade: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on LighterCore.
LighterCore::parse_trade(self, trade, &[market.clone()])
}
fn parse_order(&self, order: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on LighterCore.
LighterCore::parse_order(self, order, &[market.clone()])
}
fn parse_ohlcv(&self, ohlcv: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on LighterCore.
LighterCore::parse_ohlcv(self, ohlcv, &[market.clone()])
}
fn parse_position(&self, position: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on LighterCore.
LighterCore::parse_position(self, position, &[market.clone()])
}
fn parse_funding_rate(&self, rate: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on LighterCore.
LighterCore::parse_funding_rate(self, rate, &[market.clone()])
}
fn parse_transfer(&self, transfer: crate::Value, currency: crate::Value) -> crate::Value {
// Forward to the inherent method on LighterCore.
LighterCore::parse_transfer(self, transfer, &[currency.clone()])
}
fn parse_currency(&self, currency: crate::Value) -> crate::Value {
// Forward to the inherent method on LighterCore.
LighterCore::parse_currency(self, currency)
}
fn parse_margin_modification(&self, data: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on LighterCore.
LighterCore::parse_margin_modification(self, data, &[market.clone()])
}
fn parse_account(&self, account: crate::Value) -> crate::Value {
// Forward to the inherent method on LighterCore.
LighterCore::parse_account(self, account)
}
fn parse_transaction(&self, transaction: crate::Value, currency: crate::Value) -> crate::Value {
// Forward to the inherent method on LighterCore.
LighterCore::parse_transaction(self, transaction, &[currency.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 LighterCore.
LighterCore::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 LighterCore.
LighterCore::handle_errors(self, code, reason, url, method, headers, body, response, request_headers, request_body)
}
}
impl crate::exchange_generated::ExchangeBase for LighterCore {
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 {
"add_margin" => self.add_margin(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), &args.get(2..).unwrap_or(&[]).to_vec()[..]).await,
"approve_builder_fee" => self.approve_builder_fee(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..).unwrap_or(&[]).to_vec()[..]).await,
"cancel_all_orders" => self.cancel_all_orders(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"cancel_all_orders_after" => self.cancel_all_orders_after(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).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,
"change_api_key" => self.change_api_key(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"create_auth" => self.create_auth(&args.get(0..).unwrap_or(&[]).to_vec()[..]),
"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_order_request" => self.create_order_request(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()[..]),
"create_sub_account" => self.create_sub_account(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"edit_order" => self.edit_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,
"fetch_accounts" => self.fetch_accounts(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_balance" => self.fetch_balance(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_closed_orders" => self.fetch_closed_orders(&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_rates" => self.fetch_funding_rates(&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_nonce" => self.fetch_nonce(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), &args.get(2..).unwrap_or(&[]).to_vec()[..]).await,
"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_book" => self.fetch_order_book(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_position" => self.fetch_position(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_positions" => self.fetch_positions(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_status" => self.fetch_status(&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_tickers" => self.fetch_tickers(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_time" => self.fetch_time(&args.get(0..).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,
"get_lighter_private_key" => self.get_lighter_private_key(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)),
"handle_account_index" => self.handle_account_index(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,
"handle_api_key_index" => self.handle_api_key_index(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()[..]),
"handle_builder_fee_approval" => self.handle_builder_fee_approval(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)).await,
"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)),
"hash_message" => self.hash_message(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"load_account" => self.load_account(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,
"modify_leverage_and_margin_mode" => self.modify_leverage_and_margin_mode(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), &args.get(2..).unwrap_or(&[]).to_vec()[..]).await,
"parse_account" => self.parse_account(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" => self.parse_funding_rate(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_margin_modification" => self.parse_margin_modification(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"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_order_time_in_force" => self.parse_order_time_in_force(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_order_time_in_force_integer" => self.parse_order_time_in_force_integer(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_order_type" => self.parse_order_type(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_order_type_integer" => self.parse_order_type_integer(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_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_transaction_status" => self.parse_transaction_status(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_transfer" => self.parse_transfer(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"pow" => self.pow(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)),
"pre_load_lighter_library" => self.pre_load_lighter_library(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"reduce_margin" => self.reduce_margin(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), &args.get(2..).unwrap_or(&[]).to_vec()[..]).await,
"set_leverage" => self.set_leverage(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"set_margin" => self.set_margin(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), &args.get(2..).unwrap_or(&[]).to_vec()[..]).await,
"set_margin_mode" => self.set_margin_mode(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_and_cancel_all_orders" => self.sign_and_cancel_all_orders(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"sign_and_cancel_order" => self.sign_and_cancel_order(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), &args.get(2..).unwrap_or(&[]).to_vec()[..]).await,
"sign_and_create_order" => self.sign_and_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).cloned().unwrap_or(crate::Value::Null), &args.get(5..).unwrap_or(&[]).to_vec()[..]).await,
"sign_hash" => self.sign_hash(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)),
"sign_l1_and_prepare_tx_info" => self.sign_l1_and_prepare_tx_info(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)),
"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,
"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 LighterCore {
type Target = crate::exchange::Exchange;
fn deref(&self) -> &crate::exchange::Exchange { &self.exchange }
}
impl std::ops::DerefMut for LighterCore {
fn deref_mut(&mut self) -> &mut crate::exchange::Exchange { &mut self.exchange }
}
impl LighterCore {
pub fn describe(&self) -> Value {
return self.deep_extend(self.super_describe(), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), Value::Str("lighter".to_string()));
m.insert("name".to_string(), Value::Str("Lighter".to_string()));
m.insert("countries".to_string(), Value::List(vec![]));
m.insert("version".to_string(), Value::Str("v1".to_string()));
m.insert("rateLimit".to_string(), Value::Int(1000));
m.insert("certified".to_string(), Value::Bool(false));
m.insert("pro".to_string(), Value::Bool(true));
m.insert("dex".to_string(), Value::Bool(true));
m.insert("quoteJsonNumbers".to_string(), Value::Bool(false));
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(true));
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("addMargin".to_string(), Value::Bool(true));
m.insert("borrowCrossMargin".to_string(), Value::Bool(false));
m.insert("borrowIsolatedMargin".to_string(), Value::Bool(false));
m.insert("borrowMargin".to_string(), Value::Bool(false));
m.insert("cancelAllOrders".to_string(), Value::Bool(true));
m.insert("cancelAllOrdersAfter".to_string(), Value::Bool(true));
m.insert("cancelOrder".to_string(), Value::Bool(true));
m.insert("cancelOrders".to_string(), Value::Bool(false));
m.insert("cancelOrdersForSymbols".to_string(), Value::Bool(false));
m.insert("closeAllPositions".to_string(), Value::Bool(false));
m.insert("closePosition".to_string(), Value::Bool(false));
m.insert("createMarketBuyOrderWithCost".to_string(), Value::Bool(false));
m.insert("createMarketOrderWithCost".to_string(), Value::Bool(false));
m.insert("createMarketSellOrderWithCost".to_string(), Value::Bool(false));
m.insert("createOrder".to_string(), Value::Bool(true));
m.insert("createOrders".to_string(), Value::Bool(false));
m.insert("createPostOnlyOrder".to_string(), Value::Bool(false));
m.insert("createReduceOnlyOrder".to_string(), Value::Bool(false));
m.insert("createStopOrder".to_string(), Value::Bool(false));
m.insert("createTriggerOrder".to_string(), Value::Bool(false));
m.insert("editOrder".to_string(), Value::Bool(true));
m.insert("fetchAccounts".to_string(), Value::Bool(true));
m.insert("fetchAllGreeks".to_string(), Value::Bool(false));
m.insert("fetchBalance".to_string(), Value::Bool(true));
m.insert("fetchBorrowInterest".to_string(), Value::Bool(false));
m.insert("fetchBorrowRate".to_string(), Value::Bool(false));
m.insert("fetchBorrowRateHistories".to_string(), Value::Bool(false));
m.insert("fetchBorrowRateHistory".to_string(), Value::Bool(false));
m.insert("fetchBorrowRates".to_string(), Value::Bool(false));
m.insert("fetchBorrowRatesPerSymbol".to_string(), Value::Bool(false));
m.insert("fetchCanceledAndClosedOrders".to_string(), Value::Bool(false));
m.insert("fetchCanceledOrders".to_string(), Value::Bool(false));
m.insert("fetchClosedOrders".to_string(), Value::Bool(true));
m.insert("fetchCrossBorrowRate".to_string(), Value::Bool(false));
m.insert("fetchCrossBorrowRates".to_string(), Value::Bool(false));
m.insert("fetchCurrencies".to_string(), Value::Bool(true));
m.insert("fetchDepositAddress".to_string(), Value::Bool(false));
m.insert("fetchDepositAddresses".to_string(), Value::Bool(false));
m.insert("fetchDeposits".to_string(), Value::Bool(true));
m.insert("fetchDepositWithdrawFee".to_string(), Value::Bool(false));
m.insert("fetchDepositWithdrawFees".to_string(), Value::Bool(false));
m.insert("fetchFundingHistory".to_string(), Value::Bool(false));
m.insert("fetchFundingRate".to_string(), Value::Bool(false));
m.insert("fetchFundingRateHistory".to_string(), Value::Bool(false));
m.insert("fetchFundingRates".to_string(), Value::Bool(true));
m.insert("fetchGreeks".to_string(), Value::Bool(false));
m.insert("fetchIndexOHLCV".to_string(), Value::Bool(false));
m.insert("fetchIsolatedBorrowRate".to_string(), Value::Bool(false));
m.insert("fetchIsolatedBorrowRates".to_string(), Value::Bool(false));
m.insert("fetchLedger".to_string(), Value::Bool(false));
m.insert("fetchLeverage".to_string(), Value::Bool(false));
m.insert("fetchLeverageTiers".to_string(), Value::Bool(false));
m.insert("fetchLiquidations".to_string(), Value::Bool(false));
m.insert("fetchMarginMode".to_string(), Value::Bool(false));
m.insert("fetchMarketLeverageTiers".to_string(), Value::Bool(false));
m.insert("fetchMarkets".to_string(), Value::Bool(true));
m.insert("fetchMarkOHLCV".to_string(), Value::Bool(false));
m.insert("fetchMyLiquidations".to_string(), Value::Bool(false));
m.insert("fetchMyTrades".to_string(), Value::Bool(true));
m.insert("fetchOHLCV".to_string(), Value::Bool(true));
m.insert("fetchOpenInterest".to_string(), Value::Bool(false));
m.insert("fetchOpenInterestHistory".to_string(), Value::Bool(false));
m.insert("fetchOpenInterests".to_string(), Value::Bool(false));
m.insert("fetchOpenOrders".to_string(), Value::Bool(true));
m.insert("fetchOption".to_string(), Value::Bool(false));
m.insert("fetchOptionChain".to_string(), Value::Bool(false));
m.insert("fetchOrder".to_string(), Value::Bool(false));
m.insert("fetchOrderBook".to_string(), Value::Bool(true));
m.insert("fetchOrders".to_string(), Value::Bool(false));
m.insert("fetchOrderTrades".to_string(), Value::Bool(false));
m.insert("fetchPosition".to_string(), Value::Bool(true));
m.insert("fetchPositionMode".to_string(), Value::Bool(false));
m.insert("fetchPositions".to_string(), Value::Bool(true));
m.insert("fetchPositionsRisk".to_string(), Value::Bool(false));
m.insert("fetchPremiumIndexOHLCV".to_string(), Value::Bool(false));
m.insert("fetchStatus".to_string(), Value::Bool(true));
m.insert("fetchTicker".to_string(), Value::Bool(true));
m.insert("fetchTickers".to_string(), Value::Bool(true));
m.insert("fetchTime".to_string(), Value::Bool(true));
m.insert("fetchTrades".to_string(), Value::Bool(false));
m.insert("fetchTradingFee".to_string(), Value::Bool(false));
m.insert("fetchTradingFees".to_string(), Value::Bool(false));
m.insert("fetchTransfer".to_string(), Value::Bool(false));
m.insert("fetchTransfers".to_string(), Value::Bool(true));
m.insert("fetchVolatilityHistory".to_string(), Value::Bool(false));
m.insert("fetchWithdrawal".to_string(), Value::Bool(false));
m.insert("fetchWithdrawals".to_string(), Value::Bool(true));
m.insert("reduceMargin".to_string(), Value::Bool(true));
m.insert("repayCrossMargin".to_string(), Value::Bool(false));
m.insert("repayIsolatedMargin".to_string(), Value::Bool(false));
m.insert("sandbox".to_string(), Value::Bool(true));
m.insert("setLeverage".to_string(), Value::Bool(true));
m.insert("setMargin".to_string(), Value::Bool(true));
m.insert("setMarginMode".to_string(), Value::Bool(true));
m.insert("setPositionMode".to_string(), Value::Bool(false));
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("1m".to_string()));
m.insert("5m".to_string(), Value::Str("5m".to_string()));
m.insert("15m".to_string(), Value::Str("15m".to_string()));
m.insert("30m".to_string(), Value::Str("30m".to_string()));
m.insert("1h".to_string(), Value::Str("1h".to_string()));
m.insert("4h".to_string(), Value::Str("4h".to_string()));
m.insert("12h".to_string(), Value::Str("12h".to_string()));
m.insert("1d".to_string(), Value::Str("1d".to_string()));
m.insert("1w".to_string(), Value::Str("1w".to_string()));
m
}));
m.insert("hostname".to_string(), Value::Str("zklighter.elliot.ai".to_string()));
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/5aa1158d-0734-49fc-9155-501d94b76a0b".to_string()));
m.insert("api".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("root".to_string(), Value::Str("https://mainnet.{hostname}".to_string()));
m.insert("public".to_string(), Value::Str("https://mainnet.{hostname}".to_string()));
m.insert("private".to_string(), Value::Str("https://mainnet.{hostname}".to_string()));
m
}));
m.insert("test".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("root".to_string(), Value::Str("https://testnet.{hostname}".to_string()));
m.insert("public".to_string(), Value::Str("https://testnet.{hostname}".to_string()));
m.insert("private".to_string(), Value::Str("https://testnet.{hostname}".to_string()));
m
}));
m.insert("www".to_string(), Value::Str("https://lighter.xyz/".to_string()));
m.insert("doc".to_string(), Value::Str("https://apidocs.lighter.xyz/".to_string()));
m.insert("fees".to_string(), Value::Str("https://docs.lighter.xyz/perpetual-futures/fees".to_string()));
m.insert("referral".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("url".to_string(), Value::Str("https://app.lighter.xyz/?referral=715955W9".to_string()));
m.insert("discount".to_string(), Value::Float(0.1));
m
}));
m
}));
m.insert("api".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("root".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("get".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("info".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m
}));
m
}));
m.insert("public".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("get".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("account".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("accountsByL1Address".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("apikeys".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("exchangeStats".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("assetDetails".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("orderBookDetails".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("orderBookOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("orderBooks".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("recentTrades".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("blockTxs".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("nextNonce".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("tx".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("txFromL1TxHash".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("txs".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("announcement".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("block".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("blocks".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("currentHeight".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("candles".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("fundings".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("fastbridge/info".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("funding-rates".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("withdrawalDelay".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m
}));
m.insert("post".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("sendTx".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("sendTxBatch".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m
}));
m
}));
m.insert("private".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("get".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("accountLimits".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("accountMetadata".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("pnl".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("l1Metadata".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("liquidations".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("positionFunding".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("publicPoolsMetadata".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("accountActiveOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("accountInactiveOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("export".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("trades".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("accountTxs".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("deposit/history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("transfer/history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("withdraw/history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("referral/points".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("transferFeeInfo".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m
}));
m.insert("post".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("changeAccountTier".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("notification/ack".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m
}));
m
}));
m
}));
m.insert("httpExceptions".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
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("21146".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("21500".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("21501".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("21502".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("21503".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("21504".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("21505".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("21506".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("21507".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("21508".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("21511".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("21512".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("21600".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("21601".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("21602".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("21603".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("21604".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("21605".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("21606".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("21607".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("21608".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("21611".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("21612".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("21613".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("21614".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("21700".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("21701".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("21702".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("21703".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("21704".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("21705".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("21706".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("21707".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("21708".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("21709".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("21710".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("21711".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("21712".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("21713".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("21714".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("21715".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("21716".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("21717".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("21718".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("21719".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("21720".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("21721".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("21722".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("21723".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("21724".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("21725".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("21726".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("21727".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("21728".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("21729".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("21730".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("21731".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("21732".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("21733".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("21734".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("21735".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("21736".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("21737".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("21738".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("21739".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("21740".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("21901".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("21902".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("21903".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("21904".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("21905".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("21906".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("23000".to_string(), Value::Str("RateLimitExceeded".to_string()).clone());
m.insert("23001".to_string(), Value::Str("RateLimitExceeded".to_string()).clone());
m.insert("23002".to_string(), Value::Str("RateLimitExceeded".to_string()).clone());
m.insert("23003".to_string(), Value::Str("RateLimitExceeded".to_string()).clone());
m
}));
m.insert("broad".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
m
}));
m.insert("fees".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("taker".to_string(), Value::Int(0));
m.insert("maker".to_string(), Value::Int(0));
m
}));
m.insert("requiredCredentials".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("apiKey".to_string(), Value::Bool(false));
m.insert("secret".to_string(), Value::Bool(false));
m.insert("walletAddress".to_string(), Value::Bool(false));
m.insert("privateKey".to_string(), Value::Bool(true));
m.insert("password".to_string(), Value::Bool(false));
m
}));
m.insert("precisionMode".to_string(), Value::Int(crate::runtime::TICK_SIZE));
m.insert("commonCurrencies".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
m.insert("options".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("defaultType".to_string(), Value::Str("swap".to_string()));
m.insert("builderFee".to_string(), Value::Bool(true));
m.insert("chainId".to_string(), Value::Int(304));
m.insert("accountIndex".to_string(), Value::Null);
m.insert("apiKeyIndex".to_string(), Value::Null);
m.insert("lighterPrivateKey".to_string(), Value::Null);
m.insert("wasmExecPath".to_string(), Value::Null);
m.insert("libraryPath".to_string(), Value::Null);
m.insert("integratorAccountIndex".to_string(), Value::Int(718718));
m.insert("integratorMakerFee".to_string(), Value::Int(1000));
m.insert("integratorTakerFee".to_string(), Value::Int(1000));
m.insert("authDeadlineExpiry".to_string(), Value::Int(28800));
m.insert("authDeadlineMinimumRemaining".to_string(), Value::Int(60));
m
}));
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("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("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
}));
m
}));
m
})]);
Value::Null
}
pub async fn load_account(&mut self, mut chainId: Value, mut privateKey: Value, mut apiKeyIndex: Value, mut accountIndex: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
self.init_auth_object(accountIndex.clone(), apiKeyIndex.clone());
let mut cachedAuths: Value = self.safe_dict(get_value(&get_value(&self.options, &Value::Str("auths".to_string())), &accountIndex), apiKeyIndex.clone(), &[]);
let mut signer: Value = self.safe_value_k(cachedAuths.clone(), "signer", &[]);
if !is_equal(&signer, &Value::Null) {
return signer;
}
let mut libraryPath: Value = Value::Null;
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("loadAccount".to_string()), Value::Str("libraryPath".to_string()), &[]); libraryPath = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut lighterPrivateKeyIsSet: bool = is_true(&(!is_equal(&privateKey, &Value::Null))) && is_true(&(!is_equal(&privateKey, &Value::Str("".to_string()))));
if is_true(&lighterPrivateKeyIsSet) && is_true(&(!is_equal(&libraryPath, &Value::Null))) && is_true(&(!is_equal(&apiKeyIndex, &Value::Null))) && is_true(&(!is_equal(&accountIndex, &Value::Null))) {
// load lighter library, and create lighter client
signer = self.load_lighter_library(libraryPath.clone(), chainId.clone(), privateKey.clone(), self.parse_to_int(apiKeyIndex.clone()), self.parse_to_int(accountIndex.clone()), &[Value::Bool(true)]).await;
add_element_to_object(get_value_mut(get_value_mut(get_value_mut(&mut self.options, &Value::Str("auths".to_string())), &accountIndex), &apiKeyIndex), &Value::Str("signer".to_string()), signer.clone());
return signer;
}
let mut privateKeyIsSet: bool = is_true(&(!is_equal(&self.privateKey, &Value::Null))) && is_true(&(!is_equal(&self.privateKey, &Value::Str("".to_string()))));
if is_true(&privateKeyIsSet) && is_true(&(!is_equal(&apiKeyIndex, &Value::Null))) && is_true(&(!is_equal(&accountIndex, &Value::Null))) {
if is_greater_than(&get_array_length(&self.privateKey), &Value::Int(66)) {
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" after the latest update (v4.5.50), CCXT now expects the l1 private key to be provided in the credentials. Please check for more details: https://github.com/ccxt/ccxt/wiki/FAQ#how-to-use-the-lighter-exchange-in-ccxt".to_string()))));
}
// load lighter library without creating lighter client
signer = self.load_lighter_library(libraryPath.clone(), chainId.clone(), Value::Str("".to_string()), self.parse_to_int(apiKeyIndex.clone()), self.parse_to_int(accountIndex.clone()), &[Value::Bool(false)]).await;
add_element_to_object(get_value_mut(get_value_mut(get_value_mut(&mut self.options, &Value::Str("auths".to_string())), &accountIndex), &apiKeyIndex), &Value::Str("signer".to_string()), signer.clone());
let mut res: Value = Box::pin(self.change_api_key(&[])).await;
Box::pin(self.handle_builder_fee_approval(self.parse_to_int(accountIndex.clone()), self.parse_to_int(apiKeyIndex.clone()))).await;
return res;
}
return signer;
Value::Null
}
pub fn init_auth_object(&self, mut strAccountIndex: Value, mut strApiKeyIndex: Value) {
if !is_true(&(Value::Bool(in_op(&self.options, &Value::Str("auths".to_string()))))) {
add_element_to_object(&mut self.options.clone(), &Value::Str("auths".to_string()), Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
}
if !is_true(&(Value::Bool(in_op(&get_value(&self.options, &Value::Str("auths".to_string())), &strAccountIndex)))) {
add_element_to_object(get_value_mut(unsafe { crate::runtime::coerce_value_to_mut(&self.options) }, &Value::Str("auths".to_string())), &strAccountIndex, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
}
if !is_true(&(Value::Bool(in_op(&get_value(&get_value(&self.options, &Value::Str("auths".to_string())), &strAccountIndex), &strApiKeyIndex)))) {
add_element_to_object(get_value_mut(get_value_mut(unsafe { crate::runtime::coerce_value_to_mut(&self.options) }, &Value::Str("auths".to_string())), &strAccountIndex), &strApiKeyIndex, Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("signer".to_string(), Value::Null);
m.insert("lighterPrivateKey".to_string(), Value::Null);
m.insert("deadline".to_string(), Value::Null);
m.insert("token".to_string(), Value::Null);
m
}));
}
}
pub fn get_lighter_private_key(&self, mut strAccountIndex: Value, mut strApiKeyIndex: Value) -> Value {
if !is_true(&(Value::Bool(in_op(&self.options, &Value::Str("auths".to_string()))))) {
return Value::Null;
}
if !is_true(&(Value::Bool(in_op(&get_value(&self.options, &Value::Str("auths".to_string())), &strAccountIndex)))) {
return Value::Null;
}
if !is_true(&(Value::Bool(in_op(&get_value(&get_value(&self.options, &Value::Str("auths".to_string())), &strAccountIndex), &strApiKeyIndex)))) {
return Value::Null;
}
if !is_true(&(Value::Bool(in_op(&get_value(&get_value(&get_value(&self.options, &Value::Str("auths".to_string())), &strAccountIndex), &strApiKeyIndex), &Value::Str("lighterPrivateKey".to_string()))))) {
return Value::Null;
}
return get_value(&get_value(&get_value(&get_value(&self.options, &Value::Str("auths".to_string())), &strAccountIndex), &strApiKeyIndex), &Value::Str("lighterPrivateKey".to_string()));
Value::Null
}
/*
* @method
* @name lighter#preLoadLighterLibrary
* @description if the required credentials are available in options, it will pre-load the lighter Signer to avoid delaying sensitive calls like createOrder the first time they're executed
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {boolean} true if the signer was loaded, false otherwise
*/
pub async fn pre_load_lighter_library(&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 apiKeyIndex: Value = Value::Null;
{ let __destr_tmp = self.handle_api_key_index(params.clone(), Value::Str("loadAccount".to_string()), Value::Str("apiKeyIndex".to_string()), Value::Str("api_key_index".to_string()), &[]); apiKeyIndex = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut accountIndex: Value = Value::Null;
{ let __destr_tmp = self.handle_account_index(params.clone(), Value::Str("loadAccount".to_string()), Value::Str("accountIndex".to_string()), Value::Str("account_index".to_string()), &[]).await; accountIndex = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_equal(&accountIndex, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" requires accountIndex or account_index".to_string()))));
}
let mut strAccountIndex: Value = self.number_to_string(accountIndex.clone());
let mut strApiKeyIndex: Value = self.number_to_string(apiKeyIndex.clone());
self.init_auth_object(strAccountIndex.clone(), strApiKeyIndex.clone());
let mut signer: Value = self.safe_dict(get_value(&get_value(&get_value(&self.options, &Value::Str("auths".to_string())), &strAccountIndex), &strApiKeyIndex), Value::Str("signer".to_string()), &[]);
if !is_equal(&signer, &Value::Null) {
return Value::Bool(true);
}
signer = self.load_account(get_value(&self.options, &Value::Str("chainId".to_string())), self.get_lighter_private_key(strAccountIndex.clone(), strApiKeyIndex.clone()), strApiKeyIndex.clone(), strAccountIndex.clone(), &[]).await;
self.handle_builder_fee_approval(accountIndex.clone(), apiKeyIndex.clone()).await;
return Value::Bool(!is_equal(&signer, &Value::Null));
Value::Null
}
pub fn handle_api_key_index(&self, mut params: Value, mut methodName1: Value, mut optionName1: Value, mut optionName2: Value, optional_args: &[Value]) -> Value {
let mut defaultValue = get_arg(optional_args, 0, Value::Null);
let mut apiKeyIndex: Value = Value::Null;
{ let __destr_tmp = self.handle_option_and_params2(params.clone(), methodName1.clone(), optionName1.clone(), optionName2.clone(), &[defaultValue.clone()]); apiKeyIndex = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_true(&(is_equal(&apiKeyIndex, &Value::Null))) || is_true(&(is_less_than(&apiKeyIndex, &Value::Int(4)))) || is_true(&(is_greater_than(&apiKeyIndex, &Value::Int(254)))) {
// apiKeyIndex = this.randNumber (2);
apiKeyIndex = Value::Int(254);
add_element_to_object(&mut self.options.clone(), &Value::Str("apiKeyIndex".to_string()), apiKeyIndex.clone()); // default to a value to avoid overriding other keys
}
return Value::List(vec![self.parse_to_int(apiKeyIndex.clone()), params.clone()]);
Value::Null
}
pub async fn handle_account_index(&mut self, mut params: Value, mut methodName1: Value, mut optionName1: Value, mut optionName2: Value, optional_args: &[Value]) -> Value {
let mut defaultValue = get_arg(optional_args, 0, Value::Null);
let mut accountIndex: Value = Value::Null;
{ let __destr_tmp = self.handle_option_and_params2(params.clone(), methodName1.clone(), optionName1.clone(), optionName2.clone(), &[defaultValue.clone()]); accountIndex = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_equal(&accountIndex, &Value::Null) {
let mut walletAddress: Value = self.walletAddress.clone();
if !is_equal(&self.privateKey, &Value::Null) {
if is_greater_than(&get_array_length(&self.privateKey), &Value::Int(66)) {
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" after the latest update (v4.5.50), CCXT now expects the l1 private key to be provided in the credentials. Please check for more details: https://github.com/ccxt/ccxt/wiki/FAQ#how-to-use-the-lighter-exchange-in-ccxt".to_string()))));
}
walletAddress = self.eth_get_address_from_private_key(self.privateKey.clone(), &[]);
}
if is_equal(&walletAddress, &Value::Null) || is_equal(&walletAddress, &Value::Str("".to_string())) {
panic!("{}", crate::exchange_errors::arguments_required(add(&add(&add(&add(&add(&add(&add(&self.id, &Value::Str(" ".to_string())), &methodName1), &Value::Str("() requires an ".to_string())), &optionName1), &Value::Str("/".to_string())), &optionName2), &Value::Str(" parameter or walletAddress to fetch accountIndex. Alternatively set privateKey in credentials to enable automatic walletAddress detection.".to_string()))));
}
let mut res: Value = self.public_get_accounts_by_l1_address(&[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("l1_address".to_string(), walletAddress.clone());
m
})]).await;
//
// {
// "code": 200,
// "l1_address": "0xaaaabbbb....ccccdddd",
// "sub_accounts": [
// {
// "code": 0,
// "account_type": 0,
// "index": 666666,
// "l1_address": "0xaaaabbbb....ccccdddd",
// "cancel_all_time": 0,
// "total_order_count": 0,
// "total_isolated_order_count": 0,
// "pending_order_count": 0,
// "available_balance": "",
// "status": 0,
// "collateral": "40",
// "transaction_time": 0,
// "account_trading_mode": 0
// }
// ]
// }
//
let mut subAccounts: Value = self.safe_list_k(res.clone(), "sub_accounts", &[]);
if is_true(&Value::Bool(is_array(&subAccounts))) {
let mut account: Value = self.safe_dict(subAccounts.clone(), Value::Int(0), &[]);
if is_equal(&account, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&add(&add(&add(&add(&add(&add(&self.id, &Value::Str(" ".to_string())), &methodName1), &Value::Str("() requires an ".to_string())), &optionName1), &Value::Str(" or ".to_string())), &optionName2), &Value::Str(" parameter".to_string()))));
}
accountIndex = get_value(&account, &Value::Str("index".to_string()));
add_element_to_object(&mut self.options, &Value::Str("accountIndex".to_string()), accountIndex.clone());
}
}
return Value::List(vec![self.parse_to_int(accountIndex.clone()), params.clone()]);
Value::Null
}
pub async fn create_sub_account(&mut self, mut name: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut apiKeyIndex: Value = Value::Null;
{ let __destr_tmp = self.handle_api_key_index(params.clone(), Value::Str("createSubAccount".to_string()), Value::Str("apiKeyIndex".to_string()), Value::Str("api_key_index".to_string()), &[]); apiKeyIndex = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut accountIndex: Value = Value::Null;
{ let __destr_tmp = self.handle_account_index(params.clone(), Value::Str("createSubAccount".to_string()), Value::Str("accountIndex".to_string()), Value::Str("account_index".to_string()), &[]).await; accountIndex = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut nonce: Value = self.fetch_nonce(accountIndex.clone(), apiKeyIndex.clone(), &[params.clone()]).await;
let mut signRaw: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("nonce".to_string(), nonce.clone());
m.insert("api_key_index".to_string(), apiKeyIndex.clone());
m.insert("account_index".to_string(), accountIndex.clone());
m
});
let mut strAccountIndex: Value = self.number_to_string(accountIndex.clone());
let mut strApiKeyIndex: Value = self.number_to_string(apiKeyIndex.clone());
let mut signer: Value = self.load_account(get_value(&self.options, &Value::Str("chainId".to_string())), self.get_lighter_private_key(strAccountIndex.clone(), strApiKeyIndex.clone()), strApiKeyIndex.clone(), strAccountIndex.clone(), &[params.clone()]).await;
let __ws_arg_0 = self.extend(signRaw.clone(), &[params.clone()]);
let mut txTypetxInfoVariable = self.lighter_sign_create_sub_account(signer.clone(), __ws_arg_0);
let mut txType: Value = get_value(&txTypetxInfoVariable, &Value::Int(0));
let mut txInfo: Value = get_value(&txTypetxInfoVariable, &Value::Int(1));
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("tx_type".to_string(), txType.clone());
m.insert("tx_info".to_string(), txInfo.clone());
m
});
return self.public_post_send_tx(&[request.clone()]).await;
Value::Null
}
pub fn create_auth(&self, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
// don't omit [accountIndex, apiKeyIndex], request may need them
let mut apiKeyIndex: Value = self.safe_string2(params.clone(), Value::Str("apiKeyIndex".to_string()), Value::Str("api_key_index".to_string()), &[]);
if is_equal(&apiKeyIndex, &Value::Null) {
let mut res: Value = self.handle_option_and_params2(Value::Map({
let mut m = indexmap::IndexMap::new();
m
}), Value::Str("createAuth".to_string()), Value::Str("apiKeyIndex".to_string()), Value::Str("api_key_index".to_string()), &[]);
apiKeyIndex = self.safe_string(res.clone(), Value::Int(0), &[]);
}
let mut accountIndex: Value = self.safe_string2(params.clone(), Value::Str("accountIndex".to_string()), Value::Str("account_index".to_string()), &[]);
if is_equal(&accountIndex, &Value::Null) {
let mut res: Value = self.handle_option_and_params2(Value::Map({
let mut m = indexmap::IndexMap::new();
m
}), Value::Str("createAuth".to_string()), Value::Str("accountIndex".to_string()), Value::Str("account_index".to_string()), &[]);
accountIndex = self.safe_string(res.clone(), Value::Int(0), &[]);
}
let mut auths: Value = self.safe_dict_k(self.options.clone(), "auths", &[]);
let mut accountAuths: Value = self.safe_dict(auths.clone(), accountIndex.clone(), &[]);
let mut cachedAuth: Value = self.safe_dict(accountAuths.clone(), apiKeyIndex.clone(), &[]);
let mut cachedDeadline: Value = self.safe_integer_k(cachedAuth.clone(), "deadline", &[]);
if !is_equal(&cachedDeadline, &Value::Null) {
let mut minimumDeadline: Value = add(&self.seconds(), &self.safe_integer_k(self.options.clone(), "authDeadlineMinimumRemaining", &[Value::Int(60)]));
if is_greater_than_or_equal(&cachedDeadline, &minimumDeadline) {
return self.safe_string_k(cachedAuth.clone(), "token", &[]);
}
}
let mut deadline: Value = add(&self.seconds(), &self.safe_integer_k(self.options.clone(), "authDeadlineExpiry", &[Value::Int(28800)]));
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("deadline".to_string(), deadline.clone());
m.insert("api_key_index".to_string(), self.parse_to_int(apiKeyIndex.clone()));
m.insert("account_index".to_string(), self.parse_to_int(accountIndex.clone()));
m
});
let mut token: Value = self.lighter_create_auth_token(get_value(&get_value(&get_value(&get_value(&self.options, &Value::Str("auths".to_string())), &accountIndex), &apiKeyIndex), &Value::Str("signer".to_string())), request.clone());
add_element_to_object(get_value_mut(get_value_mut(get_value_mut(unsafe { crate::runtime::coerce_value_to_mut(&self.options) }, &Value::Str("auths".to_string())), &accountIndex), &apiKeyIndex), &Value::Str("deadline".to_string()), deadline.clone());
add_element_to_object(get_value_mut(get_value_mut(get_value_mut(unsafe { crate::runtime::coerce_value_to_mut(&self.options) }, &Value::Str("auths".to_string())), &accountIndex), &apiKeyIndex), &Value::Str("token".to_string()), token.clone());
return token;
Value::Null
}
pub fn pow(&self, mut n: Value, mut m: Value) -> Value {
let mut r: Value = crate::precise::Precise::stringMul(&n, &Value::Str("1".to_string()));
let mut c: Value = self.parse_to_int(m.clone());
if is_less_than(&c, &Value::Int(0)) {
panic!("{}", crate::exchange_errors::bad_request(add(&self.id, &Value::Str(" pow() requires m > 0.".to_string()))));
}
if is_equal(&c, &Value::Int(0)) {
return Value::Str("1".to_string());
}
if is_greater_than(&c, &Value::Int(100)) {
panic!("{}", crate::exchange_errors::bad_request(add(&self.id, &Value::Str(" pow() requires m < 100.".to_string()))));
}
{
let mut i: Value = Value::Int(1);
let mut __for_first_917: bool = true;
while { if !__for_first_917 { i = add(&i, &Value::Int(1)); } __for_first_917 = false; is_less_than(&i, &c) } {
r = crate::precise::Precise::stringMul(&r, &n);
}
}
return r;
Value::Null
}
pub fn hash_message(&self, mut message: Value) -> Value {
let mut binaryMessage: Value = self.encode(message.clone());
let mut binaryMessageLength: Value = self.binary_length(binaryMessage.clone(), &[]);
let mut x19: Value = self.base16_to_binary(Value::Str("19".to_string()), &[]);
let mut newline: Value = self.base16_to_binary(Value::Str("0a".to_string()), &[]);
let mut prefix: Value = self.binary_concat(x19.clone(), &[self.encode(Value::Str("Ethereum Signed Message:".to_string())), newline.clone(), self.encode(self.number_to_string(binaryMessageLength.clone()))]);
return add(&Value::Str("0x".to_string()), &self.hash(self.binary_concat(prefix.clone(), &[binaryMessage.clone()]), Value::Str("keccak".to_string()), &[Value::Str("hex".to_string())]));
Value::Null
}
pub fn sign_hash(&self, mut hash: Value, mut privateKey: Value) -> Value {
self.check_required_credentials(&[]);
let mut signature: Value = ecdsa(slice(&hash, &negate(&Value::Int(64)), &Value::Null), slice(&privateKey, &negate(&Value::Int(64)), &Value::Null), Value::Str("secp256k1".to_string()), Value::Null);
let mut r: Value = get_value(&signature, &Value::Str("r".to_string()));
let mut s: Value = get_value(&signature, &Value::Str("s".to_string()));
let mut v: Value = self.int_to_base16(self.sum(&[Value::Int(27), get_value(&signature, &Value::Str("v".to_string()))]), &[]);
return add(&add(&add(&Value::Str("0x".to_string()), &pad_start(&r, &Value::Int(64), &Value::Str("0".to_string()))), &pad_start(&s, &Value::Int(64), &Value::Str("0".to_string()))), &v);
Value::Null
}
pub fn sign_l1_and_prepare_tx_info(&self, mut txInfo: Value, mut message: Value, mut privateKey: Value) -> Value {
let mut hashMessage: Value = self.hash_message(message.clone());
let mut signature: Value = self.sign_hash(hashMessage.clone(), privateKey.clone());
let mut decTxInfo: Value = self.parse_json_value(txInfo.clone());
add_element_to_object(&mut decTxInfo, &Value::Str("L1Sig".to_string()), signature.clone());
return self.json(decTxInfo.clone());
Value::Null
}
pub async fn handle_builder_fee_approval(&mut self, mut accountIndex: Value, mut apiKeyIndex: Value) -> Value {
let mut buildFee: Value = self.safe_bool_k(self.options.clone(), "builderFee", &[Value::Bool(true)]);
if !is_equal(&buildFee, &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 _try_result = futures::FutureExt::catch_unwind(std::panic::AssertUnwindSafe(async {
let mut builder: Value = self.safe_integer_k(self.options.clone(), "integratorAccountIndex", &[Value::Int(718718)]);
let mut takerFeeRate: Value = self.safe_integer_k(self.options.clone(), "integratorTakerFee", &[Value::Int(1000)]);
let mut makerFeeRate: Value = self.safe_integer_k(self.options.clone(), "integratorMakerFee", &[Value::Int(1000)]);
Box::pin(self.approve_builder_fee(builder.clone(), takerFeeRate.clone(), makerFeeRate.clone(), accountIndex.clone(), apiKeyIndex.clone(), &[])).await;
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));
}
return Value::Bool(true);
Value::Null
}
pub async fn approve_builder_fee(&mut self, mut builder: Value, mut takerFeeRate: Value, mut makerFeeRate: Value, mut accountIndex: Value, mut apiKeyIndex: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut strAccountIndex: Value = self.number_to_string(accountIndex.clone());
let mut strApiKeyIndex: Value = self.number_to_string(apiKeyIndex.clone());
let mut signer: Value = Box::pin(self.load_account(get_value(&self.options, &Value::Str("chainId".to_string())), self.get_lighter_private_key(strAccountIndex.clone(), strApiKeyIndex.clone()), strApiKeyIndex.clone(), strAccountIndex.clone(), &[params.clone()])).await;
let __ws_arg_1 = self.extend(params.clone(), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("skipNonce".to_string(), Value::Bool(false));
m
})]);
let mut nonce: Value = self.fetch_nonce(accountIndex.clone(), apiKeyIndex.clone(), &[__ws_arg_1]).await;
let mut expiry: Value = add(&self.milliseconds(), &multiply(&Value::Int(365), &Value::Int(864000)));
let mut signRaw: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("integrator_account_index".to_string(), builder.clone());
m.insert("integrator_taker_fee".to_string(), takerFeeRate.clone());
m.insert("integrator_maker_fee".to_string(), makerFeeRate.clone());
m.insert("approval_expiry".to_string(), expiry.clone());
m.insert("nonce".to_string(), nonce.clone());
m.insert("api_key_index".to_string(), apiKeyIndex.clone());
m.insert("account_index".to_string(), accountIndex.clone());
m
});
let __ws_arg_2 = self.extend(signRaw.clone(), &[params.clone()]);
let mut txTypetxInfomessageToSignVariable = self.lighter_sign_approve_integrator(signer.clone(), __ws_arg_2);
let mut txType: Value = get_value(&txTypetxInfomessageToSignVariable, &Value::Int(0));
let mut txInfo: Value = get_value(&txTypetxInfomessageToSignVariable, &Value::Int(1));
let mut messageToSign: Value = get_value(&txTypetxInfomessageToSignVariable, &Value::Int(2));
let mut newTxInfo: Value = self.sign_l1_and_prepare_tx_info(txInfo.clone(), messageToSign.clone(), self.privateKey.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("tx_type".to_string(), txType.clone());
m.insert("tx_info".to_string(), newTxInfo.clone());
m
});
let mut response: Value = self.public_post_send_tx(&[request.clone()]).await;
return response;
Value::Null
}
pub async fn change_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 apiKeyIndex: Value = Value::Null;
{ let __destr_tmp = self.handle_api_key_index(params.clone(), Value::Str("changeApiKey".to_string()), Value::Str("apiKeyIndex".to_string()), Value::Str("api_key_index".to_string()), &[]); apiKeyIndex = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut accountIndex: Value = Value::Null;
{ let __destr_tmp = self.handle_account_index(params.clone(), Value::Str("changeApiKey".to_string()), Value::Str("accountIndex".to_string()), Value::Str("account_index".to_string()), &[]).await; accountIndex = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut strAccountIndex: Value = self.number_to_string(accountIndex.clone());
let mut strApiKeyIndex: Value = self.number_to_string(apiKeyIndex.clone());
let mut signerNotLoad: Value = get_value(&get_value(&get_value(&get_value(&self.options, &Value::Str("auths".to_string())), &strAccountIndex), &strApiKeyIndex), &Value::Str("signer".to_string()));
let mut privateKeypublicKeyVariable = self.lighter_generate_api_key(signerNotLoad.clone());
let mut privateKey: Value = get_value(&privateKeypublicKeyVariable, &Value::Int(0));
let mut publicKey: Value = get_value(&privateKeypublicKeyVariable, &Value::Int(1));
let __ws_arg_3 = self.extend(params.clone(), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("skipNonce".to_string(), Value::Bool(false));
m
})]);
let mut nonce: Value = self.fetch_nonce(accountIndex.clone(), apiKeyIndex.clone(), &[__ws_arg_3]).await;
let mut signRaw: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("pubkey".to_string(), self.encode(publicKey.clone()));
m.insert("nonce".to_string(), nonce.clone());
m.insert("api_key_index".to_string(), apiKeyIndex.clone());
m.insert("account_index".to_string(), accountIndex.clone());
m
});
// create lighter client
let mut signer: Value = self.lighter_create_client(signerNotLoad.clone(), get_value(&self.options, &Value::Str("chainId".to_string())), privateKey.clone(), apiKeyIndex.clone(), accountIndex.clone());
let __ws_arg_4 = self.extend(signRaw.clone(), &[params.clone()]);
let mut txTypetxInfomessageToSignVariable = self.lighter_sign_change_pubkey(signer.clone(), __ws_arg_4);
let mut txType: Value = get_value(&txTypetxInfomessageToSignVariable, &Value::Int(0));
let mut txInfo: Value = get_value(&txTypetxInfomessageToSignVariable, &Value::Int(1));
let mut messageToSign: Value = get_value(&txTypetxInfomessageToSignVariable, &Value::Int(2));
let mut newTxInfo: Value = self.sign_l1_and_prepare_tx_info(txInfo.clone(), messageToSign.clone(), self.privateKey.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("tx_type".to_string(), txType.clone());
m.insert("tx_info".to_string(), newTxInfo.clone());
m
});
self.public_post_send_tx(&[request.clone()]).await;
add_element_to_object(get_value_mut(get_value_mut(get_value_mut(&mut self.options, &Value::Str("auths".to_string())), &strAccountIndex), &strApiKeyIndex), &Value::Str("lighterPrivateKey".to_string()), privateKey.clone());
add_element_to_object(get_value_mut(get_value_mut(get_value_mut(&mut self.options, &Value::Str("auths".to_string())), &strAccountIndex), &strApiKeyIndex), &Value::Str("signer".to_string()), signer.clone()); // reassign signer in go
Box::pin(self.handle_builder_fee_approval(accountIndex.clone(), apiKeyIndex.clone())).await;
return signer;
Value::Null
}
pub fn set_sandbox_mode(&mut self, mut enable: Value) {
self.super_set_sandbox_mode(enable.clone());
add_element_to_object(&mut self.options, &Value::Str("sandboxMode".to_string()), enable.clone());
add_element_to_object(&mut self.options, &Value::Str("chainId".to_string()), ternary(is_true(&enable), Value::Int(300), Value::Int(304)));
}
pub fn create_order_request(&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
}));
if is_equal(&type_var, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" requires a type argument".to_string()))));
}
if is_equal(&side, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" requires a side argument".to_string()))));
}
/*
* @method
* @ignore
* @name lighter#createOrderRequest
* @description helper function to build the request
* @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 you want to trade in units of the base currency
* @param {float} [price] the price that the order is to be fulfilled, in units of the quote currency, ignored in market orders
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {int} [params.nonce] nonce for the account
* @param {int} [params.apiKeyIndex] apiKeyIndex
* @param {int} [params.accountIndex] accountIndex
* @param {int} [params.orderExpiry] orderExpiry
* @returns {any[]} request to be sent to the exchange
*/
if is_equal(&price, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" createOrder() requires a price argument".to_string()))));
}
let mut reduceOnly: Value = self.safe_bool2(params.clone(), Value::Str("reduceOnly".to_string()), Value::Str("reduce_only".to_string()), &[Value::Bool(false)]); // default false
let mut orderType: Value = to_upper(&type_var);
let mut market: Value = self.market(symbol.clone());
let mut orderSide: Value = to_upper(&side);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("market_index".to_string(), self.parse_to_int(get_value(&market, &Value::Str("id".to_string()))));
m
});
let mut nonce: Value = Value::Null;
let mut apiKeyIndex: Value = Value::Null;
let mut accountIndex: Value = Value::Null;
let mut orderExpiry: Value = Value::Null;
{ let __destr_tmp = self.handle_api_key_index(params.clone(), Value::Str("createOrder".to_string()), Value::Str("apiKeyIndex".to_string()), Value::Str("api_key_index".to_string()), &[]); apiKeyIndex = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
{ let __destr_tmp = self.handle_option_and_params2(params.clone(), Value::Str("createOrder".to_string()), Value::Str("accountIndex".to_string()), Value::Str("account_index".to_string()), &[]); accountIndex = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("createOrder".to_string()), Value::Str("nonce".to_string()), &[]); nonce = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("createOrder".to_string()), Value::Str("orderExpiry".to_string()), &[Value::Int(0)]); orderExpiry = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if !is_equal(&nonce, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("nonce".to_string()), nonce.clone());
}
add_element_to_object(&mut request, &Value::Str("api_key_index".to_string()), apiKeyIndex.clone());
add_element_to_object(&mut request, &Value::Str("account_index".to_string()), self.parse_to_int(accountIndex.clone()));
let mut triggerPrice: Value = self.safe_string2(params.clone(), Value::Str("triggerPrice".to_string()), Value::Str("stopPrice".to_string()), &[]);
let mut stopLossPrice: Value = self.safe_value_k(params.clone(), "stopLossPrice", &[triggerPrice.clone()]);
let mut takeProfitPrice: Value = self.safe_value_k(params.clone(), "takeProfitPrice", &[]);
let mut stopLoss: Value = self.safe_value_k(params.clone(), "stopLoss", &[]);
let mut takeProfit: Value = self.safe_value_k(params.clone(), "takeProfit", &[]);
let mut hasStopLoss: bool = !is_equal(&stopLoss, &Value::Null);
let mut hasTakeProfit: bool = !is_equal(&takeProfit, &Value::Null);
let mut isConditional: bool = is_true(&(!is_equal(&stopLossPrice, &Value::Null))) || is_true(&(!is_equal(&takeProfitPrice, &Value::Null)));
let mut isMarketOrder: Value = Value::Bool(is_equal(&orderType, &Value::Str("MARKET".to_string())));
let mut timeInForce: Value = self.safe_string_lower(params.clone(), Value::Str("timeInForce".to_string()), &[Value::Str("gtt".to_string())]);
let mut postOnly: Value = self.is_post_only(isMarketOrder.clone(), Value::Null, &[params.clone()]);
params = self.omit(params.clone(), Value::List(vec![Value::Str("stopLoss".to_string()), Value::Str("takeProfit".to_string()), Value::Str("timeInForce".to_string())]), &[]);
let mut orderTypeNum: Value = Value::Null;
let mut timeInForceNum: Value = Value::Null;
if is_true(&isMarketOrder) {
orderTypeNum = Value::Int(1);
timeInForceNum = Value::Int(0);
} else {
orderTypeNum = Value::Int(0);
}
if is_equal(&orderSide, &Value::Str("BUY".to_string())) {
add_element_to_object(&mut request, &Value::Str("is_ask".to_string()), Value::Int(0));
} else {
add_element_to_object(&mut request, &Value::Str("is_ask".to_string()), Value::Int(1));
}
if is_true(&postOnly) {
timeInForceNum = Value::Int(2);
orderExpiry = negate(&Value::Int(1));
} else {
if !is_true(&isMarketOrder) {
if is_equal(&timeInForce, &Value::Str("ioc".to_string())) {
timeInForceNum = Value::Int(0);
orderExpiry = Value::Int(0);
} else if is_equal(&timeInForce, &Value::Str("gtt".to_string())) {
timeInForceNum = Value::Int(1);
orderExpiry = negate(&Value::Int(1));
}
}
}
let mut marketInfo: Value = self.safe_dict_k(market.clone(), "info", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut amountStr: Value = Value::Null;
let mut priceStr: Value = self.price_to_precision(symbol.clone(), price.clone());
let mut amountScale: Value = self.pow(Value::Str("10".to_string()), get_value(&marketInfo, &Value::Str("size_decimals".to_string())));
let mut priceScale: Value = self.pow(Value::Str("10".to_string()), get_value(&marketInfo, &Value::Str("price_decimals".to_string())));
let mut triggerPriceStr: Value = Value::Str("0".to_string()); // default is 0
let mut defaultClientOrderId: Value = self.rand_number(Value::Int(9)); // c# only support int32 2147483647.
let mut clientOrderId: Value = self.safe_integer2(params.clone(), Value::Str("client_order_index".to_string()), Value::Str("clientOrderId".to_string()), &[defaultClientOrderId.clone()]);
params = self.omit(params.clone(), Value::List(vec![Value::Str("reduceOnly".to_string()), Value::Str("reduce_only".to_string()), Value::Str("timeInForce".to_string()), Value::Str("postOnly".to_string()), Value::Str("nonce".to_string()), Value::Str("apiKeyIndex".to_string()), Value::Str("stopPrice".to_string()), Value::Str("triggerPrice".to_string()), Value::Str("stopLossPrice".to_string()), Value::Str("takeProfitPrice".to_string()), Value::Str("client_order_index".to_string()), Value::Str("clientOrderId".to_string())]), &[]);
if is_true(&isConditional) {
amountStr = self.number_to_string(amount.clone());
if !is_equal(&stopLossPrice, &Value::Null) {
if is_true(&isMarketOrder) {
orderTypeNum = Value::Int(2);
} else {
orderTypeNum = Value::Int(3);
}
triggerPriceStr = self.price_to_precision(symbol.clone(), stopLossPrice.clone());
} else if !is_equal(&takeProfitPrice, &Value::Null) {
if is_true(&isMarketOrder) {
orderTypeNum = Value::Int(4);
} else {
orderTypeNum = Value::Int(5);
}
triggerPriceStr = self.price_to_precision(symbol.clone(), takeProfitPrice.clone());
}
} else {
amountStr = self.amount_to_precision(symbol.clone(), amount.clone());
}
add_element_to_object(&mut request, &Value::Str("order_expiry".to_string()), orderExpiry.clone());
add_element_to_object(&mut request, &Value::Str("order_type".to_string()), orderTypeNum.clone());
add_element_to_object(&mut request, &Value::Str("time_in_force".to_string()), timeInForceNum.clone());
add_element_to_object(&mut request, &Value::Str("reduce_only".to_string()), ternary(is_true(&(is_equal(&reduceOnly, &Value::Bool(true)))), Value::Int(1), Value::Int(0)));
add_element_to_object(&mut request, &Value::Str("client_order_index".to_string()), clientOrderId.clone());
add_element_to_object(&mut request, &Value::Str("base_amount".to_string()), self.parse_to_int(crate::precise::Precise::stringMul(&amountStr, &amountScale)));
add_element_to_object(&mut request, &Value::Str("avg_execution_price".to_string()), self.parse_to_int(crate::precise::Precise::stringMul(&priceStr, &priceScale)));
add_element_to_object(&mut request, &Value::Str("trigger_price".to_string()), self.parse_to_int(crate::precise::Precise::stringMul(&triggerPriceStr, &priceScale)));
if is_true(&self.safe_bool_k(self.options.clone(), "builderFee", &[Value::Bool(true)])) {
add_element_to_object(&mut request, &Value::Str("integrator_account_index".to_string()), get_value(&self.options, &Value::Str("integratorAccountIndex".to_string())));
add_element_to_object(&mut request, &Value::Str("integrator_taker_fee".to_string()), get_value(&self.options, &Value::Str("integratorTakerFee".to_string())));
add_element_to_object(&mut request, &Value::Str("integrator_maker_fee".to_string()), get_value(&self.options, &Value::Str("integratorMakerFee".to_string())));
}
let mut orders: Value = Value::List(vec![]);
append_to_array(&mut orders, self.extend(request.clone(), &[params.clone()]));
if is_true(&hasStopLoss) || is_true(&hasTakeProfit) {
// group order
add_element_to_object(get_value_mut(&mut orders, &Value::Int(0)), &Value::Str("client_order_index".to_string()), Value::Int(0)); // client order index should be 0
let mut triggerOrderSide: Value = Value::Str("".to_string());
if is_equal(&side, &Value::Str("BUY".to_string())) {
triggerOrderSide = Value::Str("sell".to_string());
} else {
triggerOrderSide = Value::Str("buy".to_string());
}
let mut stopLossOrderTriggerPrice: Value = self.safe_number2(stopLoss.clone(), Value::Str("triggerPrice".to_string()), Value::Str("stopPrice".to_string()), &[]);
let mut stopLossOrderType: Value = self.safe_string_k(stopLoss.clone(), "type", &[Value::Str("limit".to_string())]);
let mut stopLossOrderLimitPrice: Value = self.safe_number2(stopLoss.clone(), Value::Str("price".to_string()), Value::Str("stopLossPrice".to_string()), &[stopLossOrderTriggerPrice.clone()]);
let mut takeProfitOrderTriggerPrice: Value = self.safe_number2(takeProfit.clone(), Value::Str("triggerPrice".to_string()), Value::Str("stopPrice".to_string()), &[]);
let mut takeProfitOrderType: Value = self.safe_string_k(takeProfit.clone(), "type", &[Value::Str("limit".to_string())]);
let mut takeProfitOrderLimitPrice: Value = self.safe_number2(takeProfit.clone(), Value::Str("price".to_string()), Value::Str("takeProfitPrice".to_string()), &[takeProfitOrderTriggerPrice.clone()]);
// amount should be 0 for child orders
if !is_equal(&stopLoss, &Value::Null) {
let __ws_arg_5 = self.extend(params.clone(), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("stopLossPrice".to_string(), stopLossOrderTriggerPrice.clone());
m.insert("reduceOnly".to_string(), Value::Bool(true));
m
})]);
let mut orderObj: Value = get_value(&self.create_order_request(symbol.clone(), stopLossOrderType.clone(), triggerOrderSide.clone(), Value::Int(0), &[stopLossOrderLimitPrice.clone(), __ws_arg_5]), &Value::Int(0));
add_element_to_object(&mut orderObj, &Value::Str("client_order_index".to_string()), Value::Int(0));
append_to_array(&mut orders, orderObj.clone());
}
if !is_equal(&takeProfit, &Value::Null) {
let __ws_arg_6 = self.extend(params.clone(), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("takeProfitPrice".to_string(), takeProfitOrderTriggerPrice.clone());
m.insert("reduceOnly".to_string(), Value::Bool(true));
m
})]);
let mut orderObj: Value = get_value(&self.create_order_request(symbol.clone(), takeProfitOrderType.clone(), triggerOrderSide.clone(), Value::Int(0), &[takeProfitOrderLimitPrice.clone(), __ws_arg_6]), &Value::Int(0));
add_element_to_object(&mut orderObj, &Value::Str("client_order_index".to_string()), Value::Int(0));
append_to_array(&mut orders, orderObj.clone());
}
}
return orders;
Value::Null
}
pub async fn fetch_nonce(&mut self, mut accountIndex: Value, mut apiKeyIndex: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_true(&(is_equal(&accountIndex, &Value::Null))) || is_true(&(is_equal(&apiKeyIndex, &Value::Null))) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" fetchNonce() requires accountIndex and apiKeyIndex.".to_string()))));
}
if is_true(&Value::Bool(in_op(¶ms, &Value::Str("nonce".to_string())))) {
return self.safe_integer_k(params.clone(), "nonce", &[]);
}
let mut nonceInOptions: Value = self.safe_integer_k(self.options.clone(), "nonce", &[]);
if !is_equal(&nonceInOptions, &Value::Null) {
return nonceInOptions;
}
// avoid skipNonce for l1 operations
let mut skipNonce: Value = Value::Bool(true);
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchNonce".to_string()), Value::Str("skipNonce".to_string()), &[Value::Bool(true)]); skipNonce = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_true(&skipNonce) {
return self.milliseconds();
}
let mut response: Value = self.public_get_next_nonce(&[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("account_index".to_string(), accountIndex.clone());
m.insert("api_key_index".to_string(), apiKeyIndex.clone());
m
})]).await;
return self.safe_integer_k(response.clone(), "nonce", &[]);
Value::Null
}
pub async fn sign_and_create_order(&mut self, mut method: Value, 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
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut accountIndex: Value = Value::Null;
{ let __destr_tmp = self.handle_account_index(params.clone(), method.clone(), Value::Str("accountIndex".to_string()), Value::Str("account_index".to_string()), &[]).await; accountIndex = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
add_element_to_object(&mut params, &Value::Str("accountIndex".to_string()), accountIndex.clone());
let mut market: Value = self.market(symbol.clone());
let mut groupingType: Value = Value::Null;
{ let __destr_tmp = self.handle_option_and_params(params.clone(), method.clone(), Value::Str("groupingType".to_string()), &[Value::Int(3)]); groupingType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }; // default GROUPING_TYPE_ONE_TRIGGERS_A_ONE_CANCELS_THE_OTHER
let mut orderRequests: Value = self.create_order_request(symbol.clone(), type_var.clone(), side.clone(), amount.clone(), &[price.clone(), params.clone()]);
let mut totalOrderRequests: Value = get_array_length(&orderRequests);
let mut apiKeyIndex: Value = Value::Null;
let mut order: Value = Value::Null;
if is_greater_than(&totalOrderRequests, &Value::Int(0)) {
order = get_value(&orderRequests, &Value::Int(0));
apiKeyIndex = get_value(&order, &Value::Str("api_key_index".to_string()));
}
let mut strAccountIndex: Value = self.number_to_string(accountIndex.clone());
let mut strApiKeyIndex: Value = self.number_to_string(apiKeyIndex.clone());
let mut signer: Value = self.load_account(get_value(&self.options, &Value::Str("chainId".to_string())), self.get_lighter_private_key(strAccountIndex.clone(), strApiKeyIndex.clone()), strApiKeyIndex.clone(), strAccountIndex.clone(), &[params.clone()]).await;
// the nonce could be updated
if is_equal(&self.safe_integer_k(order.clone(), "nonce", &[]), &Value::Null) {
add_element_to_object(&mut order, &Value::Str("nonce".to_string()), self.fetch_nonce(accountIndex.clone(), apiKeyIndex.clone(), &[]).await);
}
let mut txType: Value = Value::Null;
let mut txInfo: Value = Value::Null;
if is_less_than(&totalOrderRequests, &Value::Int(2)) {
{ let __destr_tmp = self.lighter_sign_create_order(signer.clone(), order.clone()); txType = get_value(&__destr_tmp, &Value::Int(0)); txInfo = get_value(&__destr_tmp, &Value::Int(1)); }
} else {
let mut signingPayload: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("grouping_type".to_string(), groupingType.clone());
m.insert("orders".to_string(), orderRequests.clone());
m.insert("nonce".to_string(), get_value(&order, &Value::Str("nonce".to_string())));
m.insert("api_key_index".to_string(), apiKeyIndex.clone());
m.insert("account_index".to_string(), accountIndex.clone());
m
});
if is_true(&self.safe_bool_k(self.options.clone(), "builderFee", &[Value::Bool(true)])) {
add_element_to_object(&mut signingPayload, &Value::Str("integrator_account_index".to_string()), get_value(&order, &Value::Str("integrator_account_index".to_string())));
add_element_to_object(&mut signingPayload, &Value::Str("integrator_taker_fee".to_string()), get_value(&order, &Value::Str("integrator_taker_fee".to_string())));
add_element_to_object(&mut signingPayload, &Value::Str("integrator_maker_fee".to_string()), get_value(&order, &Value::Str("integrator_maker_fee".to_string())));
}
{ let __destr_tmp = self.lighter_sign_create_grouped_orders(signer.clone(), signingPayload.clone()); txType = get_value(&__destr_tmp, &Value::Int(0)); txInfo = get_value(&__destr_tmp, &Value::Int(1)); }
}
return Value::List(vec![txType.clone(), txInfo.clone(), order.clone(), market.clone()]);
Value::Null
}
/*
* @method
* @name lighter#createOrder
* @description create a trade 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 fulfilled, in units of the quote currency, ignored in market orders
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.timeInForce] 'GTT' or 'IOC', default is 'GTT'
* @param {int} [params.clientOrderId] client order id, should be unique for each order, default is a random number
* @param {string} [params.triggerPrice] trigger price for stop loss or take profit orders, in units of the quote currency
* @param {boolean} [params.reduceOnly] whether the order is reduce only, default false
* @param {int} [params.nonce] nonce for the account
* @param {int} [params.apiKeyIndex] apiKeyIndex
* @param {int} [params.accountIndex] accountIndex
* @param {int} [params.orderExpiry] orderExpiry
* @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
}));
let mut txTypetxInfoordermarketVariable = self.sign_and_create_order(Value::Str("createOrder".to_string()), symbol.clone(), type_var.clone(), side.clone(), amount.clone(), &[price.clone(), params.clone()]).await;
let mut txType: Value = get_value(&txTypetxInfoordermarketVariable, &Value::Int(0));
let mut txInfo: Value = get_value(&txTypetxInfoordermarketVariable, &Value::Int(1));
let mut order: Value = get_value(&txTypetxInfoordermarketVariable, &Value::Int(2));
let mut market: Value = get_value(&txTypetxInfoordermarketVariable, &Value::Int(3));
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("tx_type".to_string(), txType.clone());
m.insert("tx_info".to_string(), txInfo.clone());
m
});
let mut response: Value = self.public_post_send_tx(&[request.clone()]).await;
return self.parse_order(self.deep_extend(response.clone(), &[order.clone()]), &[market.clone()]);
Value::Null
}
/*
* @method
* @name lighter#editOrder
* @description cancels an order and places a new order
* @param {string} id order id
* @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 the currency you want to trade in units of the base currency
* @param {float} [price] the price at which the order is to be fulfilled, in units of the quote currency, ignored in market orders
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.accountIndex] account index
* @param {string} [params.apiKeyIndex] api key index
* @returns {object} an [order structure]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn edit_order(&mut self, mut id: Value, mut symbol: Value, mut type_var: Value, mut side: Value, optional_args: &[Value]) -> Value {
let mut amount = get_arg(optional_args, 0, Value::Null);
let mut price = 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 apiKeyIndex: Value = Value::Null;
{ let __destr_tmp = self.handle_api_key_index(params.clone(), Value::Str("editOrder".to_string()), Value::Str("apiKeyIndex".to_string()), Value::Str("api_key_index".to_string()), &[]); apiKeyIndex = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut accountIndex: Value = Value::Null;
{ let __destr_tmp = self.handle_account_index(params.clone(), Value::Str("editOrder".to_string()), Value::Str("accountIndex".to_string()), Value::Str("account_index".to_string()), &[]).await; accountIndex = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut strAccountIndex: Value = self.number_to_string(accountIndex.clone());
let mut strApiKeyIndex: Value = self.number_to_string(apiKeyIndex.clone());
let mut signer: Value = self.load_account(get_value(&self.options, &Value::Str("chainId".to_string())), self.get_lighter_private_key(strAccountIndex.clone(), strApiKeyIndex.clone()), strApiKeyIndex.clone(), strAccountIndex.clone(), &[params.clone()]).await;
let mut market: Value = self.market(symbol.clone());
let mut marketInfo: Value = self.safe_dict_k(market.clone(), "info", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut amountScale: Value = self.pow(Value::Str("10".to_string()), get_value(&marketInfo, &Value::Str("size_decimals".to_string())));
let mut priceScale: Value = self.pow(Value::Str("10".to_string()), get_value(&marketInfo, &Value::Str("price_decimals".to_string())));
let mut triggerPrice: Value = self.safe_string_n(params.clone(), Value::List(vec![Value::Str("stopPrice".to_string()), Value::Str("triggerPrice".to_string()), Value::Str("stopLossPrice".to_string()), Value::Str("takeProfitPrice".to_string())]), &[]);
params = self.omit(params.clone(), Value::List(vec![Value::Str("stopPrice".to_string()), Value::Str("triggerPrice".to_string()), Value::Str("stopLossPrice".to_string()), Value::Str("takeProfitPrice".to_string())]), &[]);
let mut amountStr: Value = Value::Null;
let mut priceStr: Value = self.price_to_precision(symbol.clone(), price.clone());
let mut triggerPriceStr: Value = Value::Str("0".to_string()); // default is 0
if !is_equal(&triggerPrice, &Value::Null) {
amountStr = self.number_to_string(amount.clone());
triggerPriceStr = self.price_to_precision(symbol.clone(), triggerPrice.clone());
} else {
amountStr = self.amount_to_precision(symbol.clone(), amount.clone());
}
let mut nonce: Value = self.fetch_nonce(accountIndex.clone(), apiKeyIndex.clone(), &[params.clone()]).await;
let mut signRaw: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("market_index".to_string(), self.parse_to_int(get_value(&market, &Value::Str("id".to_string()))));
m.insert("index".to_string(), self.parse_to_int(id.clone()));
m.insert("base_amount".to_string(), self.parse_to_int(crate::precise::Precise::stringMul(&amountStr, &amountScale)));
m.insert("price".to_string(), self.parse_to_int(crate::precise::Precise::stringMul(&priceStr, &priceScale)));
m.insert("trigger_price".to_string(), self.parse_to_int(crate::precise::Precise::stringMul(&triggerPriceStr, &priceScale)));
m.insert("nonce".to_string(), nonce.clone());
m.insert("api_key_index".to_string(), apiKeyIndex.clone());
m.insert("account_index".to_string(), accountIndex.clone());
m
});
if is_true(&self.safe_bool_k(self.options.clone(), "builderFee", &[Value::Bool(true)])) {
add_element_to_object(&mut signRaw, &Value::Str("integrator_account_index".to_string()), get_value(&self.options, &Value::Str("integratorAccountIndex".to_string())));
add_element_to_object(&mut signRaw, &Value::Str("integrator_taker_fee".to_string()), get_value(&self.options, &Value::Str("integratorTakerFee".to_string())));
add_element_to_object(&mut signRaw, &Value::Str("integrator_maker_fee".to_string()), get_value(&self.options, &Value::Str("integratorMakerFee".to_string())));
}
let __ws_arg_7 = self.extend(signRaw.clone(), &[params.clone()]);
let mut txTypetxInfoVariable = self.lighter_sign_modify_order(signer.clone(), __ws_arg_7);
let mut txType: Value = get_value(&txTypetxInfoVariable, &Value::Int(0));
let mut txInfo: Value = get_value(&txTypetxInfoVariable, &Value::Int(1));
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("tx_type".to_string(), txType.clone());
m.insert("tx_info".to_string(), txInfo.clone());
m
});
let mut response: Value = self.public_post_send_tx(&[request.clone()]).await;
return self.parse_order(response.clone(), &[market.clone()]);
Value::Null
}
/*
* @method
* @name lighter#fetchStatus
* @description the latest known information on the availability of the exchange API
* @see https://apidocs.lighter.xyz/reference/status
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a [status structure]{@link https://docs.ccxt.com/?id=exchange-status-structure}
*/
pub async fn fetch_status(&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 response: Value = self.root_get(&[params.clone()]).await;
//
// {
// "status": "1",
// "network_id": "1",
// "timestamp": "1717777777"
// }
//
let mut status: Value = self.safe_string_k(response.clone(), "status", &[]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("status".to_string(), ternary(is_true(&(is_equal(&status, &Value::Str("200".to_string())))), Value::Str("ok".to_string()), Value::Str("error".to_string())));
m.insert("updated".to_string(), Value::Null);
m.insert("eta".to_string(), Value::Null);
m.insert("url".to_string(), Value::Null);
m.insert("info".to_string(), response.clone());
m
});
Value::Null
}
/*
* @method
* @name lighter#fetchTime
* @description fetches the current integer timestamp in milliseconds from the exchange server
* @see https://apidocs.lighter.xyz/reference/status
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {int} the current integer timestamp in milliseconds from the exchange server
*/
pub async fn fetch_time(&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 response: Value = self.root_get(&[params.clone()]).await;
return self.safe_timestamp(response.clone(), Value::Str("timestamp".to_string()), &[]);
Value::Null
}
/*
* @method
* @name lighter#fetchMarkets
* @description retrieves data on all markets for lighter
* @see https://apidocs.lighter.xyz/reference/orderbookdetails
* @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 response: Value = self.public_get_order_book_details(&[params.clone()]).await;
//
// {
// "code": "200",
// "message": "string",
// "order_book_details": [
// {
// "symbol": "ETH",
// "market_id": 0,
// "market_type": "perp",
// "base_asset_id": 0,
// "quote_asset_id": 0,
// "status": "active",
// "taker_fee": "0.0001",
// "maker_fee": "0.0000",
// "liquidation_fee": "0.01",
// "min_base_amount": "0.01",
// "min_quote_amount": "0.1",
// "supported_size_decimals": "4",
// "supported_price_decimals": "4",
// "supported_quote_decimals": "4",
// "order_quote_limit": "281474976.710655",
// "size_decimals": "4",
// "price_decimals": "4",
// "quote_multiplier": "10000",
// "default_initial_margin_fraction": "100",
// "min_initial_margin_fraction": "100",
// "maintenance_margin_fraction": "50",
// "closeout_margin_fraction": "100",
// "last_trade_price": "3024.66",
// "daily_trades_count": "68",
// "daily_base_token_volume": "235.25",
// "daily_quote_token_volume": "93566.25",
// "daily_price_low": "3014.66",
// "daily_price_high": "3024.66",
// "daily_price_change": "3.66",
// "open_interest": "93.0",
// "daily_chart": "{1640995200:3024.66}",
// "market_config": {
// "market_margin_mode": 0,
// "insurance_fund_account_index": 281474976710655,
// "liquidation_mode": 0,
// "force_reduce_only": false,
// "funding_fee_discounts_enabled": true,
// "trading_hours": "",
// "hidden": true
// },
// "strategy_index": 0
// }
// ],
// "spot_order_book_details": [
// {
// "symbol": "ETH/USDC",
// "market_id": 2048,
// "market_type": "spot",
// "base_asset_id": 1,
// "quote_asset_id": 3,
// "status": "active",
// "taker_fee": "0.0000",
// "maker_fee": "0.0000",
// "liquidation_fee": "0.0000",
// "min_base_amount": "0.0001",
// "min_quote_amount": "0.000001",
// "order_quote_limit": "2500000.000000",
// "supported_size_decimals": 4,
// "supported_price_decimals": 2,
// "supported_quote_decimals": 6,
// "size_decimals": 4,
// "price_decimals": 2,
// "last_trade_price": 2731.79,
// "daily_trades_count": 126993,
// "daily_base_token_volume": 1203.0962,
// "daily_quote_token_volume": 3516374.947553,
// "daily_price_low": 2717.47,
// "daily_price_high": 3044.21,
// "daily_price_change": -10.2389493724579,
// "daily_chart": "{1640995200:3024.66}"
// }
// ]
// }
//
let mut spotMarkets: Value = self.safe_list_k(response.clone(), "spot_order_book_details", &[Value::List(vec![])]);
let mut swapMarkets: Value = self.safe_list_k(response.clone(), "order_book_details", &[Value::List(vec![])]);
let mut markets: Value = self.array_concat(spotMarkets.clone(), swapMarkets.clone());
let mut result: Value = Value::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_918: bool = true;
while { if !__for_first_918 { i = add(&i, &Value::Int(1)); } __for_first_918 = false; is_less_than(&i, &get_array_length(&markets)) } {
let mut market: Value = get_value(&markets, &i);
let mut market: Value = get_value(&markets, &i);
let mut id: Value = self.safe_string_k(market.clone(), "market_id", &[]);
let mut type_var: Value = self.safe_string_k(market.clone(), "market_type", &[]);
type_var = ternary(is_true(&(is_equal(&type_var, &Value::Str("perp".to_string())))), Value::Str("swap".to_string()), type_var.clone());
let mut baseId: Value = self.safe_string_k(market.clone(), "symbol", &[]);
if !is_equal(&baseId, &Value::Null) && !is_equal(&get_index_of(&baseId, &Value::Str("/".to_string())), &negate(&Value::Int(1))) {
baseId = get_value(&split(&baseId, &Value::Str("/".to_string())), &Value::Int(0));
}
let mut quoteId: Value = Value::Str("USDC".to_string());
let mut settleId: Value = ternary(is_true(&(is_equal(&type_var, &Value::Str("swap".to_string())))), Value::Str("USDC".to_string()), Value::Null);
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(&base, &Value::Str("/".to_string())), "e);
if !is_equal(&settle, &Value::Null) {
symbol = add(&add(&symbol, &Value::Str(":".to_string())), &settle);
}
let mut amountDecimals: Value = self.safe_string2(market.clone(), Value::Str("size_decimals".to_string()), Value::Str("supported_size_decimals".to_string()), &[]);
let mut priceDecimals: Value = self.safe_string2(market.clone(), Value::Str("price_decimals".to_string()), Value::Str("supported_price_decimals".to_string()), &[]);
let mut amountPrecision: Value = ternary(is_true(&(is_equal(&amountDecimals, &Value::Null))), Value::Null, self.parse_number(self.parse_precision(&[amountDecimals.clone()]), &[]));
let mut pricePrecision: Value = ternary(is_true(&(is_equal(&priceDecimals, &Value::Null))), Value::Null, self.parse_number(self.parse_precision(&[priceDecimals.clone()]), &[]));
let mut quoteMultiplier: Value = self.safe_number_k(market.clone(), "quote_multiplier", &[]);
append_to_array(&mut result, Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), id.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(), Value::Bool(is_equal(&type_var, &Value::Str("spot".to_string()))));
m.insert("margin".to_string(), Value::Bool(false));
m.insert("swap".to_string(), Value::Bool(is_equal(&type_var, &Value::Str("swap".to_string()))));
m.insert("future".to_string(), Value::Bool(false));
m.insert("option".to_string(), Value::Bool(false));
m.insert("active".to_string(), Value::Bool(is_equal(&self.safe_string_k(market.clone(), "status", &[]), &Value::Str("active".to_string()))));
m.insert("contract".to_string(), Value::Bool(is_equal(&type_var, &Value::Str("swap".to_string()))));
m.insert("linear".to_string(), ternary(is_true(&(is_equal(&type_var, &Value::Str("swap".to_string())))), Value::Bool(true), Value::Null));
m.insert("inverse".to_string(), ternary(is_true(&(is_equal(&type_var, &Value::Str("swap".to_string())))), Value::Bool(false), Value::Null));
m.insert("taker".to_string(), self.safe_number_k(market.clone(), "taker_fee", &[]));
m.insert("maker".to_string(), self.safe_number_k(market.clone(), "maker_fee", &[]));
m.insert("contractSize".to_string(), quoteMultiplier.clone());
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(), amountPrecision.clone());
m.insert("price".to_string(), pricePrecision.clone());
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_base_amount", &[]));
m.insert("max".to_string(), Value::Null);
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_quote_amount", &[]));
m.insert("max".to_string(), self.safe_number_k(market.clone(), "order_quote_limit", &[]));
m
}));
m
}));
m.insert("created".to_string(), Value::Null);
m.insert("info".to_string(), market.clone());
m
}));
}
}
return result;
Value::Null
}
/*
* @method
* @name lighter#fetchCurrencies
* @description fetches all available currencies on an exchange
* @see https://apidocs.lighter.xyz/reference/assetdetails
* @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 response: Value = self.public_get_asset_details(&[params.clone()]).await;
if is_true(&self.check_required_credentials(&[Value::Bool(false)])) {
self.pre_load_lighter_library(&[]).await;
}
//
// {
// "code": 200,
// "asset_details": [
// {
// "asset_id": 3,
// "symbol": "USDC",
// "l1_decimals": 6,
// "decimals": 6,
// "min_transfer_amount": "1.000000",
// "min_withdrawal_amount": "1.000000",
// "margin_mode": "enabled",
// "index_price": "1.000000",
// "l1_address": "0x95Fd23d5110f9D89A4b0B7d63D78F5B5Ea5074D1"
// }
// ]
// }
//
let mut data: Value = self.safe_list_k(response.clone(), "asset_details", &[Value::List(vec![])]);
return self.parse_currencies(data.clone());
Value::Null
}
pub fn parse_currency(&self, mut rawCurrency: Value) -> Value {
let mut id: Value = self.safe_string_k(rawCurrency.clone(), "asset_id", &[]);
let mut code: Value = self.safe_currency_code(self.safe_string_k(rawCurrency.clone(), "symbol", &[]), &[]);
let mut decimals: Value = self.safe_string_k(rawCurrency.clone(), "decimals", &[]);
let mut isUSDC: Value = Value::Bool(is_equal(&code, &Value::Str("USDC".to_string())));
let mut depositMin: Value = Value::Null;
let mut withdrawMin: Value = Value::Null;
if is_true(&isUSDC) {
depositMin = self.safe_number_k(rawCurrency.clone(), "min_transfer_amount", &[]);
withdrawMin = self.safe_number_k(rawCurrency.clone(), "min_withdrawal_amount", &[]);
}
return self.safe_currency_structure(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), id.clone());
m.insert("name".to_string(), code.clone());
m.insert("code".to_string(), code.clone());
m.insert("precision".to_string(), self.parse_number(add(&Value::Str("1e-".to_string()), &decimals), &[]));
m.insert("active".to_string(), Value::Bool(true));
m.insert("fee".to_string(), Value::Null);
m.insert("networks".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
m.insert("deposit".to_string(), isUSDC.clone());
m.insert("withdraw".to_string(), isUSDC.clone());
m.insert("type".to_string(), Value::Str("crypto".to_string()));
m.insert("limits".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("deposit".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), depositMin.clone());
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(), withdrawMin.clone());
m.insert("max".to_string(), Value::Null);
m
}));
m
}));
m.insert("info".to_string(), rawCurrency.clone());
m
}));
Value::Null
}
/*
* @method
* @name lighter#fetchOrderBook
* @description fetches information on open orders with bid (buy) and ask (sell) prices, volumes and other data
* @see https://apidocs.lighter.xyz/reference/orderbookorders
* @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
* @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(&symbol, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" fetchOrderBook() requires a symbol argument".to_string()))));
}
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("market_id".to_string(), get_value(&market, &Value::Str("id".to_string())));
m.insert("limit".to_string(), Value::Int(100));
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(100)));
}
let __ws_arg_8 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.public_get_order_book_orders(&[__ws_arg_8]).await;
//
// {
// "code": 200,
// "total_asks": 1,
// "asks": [
// {
// "order_index": 281475565888172,
// "order_id": "281475565888172",
// "owner_account_index": 134436,
// "initial_base_amount": "0.2000",
// "remaining_base_amount": "0.2000",
// "price": "3430.00",
// "order_expiry": 1765419046808
// }
// ],
// "total_bids": 1,
// "bids": [
// {
// "order_index": 562949401225099,
// "order_id": "562949401225099",
// "owner_account_index": 314236,
// "initial_base_amount": "1.7361",
// "remaining_base_amount": "1.3237",
// "price": "3429.80",
// "order_expiry": 1765419047587
// }
// ]
// }
//
let mut result: Value = self.parse_order_book(response.clone(), get_value(&market, &Value::Str("symbol".to_string())), &[Value::Null, Value::Str("bids".to_string()), Value::Str("asks".to_string()), Value::Str("price".to_string()), Value::Str("remaining_base_amount".to_string())]);
return result;
Value::Null
}
pub fn parse_ticker(&self, mut ticker: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// fetchTicker, fetchTickers
// {
// "symbol": "ETH",
// "market_id": 0,
// "status": "active",
// "taker_fee": "0.0000",
// "maker_fee": "0.0000",
// "liquidation_fee": "1.0000",
// "min_base_amount": "0.0050",
// "min_quote_amount": "10.000000",
// "order_quote_limit": "",
// "supported_size_decimals": 4,
// "supported_price_decimals": 2,
// "supported_quote_decimals": 6,
// "size_decimals": 4,
// "price_decimals": 2,
// "quote_multiplier": 1,
// "default_initial_margin_fraction": 500,
// "min_initial_margin_fraction": 200,
// "maintenance_margin_fraction": 120,
// "closeout_margin_fraction": 80,
// "last_trade_price": 3550.69,
// "daily_trades_count": 1197349,
// "daily_base_token_volume": 481297.3509,
// "daily_quote_token_volume": 1671431095.263844,
// "daily_price_low": 3402.41,
// "daily_price_high": 3571.45,
// "daily_price_change": 0.5294300840859545,
// "open_interest": 39559.3278,
// "daily_chart": {},
// "market_config": {
// "market_margin_mode": 0,
// "insurance_fund_account_index": 281474976710654,
// "liquidation_mode": 0,
// "force_reduce_only": false,
// "trading_hours": ""
// }
// }
//
// watchTicker, watchTickers
// {
// "market_id": 0,
// "index_price": "3015.56",
// "mark_price": "3013.91",
// "open_interest": "122736286.659423",
// "open_interest_limit": "72057594037927936.000000",
// "funding_clamp_small": "0.0500",
// "funding_clamp_big": "4.0000",
// "last_trade_price": "3013.13",
// "current_funding_rate": "0.0012",
// "funding_rate": "0.0012",
// "funding_timestamp": 1763532000004,
// "daily_base_token_volume": 643235.2763,
// "daily_quote_token_volume": 1983505435.673896,
// "daily_price_low": 2977.42,
// "daily_price_high": 3170.81,
// "daily_price_change": -0.3061987051035322
// }
//
let mut marketId: Value = self.safe_string_k(ticker.clone(), "market_id", &[]);
market = self.safe_market(&[marketId.clone(), market.clone()]);
let mut symbol: Value = get_value(&market, &Value::Str("symbol".to_string()));
let mut last: Value = self.safe_string_k(ticker.clone(), "last_trade_price", &[]);
let mut high: Value = self.safe_string_k(ticker.clone(), "daily_price_high", &[]);
let mut low: Value = self.safe_string_k(ticker.clone(), "daily_price_low", &[]);
let mut baseVolume: Value = self.safe_string_k(ticker.clone(), "daily_base_token_volume", &[]);
let mut quoteVolume: Value = self.safe_string_k(ticker.clone(), "daily_quote_token_volume", &[]);
let mut change: Value = self.safe_string_k(ticker.clone(), "daily_price_change", &[]);
let mut openInterest: Value = self.safe_string_k(ticker.clone(), "open_interest", &[]);
return self.safe_ticker(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), symbol.clone());
m.insert("timestamp".to_string(), Value::Null);
m.insert("datetime".to_string(), Value::Null);
m.insert("high".to_string(), high.clone());
m.insert("low".to_string(), low.clone());
m.insert("bid".to_string(), Value::Null);
m.insert("bidVolume".to_string(), Value::Null);
m.insert("ask".to_string(), Value::Null);
m.insert("askVolume".to_string(), Value::Null);
m.insert("vwap".to_string(), Value::Null);
m.insert("open".to_string(), Value::Null);
m.insert("close".to_string(), last.clone());
m.insert("last".to_string(), last.clone());
m.insert("previousClose".to_string(), Value::Null);
m.insert("change".to_string(), Value::Null);
m.insert("percentage".to_string(), change.clone());
m.insert("average".to_string(), Value::Null);
m.insert("baseVolume".to_string(), baseVolume.clone());
m.insert("quoteVolume".to_string(), quoteVolume.clone());
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("openInterest".to_string(), openInterest.clone());
m.insert("info".to_string(), ticker.clone());
m
}), &[market.clone()]);
Value::Null
}
/*
* @method
* @name lighter#fetchTicker
* @description fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
* @see https://apidocs.lighter.xyz/reference/orderbookdetails
* @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(&symbol, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" fetchTicker() requires a symbol argument".to_string()))));
}
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("market_id".to_string(), get_value(&market, &Value::Str("id".to_string())));
m
});
let __ws_arg_9 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.public_get_order_book_details(&[__ws_arg_9]).await;
//
// {
// "code": 200,
// "order_book_details": [
// {
// "symbol": "ETH",
// "market_id": 0,
// "status": "active",
// "taker_fee": "0.0000",
// "maker_fee": "0.0000",
// "liquidation_fee": "1.0000",
// "min_base_amount": "0.0050",
// "min_quote_amount": "10.000000",
// "order_quote_limit": "",
// "supported_size_decimals": 4,
// "supported_price_decimals": 2,
// "supported_quote_decimals": 6,
// "size_decimals": 4,
// "price_decimals": 2,
// "quote_multiplier": 1,
// "default_initial_margin_fraction": 500,
// "min_initial_margin_fraction": 200,
// "maintenance_margin_fraction": 120,
// "closeout_margin_fraction": 80,
// "last_trade_price": 3550.69,
// "daily_trades_count": 1197349,
// "daily_base_token_volume": 481297.3509,
// "daily_quote_token_volume": 1671431095.263844,
// "daily_price_low": 3402.41,
// "daily_price_high": 3571.45,
// "daily_price_change": 0.5294300840859545,
// "open_interest": 39559.3278,
// "daily_chart": {},
// "market_config": {
// "market_margin_mode": 0,
// "insurance_fund_account_index": 281474976710655,
// "liquidation_mode": 0,
// "force_reduce_only": false,
// "trading_hours": ""
// }
// }
// ]
// }
//
let mut spotTickers: Value = self.safe_list_k(response.clone(), "spot_order_book_details", &[Value::List(vec![])]);
let mut swapTickers: Value = self.safe_list_k(response.clone(), "order_book_details", &[Value::List(vec![])]);
let mut tickers: Value = self.array_concat(spotTickers.clone(), swapTickers.clone());
let mut first: Value = self.safe_dict(tickers.clone(), Value::Int(0), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_ticker(first.clone(), &[market.clone()]);
Value::Null
}
/*
* @method
* @name lighter#fetchTickers
* @description fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market
* @see https://apidocs.lighter.xyz/reference/orderbookdetails
* @param {string[]|undefined} symbols unified symbols of the markets to fetch the ticker for, all market tickers are returned if not assigned
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a dictionary of [ticker structures]{@link https://docs.ccxt.com/?id=ticker-structure}
*/
pub async fn fetch_tickers(&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
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
symbols = self.market_symbols(&[symbols.clone()]);
let mut response: Value = self.public_get_order_book_details(&[params.clone()]).await;
let mut spotTickers: Value = self.safe_list_k(response.clone(), "spot_order_book_details", &[Value::List(vec![])]);
let mut swapTickers: Value = self.safe_list_k(response.clone(), "order_book_details", &[Value::List(vec![])]);
let mut tickers: Value = self.array_concat(spotTickers.clone(), swapTickers.clone());
return self.parse_tickers(tickers.clone(), &[symbols.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_k(ohlcv.clone(), "t", &[]), self.safe_number_k(ohlcv.clone(), "o", &[]), self.safe_number_k(ohlcv.clone(), "h", &[]), self.safe_number_k(ohlcv.clone(), "l", &[]), self.safe_number_k(ohlcv.clone(), "c", &[]), self.safe_number_k(ohlcv.clone(), "v", &[])]);
Value::Null
}
/*
* @method
* @name lighter#fetchOHLCV
* @description fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market
* @see https://apidocs.lighter.xyz/reference/candles
* @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 candle to fetch
* @param {int} [limit] the maximum amount of candles to fetch
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {int} [params.until] timestamp in ms of the latest candle to fetch
* @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("1h".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
}));
if is_equal(&symbol, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" fetchOHLCV() requires a symbol argument".to_string()))));
}
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut until: Value = self.safe_integer_k(params.clone(), "until", &[]);
params = self.omit(params.clone(), Value::List(vec![Value::Str("until".to_string())]), &[]);
let mut now: Value = self.milliseconds();
let mut startTs: Value = Value::Null;
let mut endTs: Value = Value::Null;
if !is_equal(&since, &Value::Null) {
startTs = since.clone();
if !is_equal(&until, &Value::Null) {
endTs = until.clone();
} else if !is_equal(&limit, &Value::Null) {
let mut duration: Value = self.parse_timeframe(timeframe.clone());
endTs = self.sum(&[since.clone(), multiply(&multiply(&duration, &limit), &Value::Int(1000))]);
} else {
endTs = now.clone();
}
} else {
endTs = ternary(is_true(&(!is_equal(&until, &Value::Null))), until.clone(), now.clone());
let mut defaultLimit: Value = Value::Int(100);
if !is_equal(&limit, &Value::Null) {
startTs = subtract(&endTs, &multiply(&multiply(&self.parse_timeframe(timeframe.clone()), &Value::Int(1000)), &limit));
} else {
startTs = subtract(&endTs, &multiply(&multiply(&self.parse_timeframe(timeframe.clone()), &Value::Int(1000)), &defaultLimit));
}
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("market_id".to_string(), get_value(&market, &Value::Str("id".to_string())));
m.insert("count_back".to_string(), Value::Int(0));
m.insert("resolution".to_string(), self.safe_string(self.timeframes.clone(), timeframe.clone(), &[timeframe.clone()]));
m.insert("start_timestamp".to_string(), startTs.clone());
m.insert("end_timestamp".to_string(), endTs.clone());
m
});
let __ws_arg_10 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.public_get_candles(&[__ws_arg_10]).await;
//
// {
// "code": 200,
// "r": "1m",
// "c": [
// {
// "t": 1767700500000,
// "o": 3236.86,
// "h": 3237.78,
// "l": 3235.36,
// "c": 3235.39,
// "v": 55.1632,
// "V": 178530.793575,
// "i": 779870452,
// "C": "string",
// "H": "string",
// "L": "string",
// "O": "string"
// }
// ]
// }
//
let mut ohlcvs: Value = self.safe_list_k(response.clone(), "c", &[Value::List(vec![])]);
return self.parse_ohlc_vs(ohlcvs.clone(), &[market.clone(), timeframe.clone(), since.clone(), limit.clone()]);
Value::Null
}
pub fn parse_funding_rate(&self, mut contract: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// {
// "market_id": 0,
// "exchange": "lighter",
// "symbol": "ETH",
// "rate": 0.00009599999999999999
// }
//
let mut marketId: Value = self.safe_string_k(contract.clone(), "market_id", &[]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), contract.clone());
m.insert("symbol".to_string(), self.safe_symbol(marketId.clone(), &[market.clone()]));
m.insert("markPrice".to_string(), Value::Null);
m.insert("indexPrice".to_string(), Value::Null);
m.insert("interestRate".to_string(), Value::Null);
m.insert("estimatedSettlePrice".to_string(), Value::Null);
m.insert("timestamp".to_string(), Value::Null);
m.insert("datetime".to_string(), Value::Null);
m.insert("fundingRate".to_string(), self.safe_number_k(contract.clone(), "rate", &[]));
m.insert("fundingTimestamp".to_string(), Value::Null);
m.insert("fundingDatetime".to_string(), Value::Null);
m.insert("nextFundingRate".to_string(), Value::Null);
m.insert("nextFundingTimestamp".to_string(), Value::Null);
m.insert("nextFundingDatetime".to_string(), Value::Null);
m.insert("previousFundingRate".to_string(), Value::Null);
m.insert("previousFundingTimestamp".to_string(), Value::Null);
m.insert("previousFundingDatetime".to_string(), Value::Null);
m.insert("interval".to_string(), Value::Null);
m
});
Value::Null
}
/*
* @method
* @name lighter#fetchFundingRates
* @description fetch the current funding rate for multiple symbols
* @see https://apidocs.lighter.xyz/reference/funding-rates
* @param {string[]} [symbols] list of unified market symbols
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object[]} a list of [funding rate structures]{@link https://docs.ccxt.com/?id=funding-rate-structure}
*/
pub async fn fetch_funding_rates(&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
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let __ws_arg_11 = self.extend(params.clone(), &[]);
let mut response: Value = self.public_get_funding_rates(&[__ws_arg_11]).await;
//
// {
// "code": 200,
// "funding_rates": [
// {
// "market_id": 0,
// "exchange": "lighter",
// "symbol": "ETH",
// "rate": 0.00009599999999999999
// }
// ]
// }
//
let mut data: Value = self.safe_list_k(response.clone(), "funding_rates", &[Value::List(vec![])]);
let mut result: Value = Value::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_919: bool = true;
while { if !__for_first_919 { i = add(&i, &Value::Int(1)); } __for_first_919 = false; is_less_than(&i, &get_array_length(&data)) } {
let mut exchange: Value = self.safe_string_k(get_value(&data, &i), "exchange", &[]);
if is_equal(&exchange, &Value::Str("lighter".to_string())) {
append_to_array(&mut result, get_value(&data, &i));
}
}
}
return self.parse_funding_rates(result.clone(), &[symbols.clone()]);
Value::Null
}
/*
* @method
* @name ligher#fetchBalance
* @description query for balance and get the amount of funds available for trading or funds locked in orders
* @see https://apidocs.lighter.xyz/reference/account-1
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.by] fetch balance by 'index' or 'l1_address', defaults to 'index'
* @param {string} [params.value] fetch balance value, account index or l1 address
* @param {string} [params.type] 'spot', 'swap', default is 'swap'
* @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
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut accountIndex: Value = Value::Null;
{ let __destr_tmp = self.handle_account_index(params.clone(), Value::Str("fetchBalance".to_string()), Value::Str("accountIndex".to_string()), Value::Str("account_index".to_string()), &[]).await; accountIndex = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut defaultType: Value = self.safe_string2(self.options.clone(), Value::Str("fetchBalance".to_string()), Value::Str("defaultType".to_string()), &[Value::Str("spot".to_string())]);
let mut type_var: Value = self.safe_string_k(params.clone(), "type", &[defaultType.clone()]);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("by".to_string(), self.safe_string_k(params.clone(), "by", &[Value::Str("index".to_string())]));
m.insert("value".to_string(), accountIndex.clone());
m
});
let __ws_arg_12 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.public_get_account(&[__ws_arg_12]).await;
//
// {
// "code": "200",
// "total": "1",
// "accounts": [
// {
// "code": "0",
// "account_type": "0",
// "index": "1077",
// "l1_address": "0x15f43D1f2DeE81424aFd891943262aa90F22cc2A",
// "cancel_all_time": "0",
// "total_order_count": "1",
// "total_isolated_order_count": "0",
// "pending_order_count": "0",
// "available_balance": "7996.489834",
// "status": "1",
// "collateral": "9000.000000",
// "account_index": "1077",
// "name": "",
// "description": "",
// "can_invite": true,
// "referral_points_percentage": "",
// "positions": [],
// "assets": [
// {
// "symbol": "ETH",
// "asset_id": "1",
// "balance": "3.00000000",
// "locked_balance": "0.00000000"
// },
// {
// "symbol": "USDC",
// "asset_id": "3",
// "balance": "1000.000000",
// "locked_balance": "0.000000"
// }
// ],
// "total_asset_value": "9536.789088",
// "cross_asset_value": "9536.789088",
// "shares": []
// }
// ]
// }
//
let mut result: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), response.clone());
m
});
let mut accounts: Value = self.safe_list_k(response.clone(), "accounts", &[Value::List(vec![])]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_921: bool = true;
while { if !__for_first_921 { i = add(&i, &Value::Int(1)); } __for_first_921 = false; is_less_than(&i, &get_array_length(&accounts)) } {
let mut account: Value = get_value(&accounts, &i);
let mut account: Value = get_value(&accounts, &i);
if is_equal(&type_var, &Value::Str("spot".to_string())) {
let mut assets: Value = self.safe_list_k(account.clone(), "assets", &[Value::List(vec![])]);
{
let mut j: Value = Value::Int(0);
let mut __for_first_920: bool = true;
while { if !__for_first_920 { j = add(&j, &Value::Int(1)); } __for_first_920 = false; is_less_than(&j, &get_array_length(&assets)) } {
let mut asset: Value = get_value(&assets, &j);
let mut asset: Value = get_value(&assets, &j);
let mut codeId: Value = self.safe_string_k(asset.clone(), "symbol", &[]);
let mut code: Value = self.safe_currency_code(codeId.clone(), &[]);
let mut balance: Value = self.safe_dict(result.clone(), code.clone(), &[self.account()]);
{ let __be_tmp = crate::precise::Precise::stringAdd(&get_value(&balance, &Value::Str("total".to_string())), &self.safe_string_k(asset.clone(), "balance", &[])); add_element_to_object(&mut balance, &Value::Str("total".to_string()), __be_tmp); };
{ let __be_tmp = crate::precise::Precise::stringAdd(&get_value(&balance, &Value::Str("used".to_string())), &self.safe_string_k(asset.clone(), "locked_balance", &[])); add_element_to_object(&mut balance, &Value::Str("used".to_string()), __be_tmp); };
if !is_equal(&code, &Value::Null) {
add_element_to_object(&mut result, &code, balance.clone());
}
}
}
} else {
let mut perpBalance: Value = self.safe_dict_k(result.clone(), "USDC", &[self.account()]);
let mut perpTotal: Value = self.safe_string_k(perpBalance.clone(), "total", &[Value::Str("0".to_string())]);
let mut perpFree: Value = self.safe_string_k(perpBalance.clone(), "free", &[Value::Str("0".to_string())]);
let mut perpUSDCTotal: Value = self.safe_string_k(account.clone(), "collateral", &[Value::Str("0".to_string())]);
let mut perpUSDCFree: Value = self.safe_string_k(account.clone(), "available_balance", &[Value::Str("0".to_string())]);
add_element_to_object(&mut perpBalance, &Value::Str("total".to_string()), crate::precise::Precise::stringAdd(&perpTotal, &perpUSDCTotal));
add_element_to_object(&mut perpBalance, &Value::Str("free".to_string()), crate::precise::Precise::stringAdd(&perpFree, &perpUSDCFree));
add_element_to_object(&mut result, &Value::Str("USDC".to_string()), perpBalance.clone());
}
}
}
return self.safe_balance(result.clone());
Value::Null
}
/*
* @method
* @name lighter#fetchPosition
* @description fetch data on an open position
* @see https://apidocs.lighter.xyz/reference/account-1
* @param {string} symbol unified market symbol of the market the position is held in
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.by] fetch balance by 'index' or 'l1_address', defaults to 'index'
* @param {string} [params.value] fetch balance value, account index or l1 address
* @returns {object} a [position structure]{@link https://docs.ccxt.com/?id=position-structure}
*/
pub async fn fetch_position(&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
}));
let mut positions: Value = self.fetch_positions(&[Value::List(vec![symbol.clone()]), params.clone()]).await;
return self.safe_dict(positions.clone(), Value::Int(0), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
Value::Null
}
/*
* @method
* @name lighter#fetchPositions
* @description fetch all open positions
* @see https://apidocs.lighter.xyz/reference/account-1
* @param {string[]} [symbols] list of unified market symbols
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.by] fetch balance by 'index' or 'l1_address', defaults to 'index'
* @param {string} [params.value] fetch balance value, account index or l1 address
* @returns {object[]} a list of [position structure]{@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
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut accountIndex: Value = Value::Null;
{ let __destr_tmp = self.handle_account_index(params.clone(), Value::Str("fetchPositions".to_string()), Value::Str("accountIndex".to_string()), Value::Str("account_index".to_string()), &[]).await; accountIndex = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("by".to_string(), self.safe_string_k(params.clone(), "by", &[Value::Str("index".to_string())]));
m.insert("value".to_string(), accountIndex.clone());
m
});
let __ws_arg_13 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.public_get_account(&[__ws_arg_13]).await;
//
// {
// "code": 200,
// "total": 2,
// "accounts": [
// {
// "code": 0,
// "account_type": 0,
// "index": 1077,
// "l1_address": "0x15f43D1f2DeE81424aFd891943262aa90F22cc2A",
// "cancel_all_time": 0,
// "total_order_count": 0,
// "total_isolated_order_count": 0,
// "pending_order_count": 0,
// "available_balance": "12582.743947",
// "status": 1,
// "collateral": "9100.242706",
// "account_index": 1077,
// "name": "",
// "description": "",
// "can_invite": true,
// "referral_points_percentage": "",
// "positions": [
// {
// "market_id": 0,
// "symbol": "ETH",
// "initial_margin_fraction": "5.00",
// "open_order_count": 0,
// "pending_order_count": 0,
// "position_tied_order_count": 0,
// "sign": 1,
// "position": "18.0193",
// "avg_entry_price": "2669.84",
// "position_value": "54306.566340",
// "unrealized_pnl": "6197.829558",
// "realized_pnl": "0.000000",
// "liquidation_price": "2191.1107231380406",
// "margin_mode": 0,
// "allocated_margin": "0.000000"
// }
// ],
// "assets": [],
// "total_asset_value": "15298.072264000002",
// "cross_asset_value": "15298.072264000002",
// "shares": []
// }
// ]
// }
//
let mut allPositions: Value = Value::List(vec![]);
let mut accounts: Value = self.safe_list_k(response.clone(), "accounts", &[Value::List(vec![])]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_923: bool = true;
while { if !__for_first_923 { i = add(&i, &Value::Int(1)); } __for_first_923 = false; is_less_than(&i, &get_array_length(&accounts)) } {
let mut account: Value = get_value(&accounts, &i);
let mut account: Value = get_value(&accounts, &i);
let mut positions: Value = self.safe_list_k(account.clone(), "positions", &[Value::List(vec![])]);
{
let mut j: Value = Value::Int(0);
let mut __for_first_922: bool = true;
while { if !__for_first_922 { j = add(&j, &Value::Int(1)); } __for_first_922 = false; is_less_than(&j, &get_array_length(&positions)) } {
append_to_array(&mut allPositions, get_value(&positions, &j));
}
}
}
}
return self.parse_positions(allPositions.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);
//
// {
// "market_id": 0,
// "symbol": "ETH",
// "initial_margin_fraction": "5.00",
// "open_order_count": 0,
// "pending_order_count": 0,
// "position_tied_order_count": 0,
// "sign": 1,
// "position": "18.0193",
// "avg_entry_price": "2669.84",
// "position_value": "54306.566340",
// "unrealized_pnl": "6197.829558",
// "realized_pnl": "0.000000",
// "liquidation_price": "2191.1107231380406",
// "margin_mode": 0,
// "allocated_margin": "0.000000"
// }
//
let mut marketId: Value = self.safe_string_k(position.clone(), "market_id", &[]);
market = self.safe_market(&[marketId.clone(), market.clone()]);
let mut sign: Value = self.safe_integer_k(position.clone(), "sign", &[]);
let mut side: Value = Value::Null;
if !is_equal(&sign, &Value::Null) {
side = ternary(is_true(&(is_equal(&sign, &Value::Int(1)))), Value::Str("long".to_string()), Value::Str("short".to_string()));
}
let mut marginModeId: Value = self.safe_integer_k(position.clone(), "margin_mode", &[]);
let mut marginMode: Value = Value::Null;
if !is_equal(&marginModeId, &Value::Null) {
marginMode = ternary(is_true(&(is_equal(&marginModeId, &Value::Int(0)))), Value::Str("cross".to_string()), Value::Str("isolated".to_string()));
}
let mut imfStr: Value = self.safe_string_k(position.clone(), "initial_margin_fraction", &[]);
let mut leverage: Value = Value::Null;
if !is_equal(&imfStr, &Value::Null) {
let mut imf: Value = self.parse_to_int(imfStr.clone());
if is_greater_than(&imf, &Value::Int(0)) {
leverage = divide(&Value::Int(100), &imf);
}
}
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(), get_value(&market, &Value::Str("symbol".to_string())));
m.insert("timestamp".to_string(), Value::Null);
m.insert("datetime".to_string(), Value::Null);
m.insert("isolated".to_string(), Value::Bool((is_equal(&marginMode, &Value::Str("isolated".to_string())))));
m.insert("hedged".to_string(), Value::Null);
m.insert("side".to_string(), side.clone());
m.insert("contracts".to_string(), self.safe_number_k(position.clone(), "position", &[]));
m.insert("contractSize".to_string(), Value::Null);
m.insert("entryPrice".to_string(), self.safe_number_k(position.clone(), "avg_entry_price", &[]));
m.insert("markPrice".to_string(), Value::Null);
m.insert("notional".to_string(), self.safe_number_k(position.clone(), "position_value", &[]));
m.insert("leverage".to_string(), leverage.clone());
m.insert("collateral".to_string(), self.safe_number_k(position.clone(), "allocated_margin", &[]));
m.insert("initialMargin".to_string(), Value::Null);
m.insert("maintenanceMargin".to_string(), Value::Null);
m.insert("initialMarginPercentage".to_string(), Value::Null);
m.insert("maintenanceMarginPercentage".to_string(), Value::Null);
m.insert("unrealizedPnl".to_string(), self.safe_number_k(position.clone(), "unrealized_pnl", &[]));
m.insert("liquidationPrice".to_string(), self.safe_number_k(position.clone(), "liquidation_price", &[]));
m.insert("marginMode".to_string(), marginMode.clone());
m.insert("percentage".to_string(), Value::Null);
m
}));
Value::Null
}
/*
* @method
* @name lighter#fetchAccounts
* @description fetch all the accounts associated with a profile
* @see https://apidocs.lighter.xyz/reference/account-1
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.by] fetch balance by 'index' or 'l1_address', defaults to 'index'
* @param {string} [params.value] fetch balance value, account index or l1 address
* @returns {object} a dictionary of [account structures]{@link https://docs.ccxt.com/?id=accounts-structure} indexed by the account type
*/
pub async fn fetch_accounts(&mut self, 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 accountIndex: Value = Value::Null;
{ let __destr_tmp = self.handle_account_index(params.clone(), Value::Str("fetchAccounts".to_string()), Value::Str("accountIndex".to_string()), Value::Str("account_index".to_string()), &[]).await; accountIndex = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("by".to_string(), self.safe_string_k(params.clone(), "by", &[Value::Str("index".to_string())]));
m.insert("value".to_string(), accountIndex.clone());
m
});
let __ws_arg_14 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.public_get_account(&[__ws_arg_14]).await;
//
// {
// "code": "200",
// "total": "1",
// "accounts": [
// {
// "code": "0",
// "account_type": "0",
// "index": "1077",
// "l1_address": "0x15f43D1f2DeE81424aFd891943262aa90F22cc2A",
// "cancel_all_time": "0",
// "total_order_count": "1",
// "total_isolated_order_count": "0",
// "pending_order_count": "0",
// "available_balance": "7996.489834",
// "status": "1",
// "collateral": "9000.000000",
// "account_index": "1077",
// "name": "",
// "description": "",
// "can_invite": true,
// "referral_points_percentage": "",
// "positions": [],
// "assets": [],
// "total_asset_value": "9536.789088",
// "cross_asset_value": "9536.789088",
// "shares": []
// }
// ]
// }
//
let mut accounts: Value = self.safe_list_k(response.clone(), "accounts", &[Value::List(vec![])]);
return self.parse_accounts(accounts.clone(), &[params.clone()]);
Value::Null
}
pub fn parse_account(&self, mut account: Value) -> Value {
//
// {
// "code": "0",
// "account_type": "0",
// "index": "1077",
// "l1_address": "0x15f43D1f2DeE81424aFd891943262aa90F22cc2A",
// "cancel_all_time": "0",
// "total_order_count": "1",
// "total_isolated_order_count": "0",
// "pending_order_count": "0",
// "available_balance": "7996.489834",
// "status": "1",
// "collateral": "9000.000000",
// "account_index": "1077",
// "name": "",
// "description": "",
// "can_invite": true,
// "referral_points_percentage": "",
// "positions": [],
// "assets": [],
// "total_asset_value": "9536.789088",
// "cross_asset_value": "9536.789088",
// "shares": []
// }
//
let mut accountType: Value = self.safe_string_k(account.clone(), "account_type", &[]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), self.safe_string_k(account.clone(), "account_index", &[]));
m.insert("type".to_string(), ternary(is_true(&(is_equal(&accountType, &Value::Str("0".to_string())))), Value::Str("main".to_string()), Value::Str("subaccount".to_string())));
m.insert("code".to_string(), Value::Null);
m.insert("info".to_string(), account.clone());
m
});
Value::Null
}
/*
* @method
* @name lighter#fetchOpenOrders
* @description fetch all unfilled currently open orders
* @see https://apidocs.lighter.xyz/reference/accountactiveorders
* @param {string} symbol unified market symbol
* @param {int} [since] the earliest time in ms to fetch open orders for
* @param {int} [limit] the maximum number of open orders structures to retrieve
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.accountIndex] account index
* @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
}));
if is_equal(&symbol, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" fetchOpenOrders() requires a symbol argument".to_string()))));
}
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut accountIndex: Value = Value::Null;
{ let __destr_tmp = self.handle_account_index(params.clone(), Value::Str("fetchOpenOrders".to_string()), Value::Str("accountIndex".to_string()), Value::Str("account_index".to_string()), &[]).await; accountIndex = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut apiKeyIndex: Value = Value::Null;
{ let __destr_tmp = self.handle_api_key_index(params.clone(), Value::Str("fetchOpenOrders".to_string()), Value::Str("apiKeyIndex".to_string()), Value::Str("api_key_index".to_string()), &[]); apiKeyIndex = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut strAccountIndex: Value = self.number_to_string(accountIndex.clone());
let mut strApiKeyIndex: Value = self.number_to_string(apiKeyIndex.clone());
self.load_account(get_value(&self.options, &Value::Str("chainId".to_string())), self.get_lighter_private_key(strAccountIndex.clone(), strApiKeyIndex.clone()), strApiKeyIndex.clone(), strAccountIndex.clone(), &[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("market_id".to_string(), get_value(&market, &Value::Str("id".to_string())));
m.insert("account_index".to_string(), accountIndex.clone());
m
});
let __ws_arg_15 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_get_account_active_orders(&[__ws_arg_15]).await;
//
// {
// "code": 200,
// "orders": [
// {
// "order_index": 281474977354074,
// "client_order_index": 0,
// "order_id": "281474977354074",
// "client_order_id": "0",
// "market_index": 0,
// "owner_account_index": 1077,
// "initial_base_amount": "36.0386",
// "price": "2221.60",
// "nonce": 643418,
// "remaining_base_amount": "0.0000",
// "is_ask": true,
// "base_size": 0,
// "base_price": 222160,
// "filled_base_amount": "0.0000",
// "filled_quote_amount": "0.000000",
// "side": "",
// "type": "market",
// "time_in_force": "immediate-or-cancel",
// "reduce_only": false,
// "trigger_price": "0.00",
// "order_expiry": 0,
// "status": "canceled-margin-not-allowed",
// "trigger_status": "na",
// "trigger_time": 0,
// "parent_order_index": 0,
// "parent_order_id": "0",
// "to_trigger_order_id_0": "0",
// "to_trigger_order_id_1": "0",
// "to_cancel_order_id_0": "0",
// "block_height": 102202,
// "timestamp": 1766387932,
// "created_at": 1766387932,
// "updated_at": 1766387932
// }
// ]
// }
//
let mut data: Value = self.safe_list_k(response.clone(), "orders", &[Value::List(vec![])]);
return self.parse_orders(data.clone(), &[market.clone(), since.clone(), limit.clone()]);
Value::Null
}
/*
* @method
* @name lighter#fetchClosedOrders
* @description fetch all unfilled currently closed orders
* @see https://apidocs.lighter.xyz/reference/accountinactiveorders
* @param {string} symbol unified market symbol
* @param {int} [since] the earliest time in ms to fetch open orders for
* @param {int} [limit] the maximum number of open orders structures to retrieve
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.accountIndex] account index
* @returns {Order[]} a list of [order structures]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn fetch_closed_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
}));
if is_equal(&symbol, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" fetchClosedOrders() requires a symbol argument".to_string()))));
}
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut accountIndex: Value = Value::Null;
{ let __destr_tmp = self.handle_account_index(params.clone(), Value::Str("fetchClosedOrders".to_string()), Value::Str("accountIndex".to_string()), Value::Str("account_index".to_string()), &[]).await; accountIndex = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut apiKeyIndex: Value = Value::Null;
{ let __destr_tmp = self.handle_api_key_index(params.clone(), Value::Str("fetchClosedOrders".to_string()), Value::Str("apiKeyIndex".to_string()), Value::Str("api_key_index".to_string()), &[]); apiKeyIndex = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut strAccountIndex: Value = self.number_to_string(accountIndex.clone());
let mut strApiKeyIndex: Value = self.number_to_string(apiKeyIndex.clone());
self.load_account(get_value(&self.options, &Value::Str("chainId".to_string())), self.get_lighter_private_key(strAccountIndex.clone(), strApiKeyIndex.clone()), strApiKeyIndex.clone(), strAccountIndex.clone(), &[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("market_id".to_string(), get_value(&market, &Value::Str("id".to_string())));
m.insert("account_index".to_string(), accountIndex.clone());
m.insert("limit".to_string(), Value::Int(100));
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(100)));
}
let __ws_arg_16 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_get_account_inactive_orders(&[__ws_arg_16]).await;
//
// {
// "code": 200,
// "orders": [
// {
// "order_index": 281474977354074,
// "client_order_index": 0,
// "order_id": "281474977354074",
// "client_order_id": "0",
// "market_index": 0,
// "owner_account_index": 1077,
// "initial_base_amount": "36.0386",
// "price": "2221.60",
// "nonce": 643418,
// "remaining_base_amount": "0.0000",
// "is_ask": true,
// "base_size": 0,
// "base_price": 222160,
// "filled_base_amount": "0.0000",
// "filled_quote_amount": "0.000000",
// "side": "",
// "type": "market",
// "time_in_force": "immediate-or-cancel",
// "reduce_only": false,
// "trigger_price": "0.00",
// "order_expiry": 0,
// "status": "canceled-margin-not-allowed",
// "trigger_status": "na",
// "trigger_time": 0,
// "parent_order_index": 0,
// "parent_order_id": "0",
// "to_trigger_order_id_0": "0",
// "to_trigger_order_id_1": "0",
// "to_cancel_order_id_0": "0",
// "block_height": 102202,
// "timestamp": 1766387932,
// "created_at": 1766387932,
// "updated_at": 1766387932
// }
// ]
// }
//
let mut data: Value = self.safe_list_k(response.clone(), "orders", &[Value::List(vec![])]);
return self.parse_orders(data.clone(), &[market.clone(), since.clone(), limit.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);
//
// {
// "order_index": 281474977354074,
// "client_order_index": 0,
// "order_id": "281474977354074",
// "client_order_id": "0",
// "market_index": 0,
// "owner_account_index": 1077,
// "initial_base_amount": "36.0386",
// "price": "2221.60",
// "nonce": 643418,
// "remaining_base_amount": "0.0000",
// "is_ask": true,
// "base_size": 0,
// "base_price": 222160,
// "filled_base_amount": "0.0000",
// "filled_quote_amount": "0.000000",
// "side": "",
// "type": "market",
// "time_in_force": "immediate-or-cancel",
// "reduce_only": false,
// "trigger_price": "0.00",
// "order_expiry": 0,
// "status": "canceled-margin-not-allowed",
// "trigger_status": "na",
// "trigger_time": 0,
// "parent_order_index": 0,
// "parent_order_id": "0",
// "to_trigger_order_id_0": "0",
// "to_trigger_order_id_1": "0",
// "to_cancel_order_id_0": "0",
// "block_height": 102202,
// "timestamp": 1766387932,
// "created_at": 1766387932,
// "updated_at": 1766387932
// }
//
let mut marketId: Value = self.safe_string_k(order.clone(), "market_index", &[]);
market = self.safe_market(&[marketId.clone(), market.clone()]);
let mut timestamp: Value = self.safe_timestamp(order.clone(), Value::Str("timestamp".to_string()), &[]);
let mut isAsk: Value = self.safe_bool_k(order.clone(), "is_ask", &[]);
if is_equal(&isAsk, &Value::Null) {
let mut isAskAsInteger: Value = self.safe_integer_k(order.clone(), "is_ask", &[]);
if !is_equal(&isAskAsInteger, &Value::Null) {
isAsk = Value::Bool(is_equal(&isAskAsInteger, &Value::Int(1)));
}
}
let mut side: Value = Value::Null;
if !is_equal(&isAsk, &Value::Null) {
side = ternary(is_true(&isAsk), Value::Str("sell".to_string()), Value::Str("buy".to_string()));
}
let mut type_var: Value = self.safe_string_k(order.clone(), "type", &[]);
if is_equal(&type_var, &Value::Null) {
let mut typeAsInteger: Value = self.safe_integer_k(order.clone(), "order_type", &[]);
type_var = self.parse_order_type_integer(typeAsInteger.clone());
}
let mut triggerPrice: Value = self.parse_number(self.omit_zero(self.safe_string_k(order.clone(), "trigger_price", &[])), &[]);
let mut stopLossPrice: Value = Value::Null;
let mut takeProfitPrice: Value = Value::Null;
if !is_equal(&type_var, &Value::Null) {
if is_greater_than_or_equal(&get_index_of(&type_var, &Value::Str("stop-loss".to_string())), &Value::Int(0)) {
stopLossPrice = triggerPrice.clone();
}
if is_greater_than_or_equal(&get_index_of(&type_var, &Value::Str("take-profit".to_string())), &Value::Int(0)) {
takeProfitPrice = triggerPrice.clone();
}
}
// Try to parse to integer first, because parsing an integer to a string wouldn't result in undefined
let mut tif: Value = Value::Null;
let mut tifAsInteger: Value = self.safe_integer_k(order.clone(), "time_in_force", &[]);
if !is_equal(&tifAsInteger, &Value::Null) {
tif = self.parse_order_time_in_force_integer(tifAsInteger.clone());
} else {
tif = self.safe_string_k(order.clone(), "time_in_force", &[]);
}
let mut reduceOnly: Value = self.safe_bool_k(order.clone(), "reduce_only", &[]);
if is_equal(&reduceOnly, &Value::Null) {
let mut reduceOnlyAsInteger: Value = self.safe_integer_k(order.clone(), "reduce_only", &[]);
if !is_equal(&reduceOnlyAsInteger, &Value::Null) {
reduceOnly = Value::Bool(is_equal(&reduceOnlyAsInteger, &Value::Int(1)));
}
}
let mut status: Value = self.safe_string_k(order.clone(), "status", &[]);
return self.safe_order(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), order.clone());
m.insert("id".to_string(), self.safe_string_k(order.clone(), "order_id", &[]));
m.insert("clientOrderId".to_string(), self.omit_zero(self.safe_string2(order.clone(), Value::Str("client_order_id".to_string()), Value::Str("client_order_index".to_string()), &[])));
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_timestamp(order.clone(), Value::Str("updated_at".to_string()), &[]));
m.insert("symbol".to_string(), get_value(&market, &Value::Str("symbol".to_string())));
m.insert("type".to_string(), self.parse_order_type(type_var.clone()));
m.insert("timeInForce".to_string(), self.parse_order_time_in_force(tif.clone()));
m.insert("postOnly".to_string(), Value::Bool(is_equal(&tif, &Value::Str("post-only".to_string()))));
m.insert("reduceOnly".to_string(), reduceOnly.clone());
m.insert("side".to_string(), side.clone());
m.insert("price".to_string(), self.safe_string_k(order.clone(), "price", &[]));
m.insert("triggerPrice".to_string(), triggerPrice.clone());
m.insert("stopLossPrice".to_string(), stopLossPrice.clone());
m.insert("takeProfitPrice".to_string(), takeProfitPrice.clone());
m.insert("amount".to_string(), self.safe_string_k(order.clone(), "initial_base_amount", &[]));
m.insert("cost".to_string(), self.safe_string_k(order.clone(), "filled_quote_amount", &[]));
m.insert("average".to_string(), Value::Null);
m.insert("filled".to_string(), self.safe_string_k(order.clone(), "filled_base_amount", &[]));
m.insert("remaining".to_string(), self.safe_string_k(order.clone(), "remaining_base_amount", &[]));
m.insert("status".to_string(), self.parse_order_status(status.clone()));
m.insert("fee".to_string(), Value::Null);
m.insert("trades".to_string(), Value::Null);
m
}), &[market.clone()]);
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("in-progress".to_string(), Value::Str("open".to_string()));
m.insert("pending".to_string(), Value::Str("open".to_string()));
m.insert("open".to_string(), Value::Str("open".to_string()));
m.insert("filled".to_string(), Value::Str("closed".to_string()));
m.insert("canceled".to_string(), Value::Str("canceled".to_string()));
m.insert("canceled-post-only".to_string(), Value::Str("canceled".to_string()));
m.insert("canceled-reduce-only".to_string(), Value::Str("canceled".to_string()));
m.insert("canceled-position-not-allowed".to_string(), Value::Str("rejected".to_string()));
m.insert("canceled-margin-not-allowed".to_string(), Value::Str("rejected".to_string()));
m.insert("canceled-too-much-slippage".to_string(), Value::Str("canceled".to_string()));
m.insert("canceled-not-enough-liquidity".to_string(), Value::Str("canceled".to_string()));
m.insert("canceled-self-trade".to_string(), Value::Str("canceled".to_string()));
m.insert("canceled-expired".to_string(), Value::Str("expired".to_string()));
m.insert("canceled-oco".to_string(), Value::Str("canceled".to_string()));
m.insert("canceled-child".to_string(), Value::Str("canceled".to_string()));
m.insert("canceled-liquidation".to_string(), Value::Str("canceled".to_string()));
m
});
return self.safe_string(statuses.clone(), status.clone(), &[status.clone()]);
Value::Null
}
pub fn parse_order_type(&self, mut type_var: Value) -> Value {
let mut types: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("limit".to_string(), Value::Str("limit".to_string()));
m.insert("market".to_string(), Value::Str("market".to_string()));
m.insert("stop-loss".to_string(), Value::Str("market".to_string()));
m.insert("stop-loss-limit".to_string(), Value::Str("limit".to_string()));
m.insert("take-profit".to_string(), Value::Str("market".to_string()));
m.insert("take-profit-limit".to_string(), Value::Str("limit".to_string()));
m.insert("twap".to_string(), Value::Str("twap".to_string()));
m.insert("twap-sub".to_string(), Value::Str("twap".to_string()));
m.insert("liquidation".to_string(), Value::Str("market".to_string()));
m
});
return self.safe_string(types.clone(), type_var.clone(), &[type_var.clone()]);
Value::Null
}
pub fn parse_order_type_integer(&self, mut typeInteger: Value) -> Value {
if is_equal(&typeInteger, &Value::Null) {
return Value::Null;
}
let mut types: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("0".to_string(), Value::Str("limit".to_string()));
m.insert("1".to_string(), Value::Str("market".to_string()));
m.insert("2".to_string(), Value::Str("stop-loss".to_string()));
m.insert("3".to_string(), Value::Str("stop-loss-limit".to_string()));
m.insert("4".to_string(), Value::Str("take-profit".to_string()));
m.insert("5".to_string(), Value::Str("take-profit-limit".to_string()));
m.insert("6".to_string(), Value::Str("twap".to_string()));
m.insert("7".to_string(), Value::Str("twap-sub".to_string()));
m.insert("8".to_string(), Value::Str("liquidation".to_string()));
m
});
return self.safe_string(types.clone(), to_string_val(&typeInteger), &[]);
Value::Null
}
pub fn parse_order_time_in_force(&self, mut tif: Value) -> Value {
let mut timeInForces: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("immediate-or-cancel".to_string(), Value::Str("IOC".to_string()));
m.insert("good-till-time".to_string(), Value::Str("GTC".to_string()));
m.insert("post-only".to_string(), Value::Str("PO".to_string()));
m.insert("Unknown".to_string(), Value::Null);
m
});
return self.safe_string(timeInForces.clone(), tif.clone(), &[tif.clone()]);
Value::Null
}
pub fn parse_order_time_in_force_integer(&self, mut tifInteger: Value) -> Value {
let mut timeInForces: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("0".to_string(), Value::Str("immediate-or-cancel".to_string()));
m.insert("1".to_string(), Value::Str("good-till-time".to_string()));
m.insert("2".to_string(), Value::Str("post-only".to_string()));
m
});
return self.safe_string(timeInForces.clone(), to_string_val(&tifInteger), &[]);
Value::Null
}
/*
* @method
* @name lighter#transfer
* @description transfer currency internally between wallets on the same account
* @param {string} code unified currency code
* @param {float} amount amount to transfer
* @param {string} fromAccount account to transfer from (spot, perp)
* @param {string} toAccount account to transfer to (spot, perp)
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.accountIndex] account index
* @param {string} [params.toAccountIndex] to account index, defaults to fromAccountIndex
* @param {string} [params.apiKeyIndex] api key index
* @param {string} [params.memo] hex encoding memo
* @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
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut apiKeyIndex: Value = Value::Null;
{ let __destr_tmp = self.handle_api_key_index(params.clone(), Value::Str("transfer".to_string()), Value::Str("apiKeyIndex".to_string()), Value::Str("api_key_index".to_string()), &[]); apiKeyIndex = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut accountIndex: Value = Value::Null;
{ let __destr_tmp = self.handle_account_index(params.clone(), Value::Str("transfer".to_string()), Value::Str("accountIndex".to_string()), Value::Str("account_index".to_string()), &[]).await; accountIndex = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut toAccountIndex: Value = Value::Null;
{ let __destr_tmp = self.handle_option_and_params2(params.clone(), Value::Str("transfer".to_string()), Value::Str("toAccountIndex".to_string()), Value::Str("to_account_index".to_string()), &[accountIndex.clone()]); toAccountIndex = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut strAccountIndex: Value = self.number_to_string(accountIndex.clone());
let mut strApiKeyIndex: Value = self.number_to_string(apiKeyIndex.clone());
let mut signer: Value = self.load_account(get_value(&self.options, &Value::Str("chainId".to_string())), self.get_lighter_private_key(strAccountIndex.clone(), strApiKeyIndex.clone()), strApiKeyIndex.clone(), strAccountIndex.clone(), &[params.clone()]).await;
let mut currency: Value = self.currency(code.clone());
if is_equal(&get_value(¤cy, &Value::Str("code".to_string())), &Value::Str("USDC".to_string())) {
amount = self.parse_to_int(crate::precise::Precise::stringMul(&self.pow(Value::Str("10".to_string()), Value::Str("6".to_string())), &self.currency_to_precision(code.clone(), amount.clone(), &[])));
} else if is_equal(&get_value(¤cy, &Value::Str("code".to_string())), &Value::Str("ETH".to_string())) {
amount = self.parse_to_int(crate::precise::Precise::stringMul(&self.pow(Value::Str("10".to_string()), Value::Str("8".to_string())), &self.currency_to_precision(code.clone(), amount.clone(), &[])));
} else {
panic!("{}", crate::exchange_errors::exchange_error(add(&self.id, &Value::Str(" transfer() only supports USDC and ETH transfers".to_string()))));
}
let mut fromRouteType: Value = ternary(is_true(&(is_equal(&fromAccount, &Value::Str("perp".to_string())))), Value::Int(0), Value::Int(1)); // 0: perp, 1: spot
let mut toRouteType: Value = ternary(is_true(&(is_equal(&toAccount, &Value::Str("perp".to_string())))), Value::Int(0), Value::Int(1));
let mut memo: Value = self.safe_string_k(params.clone(), "memo", &[Value::Str("0x000000000000000000000000000000".to_string())]);
params = self.omit(params.clone(), Value::List(vec![Value::Str("memo".to_string())]), &[]);
let mut nonce: Value = self.fetch_nonce(accountIndex.clone(), apiKeyIndex.clone(), &[params.clone()]).await;
let mut signRaw: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("to_account_index".to_string(), toAccountIndex.clone());
m.insert("asset_index".to_string(), self.parse_to_int(get_value(¤cy, &Value::Str("id".to_string()))));
m.insert("from_route_type".to_string(), fromRouteType.clone());
m.insert("to_route_type".to_string(), toRouteType.clone());
m.insert("amount".to_string(), amount.clone());
m.insert("usdc_fee".to_string(), Value::Int(0));
m.insert("memo".to_string(), memo.clone());
m.insert("nonce".to_string(), nonce.clone());
m.insert("api_key_index".to_string(), apiKeyIndex.clone());
m.insert("account_index".to_string(), accountIndex.clone());
m
});
let __ws_arg_17 = self.extend(signRaw.clone(), &[params.clone()]);
let mut txTypetxInfoVariable = self.lighter_sign_transfer(signer.clone(), __ws_arg_17);
let mut txType: Value = get_value(&txTypetxInfoVariable, &Value::Int(0));
let mut txInfo: Value = get_value(&txTypetxInfoVariable, &Value::Int(1));
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("tx_type".to_string(), txType.clone());
m.insert("tx_info".to_string(), txInfo.clone());
m
});
let mut response: Value = self.public_post_send_tx(&[request.clone()]).await;
return self.parse_transfer(response.clone(), &[]);
Value::Null
}
/*
* @method
* @name lighter#fetchTransfers
* @description fetch a history of internal transfers made on an account
* @see https://apidocs.lighter.xyz/reference/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
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.accountIndex] account index
* @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 [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(&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("fetchTransfers".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_cursor(Value::Str("fetchTransfers".to_string()), &[code.clone(), since.clone(), limit.clone(), params.clone(), Value::Str("cursor".to_string()), Value::Str("cursor".to_string()), Value::Null, Value::Int(50)]).await;
}
let mut accountIndex: Value = Value::Null;
{ let __destr_tmp = self.handle_account_index(params.clone(), Value::Str("fetchTransfers".to_string()), Value::Str("accountIndex".to_string()), Value::Str("account_index".to_string()), &[]).await; accountIndex = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("account_index".to_string(), accountIndex.clone());
m
});
let mut apiKeyIndex: Value = Value::Null;
{ let __destr_tmp = self.handle_api_key_index(params.clone(), Value::Str("fetchTransfers".to_string()), Value::Str("apiKeyIndex".to_string()), Value::Str("api_key_index".to_string()), &[]); apiKeyIndex = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut strAccountIndex: Value = self.number_to_string(accountIndex.clone());
let mut strApiKeyIndex: Value = self.number_to_string(apiKeyIndex.clone());
self.load_account(get_value(&self.options, &Value::Str("chainId".to_string())), self.get_lighter_private_key(strAccountIndex.clone(), strApiKeyIndex.clone()), strApiKeyIndex.clone(), strAccountIndex.clone(), &[params.clone()]).await;
let mut currency: Value = Value::Null;
if !is_equal(&code, &Value::Null) {
currency = self.currency(code.clone());
}
let __ws_arg_18 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_get_transfer_history(&[__ws_arg_18]).await;
//
// {
// "code": 200,
// "transfers": [
// {
// "id": "3085014",
// "asset_id": 3,
// "amount": "11.000000",
// "fee": "0.000000",
// "timestamp": 1766387292752,
// "type": "L2TransferOutflow",
// "from_l1_address": "0x15f43D1f2DeE81424aFd891943262aa90F22cc2A",
// "to_l1_address": "0x15f43D1f2DeE81424aFd891943262aa90F22cc2A",
// "from_account_index": 1077,
// "to_account_index": 281474976710608,
// "from_route": "spot",
// "to_route": "spot",
// "tx_hash": "d8e96178273d0938f9ede556edffc0aab8def9ec70c46a65791905291a2f5792af18625406102c80"
// }
// ],
// "cursor": "eyJpbmRleCI6MzA4NDkxNX0="
// }
//
let mut rows: Value = self.safe_list_k(response.clone(), "transfers", &[Value::List(vec![])]);
let mut cursor: Value = self.safe_string_k(response.clone(), "cursor", &[]);
let mut first: Value = self.safe_dict(rows.clone(), Value::Int(0), &[]);
if is_true(&(!is_equal(&first, &Value::Null))) && is_true(&(!is_equal(&cursor, &Value::Null))) {
add_element_to_object(get_value_mut(&mut rows, &Value::Int(0)), &Value::Str("cursor".to_string()), cursor.clone());
}
return self.parse_transfers(rows.clone(), &[currency.clone(), since.clone(), limit.clone(), params.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);
//
// {
// "id": "3085014",
// "asset_id": 3,
// "amount": "11.000000",
// "fee": "0.000000",
// "timestamp": 1766387292752,
// "type": "L2TransferOutflow",
// "from_l1_address": "0x15f43D1f2DeE81424aFd891943262aa90F22cc2A",
// "to_l1_address": "0x15f43D1f2DeE81424aFd891943262aa90F22cc2A",
// "from_account_index": 1077,
// "to_account_index": 281474976710608,
// "from_route": "spot",
// "to_route": "spot",
// "tx_hash": "d8e96178273d0938f9ede556edffc0aab8def9ec70c46a65791905291a2f5792af18625406102c80"
// }
//
let mut currencyId: Value = self.safe_string_k(transfer.clone(), "asset_id", &[]);
let mut code: Value = self.safe_currency_code(currencyId.clone(), &[currency.clone()]);
let mut timestamp: Value = self.safe_integer_k(transfer.clone(), "timestamp", &[]);
let mut fromAccount: Value = self.safe_dict_k(transfer.clone(), "from", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut toAccount: Value = self.safe_dict_k(transfer.clone(), "to", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), self.safe_string_k(transfer.clone(), "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(fromAccount.clone(), "from_account_index", &[]));
m.insert("toAccount".to_string(), self.safe_string_k(toAccount.clone(), "to_account_index", &[]));
m.insert("status".to_string(), Value::Null);
m.insert("info".to_string(), transfer.clone());
m
});
Value::Null
}
/*
* @method
* @name lighter#fetchDeposits
* @description fetch all deposits made to an account
* @see https://apidocs.lighter.xyz/reference/deposit_history
* @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 {string} [params.accountIndex] account index
* @param {string} [params.address] l1_address
* @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 [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
}));
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("fetchDeposits".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_cursor(Value::Str("fetchDeposits".to_string()), &[code.clone(), since.clone(), limit.clone(), params.clone(), Value::Str("cursor".to_string()), Value::Str("cursor".to_string()), Value::Null, Value::Int(50)]).await;
}
let mut address: Value = Value::Null;
{ let __destr_tmp = self.handle_option_and_params2(params.clone(), Value::Str("fetchDeposits".to_string()), Value::Str("address".to_string()), Value::Str("l1_address".to_string()), &[]); address = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_equal(&address, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" fetchDeposits() requires an address parameter".to_string()))));
}
let mut accountIndex: Value = Value::Null;
{ let __destr_tmp = self.handle_account_index(params.clone(), Value::Str("fetchDeposits".to_string()), Value::Str("accountIndex".to_string()), Value::Str("account_index".to_string()), &[]).await; accountIndex = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("account_index".to_string(), accountIndex.clone());
m.insert("l1_address".to_string(), address.clone());
m
});
let mut apiKeyIndex: Value = Value::Null;
{ let __destr_tmp = self.handle_api_key_index(params.clone(), Value::Str("fetchDeposits".to_string()), Value::Str("apiKeyIndex".to_string()), Value::Str("api_key_index".to_string()), &[]); apiKeyIndex = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut strAccountIndex: Value = self.number_to_string(accountIndex.clone());
let mut strApiKeyIndex: Value = self.number_to_string(apiKeyIndex.clone());
self.load_account(get_value(&self.options, &Value::Str("chainId".to_string())), self.get_lighter_private_key(strAccountIndex.clone(), strApiKeyIndex.clone()), strApiKeyIndex.clone(), strAccountIndex.clone(), &[params.clone()]).await;
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("coin".to_string()), get_value(¤cy, &Value::Str("id".to_string())));
}
let __ws_arg_19 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_get_deposit_history(&[__ws_arg_19]).await;
//
// {
// "code": 200,
// "deposits": [
// {
// "id": "2901843",
// "asset_id": 5,
// "amount": "100000.0",
// "timestamp": 1766112729741,
// "status": "completed",
// "l1_tx_hash": "0xa24d83d58e1fd72b2a44a12d1ec766fb061fa0b806de2fed940b5d8ecd50744d"
// }
// ],
// "cursor": "eyJpbmRleCI6MjkwMTg0MH0="
// }
//
let mut data: Value = self.safe_list_k(response.clone(), "deposits", &[Value::List(vec![])]);
let mut cursor: Value = self.safe_string_k(response.clone(), "cursor", &[]);
let mut first: Value = self.safe_dict(data.clone(), Value::Int(0), &[]);
if is_true(&(!is_equal(&first, &Value::Null))) && is_true(&(!is_equal(&cursor, &Value::Null))) {
add_element_to_object(get_value_mut(&mut data, &Value::Int(0)), &Value::Str("cursor".to_string()), cursor.clone());
}
return self.parse_transactions(data.clone(), &[currency.clone(), since.clone(), limit.clone()]);
Value::Null
}
/*
* @method
* @name lighter#fetchWithdrawals
* @description fetch all withdrawals made from an account
* @see https://apidocs.lighter.xyz/reference/withdraw_history
* @param {string} [code] unified currency code
* @param {int} [since] the earliest time in ms to fetch withdrawals for
* @param {int} [limit] the maximum number of withdrawals structures to retrieve
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.accountIndex] account index
* @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 [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
}));
let mut paginate: Value = Value::Bool(false);
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchWithdrawals".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_cursor(Value::Str("fetchWithdrawals".to_string()), &[code.clone(), since.clone(), limit.clone(), params.clone(), Value::Str("cursor".to_string()), Value::Str("cursor".to_string()), Value::Null, Value::Int(50)]).await;
}
let mut accountIndex: Value = Value::Null;
{ let __destr_tmp = self.handle_account_index(params.clone(), Value::Str("fetchWithdrawals".to_string()), Value::Str("accountIndex".to_string()), Value::Str("account_index".to_string()), &[]).await; accountIndex = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
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("account_index".to_string(), accountIndex.clone());
m
});
let mut apiKeyIndex: Value = Value::Null;
{ let __destr_tmp = self.handle_api_key_index(params.clone(), Value::Str("fetchWithdrawals".to_string()), Value::Str("apiKeyIndex".to_string()), Value::Str("api_key_index".to_string()), &[]); apiKeyIndex = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut strAccountIndex: Value = self.number_to_string(accountIndex.clone());
let mut strApiKeyIndex: Value = self.number_to_string(apiKeyIndex.clone());
self.load_account(get_value(&self.options, &Value::Str("chainId".to_string())), self.get_lighter_private_key(strAccountIndex.clone(), strApiKeyIndex.clone()), strApiKeyIndex.clone(), strAccountIndex.clone(), &[params.clone()]).await;
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("coin".to_string()), get_value(¤cy, &Value::Str("id".to_string())));
}
let __ws_arg_20 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_get_withdraw_history(&[__ws_arg_20]).await;
//
// {
// "code": "200",
// "message": "string",
// "withdraws": [
// {
// "id": "string",
// "amount": "0.1",
// "timestamp": "1640995200",
// "status": "failed",
// "type": "secure",
// "l1_tx_hash": "0x70997970C51812dc3A010C7d01b50e0d17dc79C8"
// }
// ],
// "cursor": "string"
// }
//
let mut data: Value = self.safe_list_k(response.clone(), "withdraws", &[Value::List(vec![])]);
let mut cursor: Value = self.safe_string_k(response.clone(), "cursor", &[]);
let mut first: Value = self.safe_dict(data.clone(), Value::Int(0), &[]);
if is_true(&(!is_equal(&first, &Value::Null))) && is_true(&(!is_equal(&cursor, &Value::Null))) {
add_element_to_object(get_value_mut(&mut data, &Value::Int(0)), &Value::Str("cursor".to_string()), cursor.clone());
}
return self.parse_transactions(data.clone(), &[currency.clone(), since.clone(), limit.clone()]);
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
// {
// "id": "2901843",
// "asset_id": 5,
// "amount": "100000.0",
// "timestamp": 1766112729741,
// "status": "completed",
// "l1_tx_hash": "0xa24d83d58e1fd72b2a44a12d1ec766fb061fa0b806de2fed940b5d8ecd50744d",
// }
//
// fetchWithdrawals
// {
// "id": "string",
// "amount": "0.1",
// "timestamp": "1640995200",
// "status": "failed",
// "type": "secure",
// "l1_tx_hash": "0x70997970C51812dc3A010C7d01b50e0d17dc79C8"
// }
//
let mut type_var: Value = self.safe_string_k(transaction.clone(), "type", &[]);
if is_equal(&type_var, &Value::Null) {
type_var = Value::Str("deposit".to_string());
} else {
type_var = Value::Str("withdrawal".to_string());
}
let mut timestamp: Value = self.safe_integer_k(transaction.clone(), "timestamp", &[]);
let mut status: Value = self.safe_string_k(transaction.clone(), "status", &[]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), transaction.clone());
m.insert("id".to_string(), self.safe_string_k(transaction.clone(), "id", &[]));
m.insert("txid".to_string(), self.safe_string_k(transaction.clone(), "l1_tx_hash", &[]));
m.insert("type".to_string(), type_var.clone());
m.insert("currency".to_string(), self.safe_currency_code(self.safe_string_k(transaction.clone(), "asset_id", &[]), &[currency.clone()]));
m.insert("network".to_string(), Value::Null);
m.insert("amount".to_string(), self.safe_number_k(transaction.clone(), "amount", &[]));
m.insert("status".to_string(), self.parse_transaction_status(status.clone()));
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(), Value::Null);
m.insert("addressTo".to_string(), Value::Null);
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.insert("internal".to_string(), Value::Null);
m
});
Value::Null
}
pub fn parse_transaction_status(&self, mut status: Value) -> Value {
let mut statuses: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("failed".to_string(), Value::Str("failed".to_string()));
m.insert("pending".to_string(), Value::Str("pending".to_string()));
m.insert("completed".to_string(), Value::Str("ok".to_string()));
m.insert("claimable".to_string(), Value::Str("ok".to_string()));
m
});
return self.safe_string(statuses.clone(), status.clone(), &[status.clone()]);
Value::Null
}
/*
* @method
* @name lighter#withdraw
* @description make a 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.accountIndex] account index
* @param {string} [params.apiKeyIndex] api key index
* @param {int} [params.routeType] wallet type, 0: perp, 1: spot, default is 0
* @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
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut apiKeyIndex: Value = Value::Null;
{ let __destr_tmp = self.handle_api_key_index(params.clone(), Value::Str("withdraw".to_string()), Value::Str("apiKeyIndex".to_string()), Value::Str("api_key_index".to_string()), &[]); apiKeyIndex = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut accountIndex: Value = Value::Null;
{ let __destr_tmp = self.handle_account_index(params.clone(), Value::Str("withdraw".to_string()), Value::Str("accountIndex".to_string()), Value::Str("account_index".to_string()), &[]).await; accountIndex = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut strAccountIndex: Value = self.number_to_string(accountIndex.clone());
let mut strApiKeyIndex: Value = self.number_to_string(apiKeyIndex.clone());
let mut signer: Value = self.load_account(get_value(&self.options, &Value::Str("chainId".to_string())), self.get_lighter_private_key(strAccountIndex.clone(), strApiKeyIndex.clone()), strApiKeyIndex.clone(), strAccountIndex.clone(), &[params.clone()]).await;
let mut currency: Value = self.currency(code.clone());
if is_equal(&get_value(¤cy, &Value::Str("code".to_string())), &Value::Str("USDC".to_string())) {
amount = self.parse_to_int(crate::precise::Precise::stringMul(&self.pow(Value::Str("10".to_string()), Value::Str("6".to_string())), &self.currency_to_precision(code.clone(), amount.clone(), &[])));
} else if is_equal(&get_value(¤cy, &Value::Str("code".to_string())), &Value::Str("ETH".to_string())) {
amount = self.parse_to_int(crate::precise::Precise::stringMul(&self.pow(Value::Str("10".to_string()), Value::Str("8".to_string())), &self.currency_to_precision(code.clone(), amount.clone(), &[])));
} else {
panic!("{}", crate::exchange_errors::exchange_error(add(&self.id, &Value::Str(" withdraw() only supports USDC and ETH transfers".to_string()))));
}
let mut routeType: Value = self.safe_integer_k(params.clone(), "routeType", &[Value::Int(0)]); // 0: perp, 1: spot
params = self.omit(params.clone(), Value::Str("routeType".to_string()), &[]);
let mut nonce: Value = self.fetch_nonce(accountIndex.clone(), apiKeyIndex.clone(), &[params.clone()]).await;
let mut signRaw: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("asset_index".to_string(), self.parse_to_int(get_value(¤cy, &Value::Str("id".to_string()))));
m.insert("route_type".to_string(), routeType.clone());
m.insert("amount".to_string(), amount.clone());
m.insert("nonce".to_string(), nonce.clone());
m.insert("api_key_index".to_string(), apiKeyIndex.clone());
m.insert("account_index".to_string(), accountIndex.clone());
m
});
let __ws_arg_21 = self.extend(signRaw.clone(), &[params.clone()]);
let mut txTypetxInfoVariable = self.lighter_sign_withdraw(signer.clone(), __ws_arg_21);
let mut txType: Value = get_value(&txTypetxInfoVariable, &Value::Int(0));
let mut txInfo: Value = get_value(&txTypetxInfoVariable, &Value::Int(1));
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("tx_type".to_string(), txType.clone());
m.insert("tx_info".to_string(), txInfo.clone());
m
});
let mut response: Value = self.public_post_send_tx(&[request.clone()]).await;
return self.parse_transaction(response.clone(), &[]);
Value::Null
}
/*
* @method
* @name lighter#fetchMyTrades
* @description fetch all trades made by the user
* @see https://apidocs.lighter.xyz/reference/trades
* @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 trades structures to retrieve
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.accountIndex] account index
* @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)
* @param {int} [params.until] timestamp in ms of the latest trade to fetch
* @returns {object[]} 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
}));
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("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_cursor(Value::Str("fetchMyTrades".to_string()), &[symbol.clone(), since.clone(), limit.clone(), params.clone(), Value::Str("next_cursor".to_string()), Value::Str("cursor".to_string()), Value::Null, Value::Int(50)]).await;
}
let mut accountIndex: Value = Value::Null;
{ let __destr_tmp = self.handle_account_index(params.clone(), Value::Str("fetchMyTrades".to_string()), Value::Str("accountIndex".to_string()), Value::Str("account_index".to_string()), &[]).await; accountIndex = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut apiKeyIndex: Value = Value::Null;
{ let __destr_tmp = self.handle_api_key_index(params.clone(), Value::Str("fetchMyTrades".to_string()), Value::Str("apiKeyIndex".to_string()), Value::Str("api_key_index".to_string()), &[]); apiKeyIndex = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut strAccountIndex: Value = self.number_to_string(accountIndex.clone());
let mut strApiKeyIndex: Value = self.number_to_string(apiKeyIndex.clone());
self.load_account(get_value(&self.options, &Value::Str("chainId".to_string())), self.get_lighter_private_key(strAccountIndex.clone(), strApiKeyIndex.clone()), strApiKeyIndex.clone(), strAccountIndex.clone(), &[params.clone()]).await;
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("sort_by".to_string(), Value::Str("timestamp".to_string()));
m.insert("limit".to_string(), Value::Int(100));
m.insert("account_index".to_string(), accountIndex.clone());
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(100)));
}
let mut until: Value = Value::Null;
{ let __destr_tmp = self.handle_option_and_params2(params.clone(), Value::Str("fetchMyTrades".to_string()), Value::Str("until".to_string()), Value::Str("from".to_string()), &[]); until = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if !is_equal(&until, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("from".to_string()), until.clone());
}
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("market_id".to_string()), get_value(&market, &Value::Str("id".to_string())));
}
let __ws_arg_22 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_get_trades(&[__ws_arg_22]).await;
//
// {
// "code": 200,
// "trades": [
// {
// "trade_id": 17609,
// "tx_hash": "99ffeaa3899fbaa51043840ddf762fd18c182a33b5125092105bee57af11fab04edf5fd90e969abd",
// "type": "trade",
// "market_id": 0,
// "size": "10.2304",
// "price": "2958.75",
// "usd_amount": "30269.196000",
// "ask_id": 281474977339869,
// "bid_id": 562949952870533,
// "ask_client_id": 0,
// "bid_client_id": 0,
// "ask_account_id": 20,
// "bid_account_id": 1077,
// "is_maker_ask": true,
// "block_height": 102070,
// "timestamp": 1766386112741,
// "taker_position_size_before": "0.0000",
// "taker_entry_quote_before": "0.000000",
// "taker_position_sign_changed": true,
// "maker_position_size_before": "-1856.8547",
// "maker_entry_quote_before": "5491685.069325",
// "maker_initial_margin_fraction_before": 500
// }
// ]
// }
//
let mut data: Value = self.safe_list_k(response.clone(), "trades", &[Value::List(vec![])]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_924: bool = true;
while { if !__for_first_924 { i = add(&i, &Value::Int(1)); } __for_first_924 = false; is_less_than(&i, &get_array_length(&data)) } {
add_element_to_object(get_value_mut(&mut data, &i), &Value::Str("account_index".to_string()), accountIndex.clone());
}
}
let mut nextCursor: Value = self.safe_string_k(response.clone(), "next_cursor", &[]);
let mut first: Value = self.safe_dict(data.clone(), Value::Int(0), &[]);
if is_true(&(!is_equal(&first, &Value::Null))) && is_true(&(!is_equal(&nextCursor, &Value::Null))) {
add_element_to_object(get_value_mut(&mut data, &Value::Int(0)), &Value::Str("next_cursor".to_string()), nextCursor.clone());
}
return self.parse_trades(data.clone(), &[market.clone(), since.clone(), limit.clone(), params.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);
//
// {
// "trade_id": 17609,
// "tx_hash": "99ffeaa3899fbaa51043840ddf762fd18c182a33b5125092105bee57af11fab04edf5fd90e969abd",
// "type": "trade",
// "market_id": 0,
// "size": "10.2304",
// "price": "2958.75",
// "usd_amount": "30269.196000",
// "ask_id": 281474977339869,
// "bid_id": 562949952870533,
// "ask_client_id": 0,
// "bid_client_id": 0,
// "ask_account_id": 20,
// "bid_account_id": 1077,
// "is_maker_ask": true,
// "block_height": 102070,
// "timestamp": 1766386112741,
// "taker_position_size_before": "0.0000",
// "taker_entry_quote_before": "0.000000",
// "taker_position_sign_changed": true,
// "maker_position_size_before": "-1856.8547",
// "maker_entry_quote_before": "5491685.069325",
// "maker_initial_margin_fraction_before": 500
// }
//
let mut marketId: Value = self.safe_string_k(trade.clone(), "market_id", &[]);
market = self.safe_market(&[marketId.clone(), market.clone()]);
let mut timestamp: Value = self.safe_integer_k(trade.clone(), "timestamp", &[]);
let mut accountIndex: Value = self.safe_string_k(trade.clone(), "account_index", &[]);
let mut askAccountId: Value = self.safe_string_k(trade.clone(), "ask_account_id", &[]);
let mut bidAccountId: Value = self.safe_string_k(trade.clone(), "bid_account_id", &[]);
let mut isMakerAsk: Value = self.safe_bool_k(trade.clone(), "is_maker_ask", &[]);
let mut side: Value = Value::Null;
let mut orderId: Value = Value::Null;
if !is_equal(&accountIndex, &Value::Null) {
if is_equal(&accountIndex, &askAccountId) {
side = Value::Str("sell".to_string());
orderId = self.safe_string_k(trade.clone(), "ask_id", &[]);
} else if is_equal(&accountIndex, &bidAccountId) {
side = Value::Str("buy".to_string());
orderId = self.safe_string_k(trade.clone(), "bid_id", &[]);
}
}
let mut takerOrMaker: Value = Value::Null;
if !is_equal(&side, &Value::Null) && !is_equal(&isMakerAsk, &Value::Null) {
let mut isMaker: Value = ternary(is_true(&(is_equal(&side, &Value::Str("sell".to_string())))), isMakerAsk.clone(), Value::Bool(!is_true(&isMakerAsk)));
takerOrMaker = ternary(is_true(&isMaker), Value::Str("maker".to_string()), Value::Str("taker".to_string()));
}
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("order".to_string(), orderId.clone());
m.insert("type".to_string(), self.safe_string_k(trade.clone(), "type", &[]));
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(), self.safe_string_k(trade.clone(), "usd_amount", &[]));
m.insert("fee".to_string(), Value::Null);
m
}), &[market.clone()]);
Value::Null
}
/*
* @method
* @name lighter#setLeverage
* @description set the level of leverage for a market
* @param {float} leverage the rate of leverage
* @param {string} symbol unified market symbol
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.accountIndex] account index
* @param {string} [params.apiKeyIndex] api key index
* @param {string} [params.marginMode] margin mode, 'cross' or 'isolated'
* @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()))));
}
let mut marginMode: Value = Value::Null;
{ let __destr_tmp = self.handle_option_and_params2(params.clone(), Value::Str("setLeverage".to_string()), Value::Str("marginMode".to_string()), Value::Str("margin_mode".to_string()), &[]); marginMode = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_equal(&marginMode, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" setLeverage() requires an marginMode parameter".to_string()))));
}
return self.modify_leverage_and_margin_mode(leverage.clone(), marginMode.clone(), &[symbol.clone(), params.clone()]).await;
Value::Null
}
/*
* @method
* @name lighter#setMarginMode
* @description set margin mode to 'cross' or 'isolated'
* @param {string} marginMode 'cross' or 'isolated'
* @param {string} symbol unified market symbol
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.accountIndex] account index
* @param {string} [params.apiKeyIndex] api key index
* @param {int} [params.leverage] required leverage
* @returns {object} response from the exchange
*/
pub async fn set_margin_mode(&mut self, mut marginMode: 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(&marginMode, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" setMarginMode() requires an marginMode parameter".to_string()))));
}
let mut leverage: Value = Value::Null;
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("setMarginMode".to_string()), Value::Str("leverage".to_string()), &[]); leverage = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_equal(&leverage, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" setMarginMode() requires an leverage parameter".to_string()))));
}
return self.modify_leverage_and_margin_mode(leverage.clone(), marginMode.clone(), &[symbol.clone(), params.clone()]).await;
Value::Null
}
pub async fn modify_leverage_and_margin_mode(&mut self, mut leverage: Value, mut marginMode: 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(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
if is_true(&(!is_equal(&marginMode, &Value::Str("cross".to_string())))) && is_true(&(!is_equal(&marginMode, &Value::Str("isolated".to_string())))) {
panic!("{}", crate::exchange_errors::bad_request(add(&self.id, &Value::Str(" modifyLeverageAndMarginMode() requires a marginMode parameter that must be either cross or isolated".to_string()))));
}
let mut apiKeyIndex: Value = Value::Null;
{ let __destr_tmp = self.handle_api_key_index(params.clone(), Value::Str("modifyLeverageAndMarginMode".to_string()), Value::Str("apiKeyIndex".to_string()), Value::Str("api_key_index".to_string()), &[]); apiKeyIndex = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_equal(&symbol, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" modifyLeverageAndMarginMode() requires a symbol argument".to_string()))));
}
let mut accountIndex: Value = Value::Null;
{ let __destr_tmp = self.handle_account_index(params.clone(), Value::Str("modifyLeverageAndMarginMode".to_string()), Value::Str("accountIndex".to_string()), Value::Str("account_index".to_string()), &[]).await; accountIndex = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut strAccountIndex: Value = self.number_to_string(accountIndex.clone());
let mut strApiKeyIndex: Value = self.number_to_string(apiKeyIndex.clone());
let mut signer: Value = self.load_account(get_value(&self.options, &Value::Str("chainId".to_string())), self.get_lighter_private_key(strAccountIndex.clone(), strApiKeyIndex.clone()), strApiKeyIndex.clone(), strAccountIndex.clone(), &[params.clone()]).await;
let mut market: Value = self.market(symbol.clone());
let mut nonce: Value = self.fetch_nonce(accountIndex.clone(), apiKeyIndex.clone(), &[params.clone()]).await;
let mut signRaw: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("market_index".to_string(), self.parse_to_int(get_value(&market, &Value::Str("id".to_string()))));
m.insert("initial_margin_fraction".to_string(), self.parse_to_int(divide(&Value::Int(10000), &leverage)));
m.insert("margin_mode".to_string(), ternary(is_true(&(is_equal(&marginMode, &Value::Str("cross".to_string())))), Value::Int(0), Value::Int(1)));
m.insert("nonce".to_string(), nonce.clone());
m.insert("api_key_index".to_string(), apiKeyIndex.clone());
m.insert("account_index".to_string(), accountIndex.clone());
m
});
let __ws_arg_23 = self.extend(signRaw.clone(), &[params.clone()]);
let mut txTypetxInfoVariable = self.lighter_sign_update_leverage(signer.clone(), __ws_arg_23);
let mut txType: Value = get_value(&txTypetxInfoVariable, &Value::Int(0));
let mut txInfo: Value = get_value(&txTypetxInfoVariable, &Value::Int(1));
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("tx_type".to_string(), txType.clone());
m.insert("tx_info".to_string(), txInfo.clone());
m
});
return self.public_post_send_tx(&[request.clone()]).await;
Value::Null
}
pub async fn sign_and_cancel_order(&mut self, mut method: Value, 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
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
if is_equal(&symbol, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&add(&add(&self.id, &Value::Str(" ".to_string())), &method), &Value::Str(" requires a symbol argument".to_string()))));
}
let mut apiKeyIndex: Value = Value::Null;
{ let __destr_tmp = self.handle_api_key_index(params.clone(), method.clone(), Value::Str("apiKeyIndex".to_string()), Value::Str("api_key_index".to_string()), &[]); apiKeyIndex = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut accountIndex: Value = Value::Null;
{ let __destr_tmp = self.handle_account_index(params.clone(), method.clone(), Value::Str("accountIndex".to_string()), Value::Str("account_index".to_string()), &[]).await; accountIndex = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut market: Value = self.market(symbol.clone());
let mut clientOrderId: Value = self.safe_string2(params.clone(), Value::Str("client_order_index".to_string()), Value::Str("clientOrderId".to_string()), &[]);
params = self.omit(params.clone(), Value::List(vec![Value::Str("client_order_index".to_string()), Value::Str("clientOrderId".to_string())]), &[]);
let mut strAccountIndex: Value = self.number_to_string(accountIndex.clone());
let mut strApiKeyIndex: Value = self.number_to_string(apiKeyIndex.clone());
let mut signer: Value = self.load_account(get_value(&self.options, &Value::Str("chainId".to_string())), self.get_lighter_private_key(strAccountIndex.clone(), strApiKeyIndex.clone()), strApiKeyIndex.clone(), strAccountIndex.clone(), &[params.clone()]).await;
let mut nonce: Value = self.fetch_nonce(accountIndex.clone(), apiKeyIndex.clone(), &[params.clone()]).await;
let mut signRaw: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("market_index".to_string(), self.parse_to_int(get_value(&market, &Value::Str("id".to_string()))));
m.insert("nonce".to_string(), nonce.clone());
m.insert("api_key_index".to_string(), apiKeyIndex.clone());
m.insert("account_index".to_string(), accountIndex.clone());
m
});
if !is_equal(&clientOrderId, &Value::Null) {
add_element_to_object(&mut signRaw, &Value::Str("order_index".to_string()), self.parse_to_int(clientOrderId.clone()));
} else if !is_equal(&id, &Value::Null) {
add_element_to_object(&mut signRaw, &Value::Str("order_index".to_string()), self.parse_to_int(id.clone()));
} else {
panic!("{}", crate::exchange_errors::arguments_required(add(&add(&add(&self.id, &Value::Str(" ".to_string())), &method), &Value::Str(" requires order id or client order id".to_string()))));
}
let __ws_arg_24 = self.extend(signRaw.clone(), &[params.clone()]);
let mut txTypetxInfoVariable = self.lighter_sign_cancel_order(signer.clone(), __ws_arg_24);
let mut txType: Value = get_value(&txTypetxInfoVariable, &Value::Int(0));
let mut txInfo: Value = get_value(&txTypetxInfoVariable, &Value::Int(1));
return Value::List(vec![txType.clone(), txInfo.clone(), market.clone()]);
Value::Null
}
/*
* @method
* @name lighter#cancelOrder
* @description cancels an open 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.accountIndex] account index
* @param {string} [params.apiKeyIndex] api key index
* @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
}));
let mut txTypetxInfomarketVariable = self.sign_and_cancel_order(Value::Str("cancelOrder".to_string()), id.clone(), &[symbol.clone(), params.clone()]).await;
let mut txType: Value = get_value(&txTypetxInfomarketVariable, &Value::Int(0));
let mut txInfo: Value = get_value(&txTypetxInfomarketVariable, &Value::Int(1));
let mut market: Value = get_value(&txTypetxInfomarketVariable, &Value::Int(2));
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("tx_type".to_string(), txType.clone());
m.insert("tx_info".to_string(), txInfo.clone());
m
});
let mut response: Value = self.public_post_send_tx(&[request.clone()]).await;
return self.parse_order(response.clone(), &[market.clone()]);
Value::Null
}
pub async fn sign_and_cancel_all_orders(&mut self, mut method: 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(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut apiKeyIndex: Value = Value::Null;
{ let __destr_tmp = self.handle_api_key_index(params.clone(), method.clone(), Value::Str("apiKeyIndex".to_string()), Value::Str("api_key_index".to_string()), &[]); apiKeyIndex = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut accountIndex: Value = Value::Null;
{ let __destr_tmp = self.handle_account_index(params.clone(), method.clone(), Value::Str("accountIndex".to_string()), Value::Str("account_index".to_string()), &[]).await; accountIndex = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut strAccountIndex: Value = self.number_to_string(accountIndex.clone());
let mut strApiKeyIndex: Value = self.number_to_string(apiKeyIndex.clone());
let mut signer: Value = self.load_account(get_value(&self.options, &Value::Str("chainId".to_string())), self.get_lighter_private_key(strAccountIndex.clone(), strApiKeyIndex.clone()), strApiKeyIndex.clone(), strAccountIndex.clone(), &[params.clone()]).await;
let mut nonce: Value = self.fetch_nonce(accountIndex.clone(), apiKeyIndex.clone(), &[params.clone()]).await;
let mut signRaw: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("time_in_force".to_string(), Value::Int(0));
m.insert("time".to_string(), Value::Int(0));
m.insert("nonce".to_string(), nonce.clone());
m.insert("api_key_index".to_string(), apiKeyIndex.clone());
m.insert("account_index".to_string(), accountIndex.clone());
m
});
let __ws_arg_25 = self.extend(signRaw.clone(), &[params.clone()]);
let mut txTypetxInfoVariable = self.lighter_sign_cancel_all_orders(signer.clone(), __ws_arg_25);
let mut txType: Value = get_value(&txTypetxInfoVariable, &Value::Int(0));
let mut txInfo: Value = get_value(&txTypetxInfoVariable, &Value::Int(1));
return Value::List(vec![txType.clone(), txInfo.clone()]);
Value::Null
}
/*
* @method
* @name lighter#cancelAllOrders
* @description cancel all open 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
* @param {string} [params.accountIndex] account index
* @param {string} [params.apiKeyIndex] api key index
* @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
}));
let mut txTypetxInfoVariable = self.sign_and_cancel_all_orders(Value::Str("cancelAllOrdersWs".to_string()), &[symbol.clone(), params.clone()]).await;
let mut txType: Value = get_value(&txTypetxInfoVariable, &Value::Int(0));
let mut txInfo: Value = get_value(&txTypetxInfoVariable, &Value::Int(1));
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("tx_type".to_string(), txType.clone());
m.insert("tx_info".to_string(), txInfo.clone());
m
});
let mut response: Value = self.public_post_send_tx(&[request.clone()]).await;
return self.parse_orders(Value::List(vec![response.clone()]), &[]);
Value::Null
}
/*
* @method
* @name lighter#cancelAllOrdersAfter
* @description dead man's switch, cancel all orders after the given timeout
* @param {number} timeout time in milliseconds, 0 represents cancel the timer
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} the api result
*/
pub async fn cancel_all_orders_after(&mut self, mut timeout: 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;
}
if is_true(&(is_less_than(&timeout, &Value::Int(300000)))) || is_true(&(is_greater_than(&timeout, &Value::Int(1296000000)))) {
panic!("{}", crate::exchange_errors::bad_request(add(&self.id, &Value::Str(" timeout should be between 5 minutes and 15 days.".to_string()))));
}
let mut apiKeyIndex: Value = Value::Null;
{ let __destr_tmp = self.handle_api_key_index(params.clone(), Value::Str("cancelOrder".to_string()), Value::Str("apiKeyIndex".to_string()), Value::Str("api_key_index".to_string()), &[]); apiKeyIndex = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut accountIndex: Value = Value::Null;
{ let __destr_tmp = self.handle_account_index(params.clone(), Value::Str("cancelAllOrdersAfter".to_string()), Value::Str("accountIndex".to_string()), Value::Str("account_index".to_string()), &[]).await; accountIndex = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut strAccountIndex: Value = self.number_to_string(accountIndex.clone());
let mut strApiKeyIndex: Value = self.number_to_string(apiKeyIndex.clone());
let mut signer: Value = self.load_account(get_value(&self.options, &Value::Str("chainId".to_string())), self.get_lighter_private_key(strAccountIndex.clone(), strApiKeyIndex.clone()), strApiKeyIndex.clone(), strAccountIndex.clone(), &[params.clone()]).await;
let mut nonce: Value = self.fetch_nonce(accountIndex.clone(), apiKeyIndex.clone(), &[params.clone()]).await;
let mut signRaw: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("time_in_force".to_string(), Value::Int(1));
m.insert("time".to_string(), add(&self.milliseconds(), &timeout));
m.insert("nonce".to_string(), nonce.clone());
m.insert("api_key_index".to_string(), apiKeyIndex.clone());
m.insert("account_index".to_string(), accountIndex.clone());
m
});
let __ws_arg_26 = self.extend(signRaw.clone(), &[params.clone()]);
let mut txTypetxInfoVariable = self.lighter_sign_cancel_all_orders(signer.clone(), __ws_arg_26);
let mut txType: Value = get_value(&txTypetxInfoVariable, &Value::Int(0));
let mut txInfo: Value = get_value(&txTypetxInfoVariable, &Value::Int(1));
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("tx_type".to_string(), txType.clone());
m.insert("tx_info".to_string(), txInfo.clone());
m
});
let mut response: Value = self.public_post_send_tx(&[request.clone()]).await;
return response;
Value::Null
}
/*
* @method
* @name lighter#addMargin
* @description add margin
* @param {string} symbol unified market symbol
* @param {float} amount amount of margin to add
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a [margin structure]{@link https://docs.ccxt.com/?id=add-margin-structure}
*/
pub async fn add_margin(&mut self, mut symbol: Value, mut amount: Value, 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("direction".to_string(), Value::Int(1));
m
});
let __ws_arg_27 = self.extend(request.clone(), &[params.clone()]);
return self.set_margin(symbol.clone(), amount.clone(), &[__ws_arg_27]).await;
Value::Null
}
/*
* @method
* @name lighter#reduceMargin
* @description remove margin from a position
* @param {string} symbol unified market symbol
* @param {float} amount the amount of margin to remove
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a [margin structure]{@link https://docs.ccxt.com/?id=reduce-margin-structure}
*/
pub async fn reduce_margin(&mut self, mut symbol: Value, mut amount: Value, 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("direction".to_string(), Value::Int(0));
m
});
let __ws_arg_28 = self.extend(request.clone(), &[params.clone()]);
return self.set_margin(symbol.clone(), amount.clone(), &[__ws_arg_28]).await;
Value::Null
}
/*
* @method
* @name lighter#setMargin
* @description Either adds or reduces margin in an isolated position in order to set the margin to a specific value
* @param {string} symbol unified market symbol of the market to set margin in
* @param {float} amount the amount to set the margin to
* @param {object} [params] parameters specific to the exchange API endpoint
* @param {string} [params.accountIndex] account index
* @param {string} [params.apiKeyIndex] api key index
* @returns {object} A [margin structure]{@link https://docs.ccxt.com/?id=add-margin-structure}
*/
pub async fn set_margin(&mut self, mut symbol: Value, mut amount: 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 apiKeyIndex: Value = Value::Null;
{ let __destr_tmp = self.handle_api_key_index(params.clone(), Value::Str("setMargin".to_string()), Value::Str("apiKeyIndex".to_string()), Value::Str("api_key_index".to_string()), &[]); apiKeyIndex = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut direction: Value = self.safe_integer_k(params.clone(), "direction", &[]); // 1 increase margin 0 decrease margin
if is_equal(&direction, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" setMargin() requires a direction parameter either 1 (increase margin) or 0 (decrease margin)".to_string()))));
}
if !is_true(&self.in_array(direction.clone(), Value::List(vec![Value::Int(0), Value::Int(1)]))) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" setMargin() requires a direction parameter either 1 (increase margin) or 0 (decrease margin)".to_string()))));
}
if is_equal(&symbol, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" setMargin() requires a symbol argument".to_string()))));
}
let mut accountIndex: Value = Value::Null;
{ let __destr_tmp = self.handle_account_index(params.clone(), Value::Str("setMargin".to_string()), Value::Str("accountIndex".to_string()), Value::Str("account_index".to_string()), &[]).await; accountIndex = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut strAccountIndex: Value = self.number_to_string(accountIndex.clone());
let mut strApiKeyIndex: Value = self.number_to_string(apiKeyIndex.clone());
let mut signer: Value = self.load_account(get_value(&self.options, &Value::Str("chainId".to_string())), self.get_lighter_private_key(strAccountIndex.clone(), strApiKeyIndex.clone()), strApiKeyIndex.clone(), strAccountIndex.clone(), &[params.clone()]).await;
let mut market: Value = self.market(symbol.clone());
let mut nonce: Value = self.fetch_nonce(accountIndex.clone(), apiKeyIndex.clone(), &[params.clone()]).await;
let mut signRaw: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("market_index".to_string(), self.parse_to_int(get_value(&market, &Value::Str("id".to_string()))));
m.insert("usdc_amount".to_string(), self.parse_to_int(crate::precise::Precise::stringMul(&self.pow(Value::Str("10".to_string()), Value::Str("6".to_string())), &self.currency_to_precision(Value::Str("USDC".to_string()), amount.clone(), &[]))));
m.insert("direction".to_string(), direction.clone());
m.insert("nonce".to_string(), nonce.clone());
m.insert("api_key_index".to_string(), apiKeyIndex.clone());
m.insert("account_index".to_string(), accountIndex.clone());
m
});
let __ws_arg_29 = self.extend(signRaw.clone(), &[params.clone()]);
let mut txTypetxInfoVariable = self.lighter_sign_update_margin(signer.clone(), __ws_arg_29);
let mut txType: Value = get_value(&txTypetxInfoVariable, &Value::Int(0));
let mut txInfo: Value = get_value(&txTypetxInfoVariable, &Value::Int(1));
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("tx_type".to_string(), txType.clone());
m.insert("tx_info".to_string(), txInfo.clone());
m
});
let mut response: Value = self.public_post_send_tx(&[request.clone()]).await;
return self.parse_margin_modification(response.clone(), &[market.clone()]);
Value::Null
}
pub fn parse_margin_modification(&self, mut data: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
let mut timestamp: Value = self.safe_integer_k(data.clone(), "predicted_execution_time_ms", &[]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), data.clone());
m.insert("symbol".to_string(), self.safe_string_k(market.clone(), "symbol", &[]));
m.insert("type".to_string(), Value::Null);
m.insert("marginMode".to_string(), Value::Null);
m.insert("amount".to_string(), Value::Null);
m.insert("total".to_string(), Value::Null);
m.insert("code".to_string(), Value::Str("USDC".to_string()));
m.insert("status".to_string(), Value::Null);
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m
});
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 url: Value = Value::Null;
if is_equal(&api, &Value::Str("root".to_string())) {
url = self.implode_hostname(get_value(&get_value(&self.urls, &Value::Str("api".to_string())), &Value::Str("public".to_string())));
} else {
url = add(&add(&add(&add(&self.implode_hostname(get_value(&get_value(&self.urls, &Value::Str("api".to_string())), &api)), &Value::Str("/api/".to_string())), &self.version), &Value::Str("/".to_string())), &path);
}
if is_equal(&api, &Value::Str("private".to_string())) {
headers = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("Authorization".to_string(), self.create_auth(&[params.clone()]));
m
});
}
if is_greater_than(&get_array_length(&object_keys(¶ms)), &Value::Int(0)) {
if is_equal(&method, &Value::Str("POST".to_string())) {
headers = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("Content-Type".to_string(), Value::Str("multipart/form-data".to_string()));
m
});
body = params.clone();
} else {
url = add(&url, &add(&Value::Str("?".to_string()), &self.rawencode(params.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 httpCode: 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(&(is_equal(&response, &Value::Null))) || is_true(&(is_equal(&response, &Value::Null))) {
return Value::Null;
}
//
// {
// "code": "200",
// "message": "string"
// }
//
let mut code: Value = self.safe_string_k(response.clone(), "code", &[]);
let mut message: Value = self.safe_string_k(response.clone(), "msg", &[]);
if !is_equal(&code, &Value::Null) && !is_equal(&code, &Value::Str("0".to_string())) && !is_equal(&code, &Value::Str("200".to_string())) {
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());
self.throw_exactly_matched_exception(get_value(&self.exceptions, &Value::Str("exact".to_string())), code.clone(), feedback.clone());
panic!("{}", crate::exchange_errors::exchange_error(feedback));
}
return Value::Null;
Value::Null
}
}