ccxt-pro 4.5.78

CCXT – CryptoCurrency eXchange Trading Library (Rust) – pro (WebSocket / watch*) exchanges
// 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;
use crate::pro::*;


pub struct KucoinfuturesCore {
    pub parent: crate::pro::kucoin::KucoinCore,
}

impl KucoinfuturesCore {
    pub fn new(config: Option<crate::Value>) -> Self {
        let mut s = Self { parent: crate::pro::kucoin::KucoinCore::new(config) };
        s.init();
        s
    }

    pub fn init(&mut self) {
        let described = KucoinfuturesCore::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 KucoinfuturesCore {
    fn nonce(&self, ) -> crate::Value {
        crate::exchange::DerivedExchange::nonce(&self.parent)
    }
    fn parse_ticker(&self, ticker: crate::Value, market: crate::Value) -> crate::Value {
        crate::exchange::DerivedExchange::parse_ticker(&self.parent, ticker, market)
    }
    fn parse_trade(&self, trade: crate::Value, market: crate::Value) -> crate::Value {
        crate::exchange::DerivedExchange::parse_trade(&self.parent, trade, market)
    }
    fn parse_order(&self, order: crate::Value, market: crate::Value) -> crate::Value {
        crate::exchange::DerivedExchange::parse_order(&self.parent, order, market)
    }
    fn parse_market(&self, market: crate::Value) -> crate::Value {
        crate::exchange::DerivedExchange::parse_market(&self.parent, market)
    }
    fn parse_ohlcv(&self, ohlcv: crate::Value, market: crate::Value) -> crate::Value {
        crate::exchange::DerivedExchange::parse_ohlcv(&self.parent, ohlcv, market)
    }
    fn parse_order_book(&self, ob: crate::Value, symbol: crate::Value, ts: crate::Value, bk: crate::Value, ak: crate::Value, pk: crate::Value, ak2: crate::Value, ck: crate::Value) -> crate::Value {
        crate::exchange::DerivedExchange::parse_order_book(&self.parent, ob, symbol, ts, bk, ak, pk, ak2, ck)
    }
    fn parse_balance(&self, response: crate::Value) -> crate::Value {
        crate::exchange::DerivedExchange::parse_balance(&self.parent, response)
    }
    fn parse_position(&self, position: crate::Value, market: crate::Value) -> crate::Value {
        crate::exchange::DerivedExchange::parse_position(&self.parent, position, market)
    }
    fn parse_funding_rate(&self, rate: crate::Value, market: crate::Value) -> crate::Value {
        crate::exchange::DerivedExchange::parse_funding_rate(&self.parent, rate, market)
    }
    fn parse_deposit(&self, tx: crate::Value, currency: crate::Value) -> crate::Value {
        crate::exchange::DerivedExchange::parse_deposit(&self.parent, tx, currency)
    }
    fn parse_deposit_address(&self, depositAddress: crate::Value, currency: crate::Value) -> crate::Value {
        crate::exchange::DerivedExchange::parse_deposit_address(&self.parent, depositAddress, currency)
    }
    fn parse_last_price(&self, entry: crate::Value, market: crate::Value) -> crate::Value {
        crate::exchange::DerivedExchange::parse_last_price(&self.parent, entry, market)
    }
    fn parse_withdrawal(&self, tx: crate::Value, currency: crate::Value) -> crate::Value {
        crate::exchange::DerivedExchange::parse_withdrawal(&self.parent, tx, currency)
    }
    fn parse_ledger_entry(&self, entry: crate::Value, currency: crate::Value) -> crate::Value {
        crate::exchange::DerivedExchange::parse_ledger_entry(&self.parent, entry, currency)
    }
    fn parse_transfer(&self, transfer: crate::Value, currency: crate::Value) -> crate::Value {
        crate::exchange::DerivedExchange::parse_transfer(&self.parent, transfer, currency)
    }
    fn parse_currency(&self, currency: crate::Value) -> crate::Value {
        crate::exchange::DerivedExchange::parse_currency(&self.parent, currency)
    }
    fn parse_bid_ask(&self, bidask: crate::Value, price_key: crate::Value, amount_key: crate::Value, market: crate::Value) -> crate::Value {
        crate::exchange::DerivedExchange::parse_bid_ask(&self.parent, bidask, price_key, amount_key, market)
    }
    fn parse_open_interest(&self, interest: crate::Value, market: crate::Value) -> crate::Value {
        crate::exchange::DerivedExchange::parse_open_interest(&self.parent, interest, market)
    }
    fn parse_liquidation(&self, liquidation: crate::Value, market: crate::Value) -> crate::Value {
        crate::exchange::DerivedExchange::parse_liquidation(&self.parent, liquidation, market)
    }
    fn parse_funding_rate_history(&self, entry: crate::Value, market: crate::Value) -> crate::Value {
        crate::exchange::DerivedExchange::parse_funding_rate_history(&self.parent, entry, market)
    }
    fn parse_margin_modification(&self, data: crate::Value, market: crate::Value) -> crate::Value {
        crate::exchange::DerivedExchange::parse_margin_modification(&self.parent, data, market)
    }
    fn parse_account(&self, account: crate::Value) -> crate::Value {
        crate::exchange::DerivedExchange::parse_account(&self.parent, account)
    }
    fn parse_my_trade(&self, trade: crate::Value, market: crate::Value) -> crate::Value {
        crate::exchange::DerivedExchange::parse_my_trade(&self.parent, trade, market)
    }
    fn parse_transaction(&self, transaction: crate::Value, currency: crate::Value) -> crate::Value {
        crate::exchange::DerivedExchange::parse_transaction(&self.parent, transaction, currency)
    }
    fn parse_borrow_interest(&self, info: crate::Value, market: crate::Value) -> crate::Value {
        crate::exchange::DerivedExchange::parse_borrow_interest(&self.parent, info, market)
    }
    fn parse_adl_rank(&self, info: crate::Value, market: crate::Value) -> crate::Value {
        crate::exchange::DerivedExchange::parse_adl_rank(&self.parent, info, market)
    }
    fn parse_income(&self, info: crate::Value, market: crate::Value) -> crate::Value {
        crate::exchange::DerivedExchange::parse_income(&self.parent, info, market)
    }
    fn parse_greeks(&self, greeks: crate::Value, market: crate::Value) -> crate::Value {
        crate::exchange::DerivedExchange::parse_greeks(&self.parent, greeks, market)
    }
    fn parse_margin_mode(&self, margin_mode: crate::Value, market: crate::Value) -> crate::Value {
        crate::exchange::DerivedExchange::parse_margin_mode(&self.parent, margin_mode, market)
    }
    fn parse_conversion(&self, conversion: crate::Value, from_currency: crate::Value, to_currency: crate::Value) -> crate::Value {
        crate::exchange::DerivedExchange::parse_conversion(&self.parent, conversion, from_currency, to_currency)
    }
    fn parse_borrow_rate(&self, info: crate::Value, currency: crate::Value) -> crate::Value {
        crate::exchange::DerivedExchange::parse_borrow_rate(&self.parent, info, currency)
    }
    fn parse_leverage(&self, leverage: crate::Value, market: crate::Value) -> crate::Value {
        crate::exchange::DerivedExchange::parse_leverage(&self.parent, leverage, market)
    }
    fn parse_market_leverage_tiers(&self, info: crate::Value, market: crate::Value) -> crate::Value {
        crate::exchange::DerivedExchange::parse_market_leverage_tiers(&self.parent, info, market)
    }
    fn parse_deposit_withdraw_fee(&self, fee: crate::Value, currency: crate::Value) -> crate::Value {
        crate::exchange::DerivedExchange::parse_deposit_withdraw_fee(&self.parent, fee, currency)
    }
    fn parse_prediction_trade(&self, trade: crate::Value, market: crate::Value) -> crate::Value {
        crate::exchange::DerivedExchange::parse_prediction_trade(&self.parent, trade, market)
    }
    fn parse_prediction_order(&self, order: crate::Value, market: crate::Value) -> crate::Value {
        crate::exchange::DerivedExchange::parse_prediction_order(&self.parent, order, market)
    }
    fn parse_prediction_position(&self, position: crate::Value, market: crate::Value) -> crate::Value {
        crate::exchange::DerivedExchange::parse_prediction_position(&self.parent, position, market)
    }
    fn create_expired_option_market(&self, symbol: crate::Value) -> crate::Value {
        crate::exchange::DerivedExchange::create_expired_option_market(&self.parent, symbol)
    }
    fn sign(&self, path: crate::Value, api: crate::Value, method: crate::Value, params: crate::Value, headers: crate::Value, body: crate::Value) -> crate::Value {
        crate::exchange::DerivedExchange::sign(&self.parent, path, api, method, params, headers, body)
    }
    fn handle_errors(&self, code: crate::Value, reason: crate::Value, url: crate::Value, method: crate::Value, headers: crate::Value, body: crate::Value, response: crate::Value, request_headers: crate::Value, request_body: crate::Value) -> crate::Value {
        crate::exchange::DerivedExchange::handle_errors(&self.parent, code, reason, url, method, headers, body, response, request_headers, request_body)
    }
}

impl crate::exchange_generated::ExchangeBase for KucoinfuturesCore {
    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 {
                "fetch_bids_asks" => self.fetch_bids_asks(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
                "parse_transfer_type" => self.parse_transfer_type(args.get(0).cloned().unwrap_or(crate::Value::Null)),
                "transfer" => self.transfer(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), args.get(3).cloned().unwrap_or(crate::Value::Null), &args.get(4..).unwrap_or(&[]).to_vec()[..]).await,
                // Go-style inheritance: an un-overridden method dispatches to the parent core.
                _ => crate::exchange_generated::ExchangeBase::call_dynamic(&mut self.parent, method, args).await,
            }
        })
    }
}
impl KucoinfuturesCore {
    /// Synchronous WS handler dispatch — routes a handler-name string (from the
    /// venue's handle_message dispatch table) to the real handler method.
    #[allow(dead_code, unreachable_patterns, clippy::all)]
    pub fn dispatch_ws_handler(&mut self, __name: &crate::Value, args: &[crate::Value]) -> crate::Value {
        let __n = match __name { crate::Value::Str(s) => s.as_str(), _ => return crate::Value::Null };
        match __n {
            "fetch_bids_asks" => { crate::exchange_stubs::enqueue_spawn("fetch_bids_asks", args.to_vec()); crate::Value::Null },
            "parse_transfer_type" => self.parse_transfer_type(args.get(0).cloned().unwrap_or(crate::Value::Null)),
            "transfer" => { crate::exchange_stubs::enqueue_spawn("transfer", args.to_vec()); crate::Value::Null },
            _ => crate::Value::Null,
        }
    }
}

impl std::ops::Deref for KucoinfuturesCore {
    type Target = crate::exchange::Exchange;
    fn deref(&self) -> &crate::exchange::Exchange { std::ops::Deref::deref(&self.parent) }
}

impl std::ops::DerefMut for KucoinfuturesCore {
    fn deref_mut(&mut self) -> &mut crate::exchange::Exchange { std::ops::DerefMut::deref_mut(&mut self.parent) }
}

impl KucoinfuturesCore {
    pub fn describe(&self) -> Value {
        return self.deep_extend(self.parent.describe(), &[Value::Map({
    let mut m = indexmap::IndexMap::new();
        m.insert("id".to_string(), Value::Str("kucoinfutures".to_string()));
        m.insert("name".to_string(), Value::Str("KuCoin Futures".to_string()));
        m.insert("urls".to_string(), Value::Map({
    let mut m = indexmap::IndexMap::new();
        m.insert("logo".to_string(), Value::Str("https://user-images.githubusercontent.com/1294454/147508995-9e35030a-d046-43a1-a006-6fabd981b554.jpg".to_string()));
        m.insert("www".to_string(), Value::Str("https://futures.kucoin.com/".to_string()));
        m.insert("referral".to_string(), Value::Str("https://futures.kucoin.com/?rcode=E5wkqe".to_string()));
    m
}));
        m.insert("has".to_string(), Value::Map({
    let mut m = indexmap::IndexMap::new();
        m.insert("CORS".to_string(), Value::Null);
        m.insert("spot".to_string(), Value::Bool(false));
        m.insert("margin".to_string(), Value::Bool(false));
        m.insert("swap".to_string(), Value::Bool(true));
        m.insert("future".to_string(), Value::Bool(true));
        m.insert("option".to_string(), Value::Null);
        m.insert("fetchBidsAsks".to_string(), Value::Bool(true));
    m
}));
        m.insert("options".to_string(), Value::Map({
    let mut m = indexmap::IndexMap::new();
        m.insert("fetchMarkets".to_string(), Value::Map({
    let mut m = indexmap::IndexMap::new();
        m.insert("types".to_string(), Value::List(vec![Value::Str("swap".to_string()), Value::Str("future".to_string()), Value::Str("contract".to_string())]));
        m.insert("fetchTickersFees".to_string(), Value::Bool(false));
    m
}));
        m.insert("defaultType".to_string(), Value::Str("swap".to_string()));
        m.insert("defaultAccountType".to_string(), Value::Str("contract".to_string()));
    m
}));
    m
})]);

    Value::Null
}

/*
 * @method
 * @name kucoinfutures#fetchBidsAsks
 * @description fetches the bid and ask price and volume for multiple markets
 * @param {string[]} [symbols] unified symbols of the markets to fetch the bids and asks for, all markets 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_bids_asks(&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
}));
        let mut request: Value = Value::Map({
            let mut m = indexmap::IndexMap::new();
                m.insert("method".to_string(), Value::Str("futuresPublicGetAllTickers".to_string()));
            m
        });
        let __ws_arg_0 = self.extend(request.clone(), &[params.clone()]);
        return self.fetch_tickers(&[symbols.clone(), __ws_arg_0]).await;

    Value::Null
}

/*
 * @method
 * @name kucoinfutures#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
 * @param {string} toAccount account to transfer to
 * @param {object} [params] extra parameters specific to the exchange API endpoint
 * @returns {object} a [transfer structure]{@link https://docs.ccxt.com/?id=transfer-structure}
 */
    pub async fn transfer(&mut self, mut code: Value, mut amount: Value, mut fromAccount: Value, mut toAccount: Value, optional_args: &[Value]) -> Value {
        let mut params = get_arg(optional_args, 0, Value::Map({
    let mut m = indexmap::IndexMap::new();
    m
}));
        if is_equal(&self.markets, &Value::Null) {
            self.load_markets(&[]).await;
        }
        let mut currency: Value = self.currency(code.clone());
        let mut amountToPrecision: Value = self.currency_to_precision(code.clone(), amount.clone(), &[]);
        let mut request: Value = Value::Map({
            let mut m = indexmap::IndexMap::new();
                m.insert("currency".to_string(), self.safe_string_k(currency.clone(), "id", &[]));
                m.insert("amount".to_string(), amountToPrecision.clone());
            m
        });
        let mut toAccountString: Value = self.parse_transfer_type(toAccount.clone());
        let mut response: Value = Value::Null;
        if is_equal(&toAccountString, &Value::Str("TRADE".to_string())) || is_equal(&toAccountString, &Value::Str("MAIN".to_string())) {
            add_element_to_object(&mut request, &Value::Str("recAccountType".to_string()), toAccountString.clone());
            let __ws_arg_1 = self.extend(request.clone(), &[params.clone()]);
            response = self.parent.parent.futures_private_post_transfer_out(&[__ws_arg_1]).await;
        }  else if is_equal(&toAccount, &Value::Str("future".to_string())) || is_equal(&toAccount, &Value::Str("swap".to_string())) || is_equal(&toAccount, &Value::Str("contract".to_string())) {
            add_element_to_object(&mut request, &Value::Str("payAccountType".to_string()), self.parse_transfer_type(fromAccount.clone()));
            let __ws_arg_2 = self.extend(request.clone(), &[params.clone()]);
            response = self.parent.parent.futures_private_post_transfer_in(&[__ws_arg_2]).await;
        }  else {
            panic!("{}", crate::exchange_errors::bad_request(add(&self.id, &Value::Str(" transfer() only supports transfers between future/swap, spot and funding accounts".to_string()))));
        }
        let mut data: Value = self.safe_dict_k(response.clone(), "data", &[Value::Map({
            let mut m = indexmap::IndexMap::new();
            m
        })]);
        let __ws_arg_3 = self.parse_transfer(data.clone(), &[currency.clone()]);
        let __ws_arg_4 = self.parse_number(amountToPrecision.clone(), &[]);
        return self.extend(__ws_arg_3, &[Value::Map({
    let mut m = indexmap::IndexMap::new();
        m.insert("amount".to_string(), __ws_arg_4);
        m.insert("fromAccount".to_string(), fromAccount.clone());
        m.insert("toAccount".to_string(), toAccount.clone());
    m
})]);

    Value::Null
}

    pub fn parse_transfer_type(&self, mut transferType: Value) -> Value {
        let mut transferTypes: Value = Value::Map({
            let mut m = indexmap::IndexMap::new();
                m.insert("spot".to_string(), Value::Str("TRADE".to_string()));
                m.insert("funding".to_string(), Value::Str("MAIN".to_string()));
            m
        });
        return self.safe_string_upper(transferTypes.clone(), transferType.clone(), &[transferType.clone()]);

    Value::Null
}
}