// PLEASE DO NOT EDIT THIS FILE, IT IS GENERATED AND WILL BE OVERWRITTEN:
// https://github.com/ccxt/ccxt/blob/master/CONTRIBUTING.md#how-to-contribute-code
#![allow(unused, non_snake_case, clippy::all)]
use crate::Value;
use crate::get_value;
use crate::runtime::*;
// Base methods are now trait methods (review #1: static dispatch). Bring the
// traits into scope so `self.market(...)`, `self.safe_market(...)`,
// `self.load_markets(...)`, … on this Core resolve to the base defaults.
use crate::exchange_generated::ExchangeBase;
use crate::exchange::ExchangeRuntime;
// Dynamic `this[method](...)` re-entries are emitted as
// `self.call_dynamic_checked(...)` (blanket-impl'd on every Core) so an
// unresolvable name raises NotSupported instead of yielding a silent Null.
use crate::exchange::CallDynamicChecked;
use crate::pro::*;
pub struct OnetradingCore {
pub parent: crate::exchanges::onetrading::OnetradingCore,
}
impl OnetradingCore {
pub fn new(config: Option<crate::Value>) -> Self {
let mut s = Self { parent: crate::exchanges::onetrading::OnetradingCore::new(config) };
s.init();
s
}
pub fn init(&mut self) {
let described = OnetradingCore::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 OnetradingCore {
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 OnetradingCore {
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 {
"authenticate" => self.authenticate(&args[..]).await,
"find_timeframe" => self.find_timeframe(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"handle_authentication_message" => self.handle_authentication_message(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)),
"handle_error_message" => self.handle_error_message(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)),
"handle_heartbeat" => self.handle_heartbeat(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)),
"handle_message" => { self.handle_message(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)); crate::Value::Null },
"handle_price_point_updates" => self.handle_price_point_updates(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)),
"handle_subscriptions" => self.handle_subscriptions(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)),
"parse_trading_order" => self.parse_trading_order(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_ws_ticker" => self.parse_ws_ticker(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"watch_balance" => self.watch_balance(&args[..]).await,
"watch_many" => self.watch_many(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), &args[3.min(args.len())..]).await,
"watch_my_trades" => self.watch_my_trades(&args[..]).await,
"watch_ohlcv" => self.watch_ohlcv(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"watch_order_book" => self.watch_order_book(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"watch_orders" => self.watch_orders(&args[..]).await,
"watch_ticker" => self.watch_ticker(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"watch_tickers" => self.watch_tickers(&args[..]).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 OnetradingCore {
/// 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_ref(), _ => return crate::Value::Null };
match __n {
"authenticate" => { crate::exchange_stubs::enqueue_spawn("authenticate", args.to_vec()); crate::Value::Null },
"find_timeframe" => self.find_timeframe(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"handle_account_update" => { self.handle_account_update(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)); crate::Value::Null },
"handle_authentication_message" => self.handle_authentication_message(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)),
"handle_balance_snapshot" => { self.handle_balance_snapshot(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)); crate::Value::Null },
"handle_delta" => { self.handle_delta(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)); crate::Value::Null },
"handle_deltas" => { self.handle_deltas(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)); crate::Value::Null },
"handle_error_message" => self.handle_error_message(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)),
"handle_heartbeat" => self.handle_heartbeat(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)),
"handle_message" => { self.handle_message(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)); crate::Value::Null },
"handle_ohlcv" => { self.handle_ohlcv(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)); crate::Value::Null },
"handle_order_book" => { self.handle_order_book(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)); crate::Value::Null },
"handle_orders" => { self.handle_orders(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)); crate::Value::Null },
"handle_price_point_updates" => self.handle_price_point_updates(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)),
"handle_subscriptions" => self.handle_subscriptions(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)),
"handle_ticker" => { self.handle_ticker(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)); crate::Value::Null },
"handle_trading" => { self.handle_trading(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)); crate::Value::Null },
"parse_trading_order" => self.parse_trading_order(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_ws_ticker" => self.parse_ws_ticker(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"update_balance" => { self.update_balance(args.get(0).cloned().unwrap_or(crate::Value::Null)); crate::Value::Null },
"watch_balance" => { crate::exchange_stubs::enqueue_spawn("watch_balance", args.to_vec()); crate::Value::Null },
"watch_many" => { crate::exchange_stubs::enqueue_spawn("watch_many", args.to_vec()); crate::Value::Null },
"watch_my_trades" => { crate::exchange_stubs::enqueue_spawn("watch_my_trades", args.to_vec()); crate::Value::Null },
"watch_ohlcv" => { crate::exchange_stubs::enqueue_spawn("watch_ohlcv", args.to_vec()); crate::Value::Null },
"watch_order_book" => { crate::exchange_stubs::enqueue_spawn("watch_order_book", args.to_vec()); crate::Value::Null },
"watch_orders" => { crate::exchange_stubs::enqueue_spawn("watch_orders", args.to_vec()); crate::Value::Null },
"watch_ticker" => { crate::exchange_stubs::enqueue_spawn("watch_ticker", args.to_vec()); crate::Value::Null },
"watch_tickers" => { crate::exchange_stubs::enqueue_spawn("watch_tickers", args.to_vec()); crate::Value::Null },
_ => crate::Value::Null,
}
}
}
impl std::ops::Deref for OnetradingCore {
type Target = crate::exchange::Exchange;
fn deref(&self) -> &crate::exchange::Exchange { std::ops::Deref::deref(&self.parent) }
}
impl std::ops::DerefMut for OnetradingCore {
fn deref_mut(&mut self) -> &mut crate::exchange::Exchange { std::ops::DerefMut::deref_mut(&mut self.parent) }
}
impl OnetradingCore {
pub fn describe(&self) -> Value {
return self.deep_extend(self.parent.describe(), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("has".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("ws".to_string(), Value::Bool(true));
m.insert("watchBalance".to_string(), Value::Bool(true));
m.insert("watchTicker".to_string(), Value::Bool(true));
m.insert("watchTickers".to_string(), Value::Bool(true));
m.insert("watchTrades".to_string(), Value::Bool(false));
m.insert("watchTradesForSymbols".to_string(), Value::Bool(false));
m.insert("watchMyTrades".to_string(), Value::Bool(true));
m.insert("watchOrders".to_string(), Value::Bool(true));
m.insert("watchOrderBook".to_string(), Value::Bool(true));
m.insert("watchOHLCV".to_string(), Value::Bool(true));
m
}));
m.insert("urls".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("api".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("ws".to_string(), Value::Str("wss://streams.fast.onetrading.com".into()));
m
}));
m
}));
m.insert("options".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("bp_remaining_quota".to_string(), Value::Int(200));
m.insert("timeframes".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("1m".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("unit".to_string(), Value::Str("MINUTES".into()));
m.insert("period".to_string(), Value::Int(1));
m
}));
m.insert("5m".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("unit".to_string(), Value::Str("MINUTES".into()));
m.insert("period".to_string(), Value::Int(5));
m
}));
m.insert("15m".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("unit".to_string(), Value::Str("MINUTES".into()));
m.insert("period".to_string(), Value::Int(15));
m
}));
m.insert("30m".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("unit".to_string(), Value::Str("MINUTES".into()));
m.insert("period".to_string(), Value::Int(30));
m
}));
m.insert("1h".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("unit".to_string(), Value::Str("HOURS".into()));
m.insert("period".to_string(), Value::Int(1));
m
}));
m.insert("4h".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("unit".to_string(), Value::Str("HOURS".into()));
m.insert("period".to_string(), Value::Int(4));
m
}));
m.insert("1d".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("unit".to_string(), Value::Str("DAYS".into()));
m.insert("period".to_string(), Value::Int(1));
m
}));
m.insert("1w".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("unit".to_string(), Value::Str("WEEKS".into()));
m.insert("period".to_string(), Value::Int(1));
m
}));
m.insert("1M".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("unit".to_string(), Value::Str("MONTHS".into()));
m.insert("period".to_string(), Value::Int(1));
m
}));
m
}));
m
}));
m.insert("streaming".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
}));
m
})]);
Value::Null
}
/*
* @method
* @name onetrading#watchBalance
* @see https://developers.bitpanda.com/exchange/#account-history-channel
* @description watch balance and get the amount of funds available for trading or funds locked in orders
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a [balance structure]{@link https://docs.ccxt.com/?id=balance-structure}
*/
pub async fn watch_balance(&mut self, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
self.authenticate(&[params.clone()]).await;
let mut url: Value = self.urls.as_map().and_then(|__m| __m.get("api")).cloned().unwrap_or(Value::Null).as_map().and_then(|__m| __m.get("ws")).cloned().unwrap_or(Value::Null);
let mut messageHash: Value = Value::Str("balance".into());
let mut subscribeHash: Value = Value::Str("ACCOUNT_HISTORY".into());
let mut bpRemainingQuota: Value = self.safe_integer_k(self.options.clone(), "bp_remaining_quota", &[Value::Int(200)]);
let mut subscribe: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("type".to_string(), Value::Str("SUBSCRIBE".into()));
m.insert("bp_remaining_quota".to_string(), bpRemainingQuota);
m.insert("channels".to_string(), Value::from(vec![Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("name".to_string(), Value::Str("ACCOUNT_HISTORY".into()));
m
})]));
m
});
let mut request: Value = self.deep_extend(subscribe, &[params]);
return self.watch(url, messageHash, &[request.clone(), subscribeHash, request.clone()]).await;
Value::Null
}
pub fn handle_balance_snapshot(&mut self, mut client: Value, mut message: Value) {
//
// snapshot
// {
// "account_id": "b355abb8-aaae-4fae-903c-c60ff74723c6",
// "type": "BALANCES_SNAPSHOT",
// "channel_name": "ACCOUNT_HISTORY",
// "time": "2019-04-01T13:39:17.155Z",
// "balances": [{
// "account_id": "b355abb8-aaae-4fae-903c-c60ff74723c6",
// "currency_code": "BTC",
// "change": "0.5",
// "available": "10.0",
// "locked": "1.1234567",
// "sequence": 1,
// "time": "2019-04-01T13:39:17.155Z"
// },
// {
// "account_id": "b355abb8-aaae-4fae-903c-c60ff74723c6",
// "currency_code": "ETH",
// "change": "0.5",
// "available": "10.0",
// "locked": "1.1234567",
// "sequence": 2,
// "time": "2019-04-01T13:39:17.155Z"
// }
// ]
// }
//
{ let __t = self.parse_balance(message); self.balance = __t; }
let mut messageHash: Value = Value::Str("balance".into());
client.resolve(&[self.balance.clone(), messageHash]);
}
/*
* @method
* @name onetrading#watchTicker
* @see https://developers.bitpanda.com/exchange/#market-ticker-channel
* @description watches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
* @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 watch_ticker(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
symbol = market.as_map().and_then(|__m| __m.get("symbol")).cloned().unwrap_or(Value::Null);
let mut subscriptionHash: Value = Value::Str("MARKET_TICKER".into());
let mut messageHash: Value = Value::Str(format!("{}{}", Value::Str("ticker.".into()), symbol).into());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("type".to_string(), Value::Str("SUBSCRIBE".into()));
m.insert("channels".to_string(), Value::from(vec![Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("name".to_string(), Value::Str("MARKET_TICKER".into()));
m.insert("price_points_mode".to_string(), Value::Str("INLINE".into()));
m
})]));
m
});
return self.watch_many(messageHash, request, subscriptionHash, &[Value::from(vec![symbol]), params]).await;
Value::Null
}
/*
* @method
* @name onetrading#watchTickers
* @see https://developers.bitpanda.com/exchange/#market-ticker-channel
* @description watches price tickers, a statistical calculation with the information for all markets or those specified.
* @param {string} symbols unified symbols of the markets to fetch the ticker for
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} an array of [ticker structure]{@link https://docs.ccxt.com/?id=ticker-structure}
*/
pub async fn watch_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 (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
symbols = self.market_symbols(&[symbols.clone()]);
if (symbols == Value::Null) {
symbols = Value::from(vec![]);
}
let mut subscriptionHash: Value = Value::Str("MARKET_TICKER".into());
let mut messageHash: Value = Value::Str("tickers".into());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("type".to_string(), Value::Str("SUBSCRIBE".into()));
m.insert("channels".to_string(), Value::from(vec![Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("name".to_string(), Value::Str("MARKET_TICKER".into()));
m.insert("price_points_mode".to_string(), Value::Str("INLINE".into()));
m
})]));
m
});
let mut tickers: Value = self.watch_many(messageHash, request, subscriptionHash, &[symbols.clone(), params]).await;
return self.filter_by_array(tickers, Value::Str("symbol".into()), &[symbols]);
Value::Null
}
pub fn handle_ticker(&mut self, mut client: Value, mut message: Value) {
let __message_empty = indexmap::IndexMap::new();
let message = message.as_map().unwrap_or(&__message_empty);
//
// {
// "ticker_updates": [{
// "instrument": "ETH_BTC",
// "last_price": "0.053752",
// "price_change": "0.000623",
// "price_change_percentage": "1.17",
// "high": "0.055",
// "low": "0.052662",
// "volume": "6.3821593247"
// }],
// "channel_name": "MARKET_TICKER",
// "type": "MARKET_TICKER_UPDATES",
// "time": "2022-06-23T16:41:00.004162Z"
// }
//
let mut tickers: Value = (match message.get("ticker_updates") { Some(__v) if matches!(__v, Value::Arr(_)) => __v.clone(), _ => Value::from(vec![]) });
let mut datetime: Value = (match message.get("time") { Some(Value::Str(__s)) if !__s.is_empty() => Value::Str(__s.clone()), Some(Value::Int(__n)) => Value::Str(__n.to_string().into()), Some(Value::Float(__f)) => Value::Str(__f.to_string().into()), _ => Value::Null });
{
let mut i: Value = Value::Int(0);
let mut __for_first_541: bool = true;
while { if !__for_first_541 { i = (match (&(i), &(Value::Int(1))) { (Value::Int(x), Value::Int(y)) => Value::Int(x + y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 + *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x + *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x + y), _ => Value::Null }); } __for_first_541 = false; i.as_f64().unwrap_or(f64::NAN) < ((tickers.len() as i64) as f64) } {
let mut ticker: Value = tickers.as_array().and_then(|__arr| match &i { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null);
let mut marketId: Value = self.safe_string_k(ticker.clone(), "instrument", &[]);
let mut symbol: Value = self.safe_symbol(marketId, &[]);
{ let __be_tmp = self.parse_ws_ticker(ticker, &[]); if let Value::Dict(__d) = &mut self.tickers { std::sync::Arc::make_mut(__d).insert(crate::runtime::stringify_param(&symbol), __be_tmp); } }
let mut timestamp: Value = self.parse8601(datetime.clone());
add_element_to_object(get_value_mut(&mut self.tickers, &symbol), &Value::Str("timestamp".into()), timestamp.clone());
{ let __be_tmp = self.iso8601(timestamp); add_element_to_object(get_value_mut(&mut self.tickers, &symbol), &Value::Str("datetime".into()), __be_tmp); };
client.resolve(&[get_value(&self.tickers, &symbol), Value::Str(format!("{}{}", Value::Str("ticker.".into()), symbol).into())]);
}
}
client.resolve(&[self.tickers.clone(), Value::Str("tickers".into())]);
}
pub fn parse_ws_ticker(&self, mut ticker: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// {
// "instrument": "ETH_BTC",
// "last_price": "0.053752",
// "price_change": "-0.000623",
// "price_change_percentage": "-1.17",
// "high": "0.055",
// "low": "0.052662",
// "volume": "6.3821593247"
// }
//
let mut marketId: Value = self.safe_string_k(ticker.clone(), "instrument", &[]);
return self.safe_ticker(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), self.safe_symbol(marketId, &[market.clone()]));
m.insert("timestamp".to_string(), Value::Null);
m.insert("datetime".to_string(), Value::Null);
m.insert("high".to_string(), self.safe_string_k(ticker.clone(), "high", &[]));
m.insert("low".to_string(), self.safe_string_k(ticker.clone(), "low", &[]));
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(), self.safe_string_k(ticker.clone(), "last_price", &[]));
m.insert("last".to_string(), self.safe_string_k(ticker.clone(), "last_price", &[]));
m.insert("previousClose".to_string(), Value::Null);
m.insert("change".to_string(), self.safe_string_k(ticker.clone(), "price_change", &[]));
m.insert("percentage".to_string(), self.safe_string_k(ticker.clone(), "price_change_percentage", &[]));
m.insert("average".to_string(), Value::Null);
m.insert("baseVolume".to_string(), Value::Null);
m.insert("quoteVolume".to_string(), self.safe_number_k(ticker.clone(), "volume", &[]));
m.insert("info".to_string(), ticker);
m
}), &[market]);
Value::Null
}
/*
* @method
* @name onetrading#watchMyTrades
* @see https://developers.bitpanda.com/exchange/#account-history-channel
* @description get the list of trades associated with the user
* @param {string} symbol unified symbol of the market to fetch trades for. Use 'any' to watch all trades
* @param {int} [since] timestamp in ms of the earliest trade to fetch
* @param {int} [limit] the maximum amount of trades to fetch
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object[]} a list of [trade structures]{@link https://docs.ccxt.com/?id=public-trades}
*/
pub async fn watch_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 (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut messageHash: Value = Value::Str("myTrades".into());
if (symbol != Value::Null) {
let mut market: Value = self.market(symbol.clone());
symbol = market.as_map().and_then(|__m| __m.get("symbol")).cloned().unwrap_or(Value::Null);
messageHash = Value::Str(format!("{}{}", messageHash, Value::Str(format!("{}{}", Value::Str(":".into()), symbol).into())).into());
}
self.authenticate(&[params.clone()]).await;
let mut url: Value = self.urls.as_map().and_then(|__m| __m.get("api")).cloned().unwrap_or(Value::Null).as_map().and_then(|__m| __m.get("ws")).cloned().unwrap_or(Value::Null);
let mut subscribeHash: Value = Value::Str("ACCOUNT_HISTORY".into());
let mut bpRemainingQuota: Value = self.safe_integer_k(self.options.clone(), "bp_remaining_quota", &[Value::Int(200)]);
let mut subscribe: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("type".to_string(), Value::Str("SUBSCRIBE".into()));
m.insert("bp_remaining_quota".to_string(), bpRemainingQuota);
m.insert("channels".to_string(), Value::from(vec![Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("name".to_string(), Value::Str("ACCOUNT_HISTORY".into()));
m
})]));
m
});
let mut request: Value = self.deep_extend(subscribe, &[params.clone()]);
let mut trades: Value = self.watch(url, messageHash, &[request.clone(), subscribeHash, request.clone()]).await;
if is_true(&self.newUpdates) {
limit = trades.get_limit(symbol.clone(), limit.clone());
}
trades = self.filter_by_symbol_since_limit(trades.clone(), &[symbol.clone(), since.clone(), limit.clone()]);
let mut numTrades: Value = get_array_length(&trades);
if is_equal(&numTrades, &Value::Int(0)) {
return Box::pin(self.watch_my_trades(&[symbol, since, limit, params])).await;
}
return trades;
Value::Null
}
/*
* @method
* @name onetrading#watchOrderBook
* @see https://docs.onetrading.com/websocket/orderbook/introduction
* @description watches information on open orders with bid (buy) and ask (sell) prices, volumes and other data
* @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 watch_order_book(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut limit = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
symbol = market.as_map().and_then(|__m| __m.get("symbol")).cloned().unwrap_or(Value::Null);
let mut messageHash: Value = Value::Str(format!("{}{}", Value::Str("book:".into()), symbol).into());
let mut subscriptionHash: Value = Value::Str("ORDER_BOOK".into());
let mut depth: Value = Value::Int(0);
if (limit != Value::Null) {
depth = limit.clone();
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("type".to_string(), Value::Str("SUBSCRIBE".into()));
m.insert("channels".to_string(), Value::from(vec![Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("name".to_string(), Value::Str("ORDER_BOOK".into()));
m.insert("depth".to_string(), depth);
m
})]));
m
});
let mut orderbook: Value = self.watch_many(messageHash, request, subscriptionHash, &[Value::from(vec![symbol]), params]).await;
return orderbook.limit();
Value::Null
}
pub fn handle_order_book(&mut self, mut client: Value, mut message: Value) {
let __pro_message_arc: std::sync::Arc<indexmap::IndexMap<String, Value>> = (match &message { Value::Dict(__d) => __d.clone(), _ => std::sync::Arc::new(indexmap::IndexMap::new()) });
let __pro_message: &indexmap::IndexMap<String, Value> = &__pro_message_arc;
//
// snapshot
// {
// "instrument_code": "ETH_BTC",
// "bids": [
// ['0.053595', "4.5352"],
// ...
// ],
// "asks": [
// ['0.055455', "0.2821"],
// ...
// ],
// "channel_name": "ORDER_BOOK",
// "type": "ORDER_BOOK_SNAPSHOT",
// "time": "2022-06-23T15:38:02.196282Z"
// }
//
// update
// {
// "instrument_code": "ETH_BTC",
// "changes": [
// ["BUY", '0.053593', "8.0587"]
// ],
// "channel_name": "ORDER_BOOK",
// "type": "ORDER_BOOK_UPDATE",
// "time": "2022-06-23T15:38:02.751301Z"
// }
//
let mut type_var: Value = (match __pro_message.get("type").cloned() { Some(Value::Str(__s)) if !__s.is_empty() => Value::Str(__s), Some(Value::Int(__n)) => Value::Str(__n.to_string().into()), Some(Value::Float(__f)) => Value::Str(__f.to_string().into()), _ => Value::Null });
let mut marketId: Value = (match __pro_message.get("instrument_code").cloned() { Some(Value::Str(__s)) if !__s.is_empty() => Value::Str(__s), Some(Value::Int(__n)) => Value::Str(__n.to_string().into()), Some(Value::Float(__f)) => Value::Str(__f.to_string().into()), _ => Value::Null });
let mut symbol: Value = self.safe_symbol(marketId, &[]);
let mut dateTime: Value = (match __pro_message.get("time").cloned() { Some(Value::Str(__s)) if !__s.is_empty() => Value::Str(__s), Some(Value::Int(__n)) => Value::Str(__n.to_string().into()), Some(Value::Float(__f)) => Value::Str(__f.to_string().into()), _ => Value::Null });
let mut timestamp: Value = self.parse8601(dateTime);
let mut channel: Value = Value::Str(format!("{}{}", Value::Str("book:".into()), symbol).into());
let mut orderbook: Value = self.safe_value(self.orderbooks.clone(), symbol.clone(), &[]);
if (orderbook == Value::Null) {
orderbook = self.order_book(&[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
}
if (type_var.as_str() == Some("ORDER_BOOK_SNAPSHOT")) {
let mut snapshot: Value = self.parse_order_book(message, symbol.clone(), &[timestamp.clone(), Value::Str("bids".into()), Value::Str("asks".into())]);
orderbook.reset(snapshot);
} else if (type_var.as_str() == Some("ORDER_BOOK_UPDATE")) {
let mut changes: Value = (match __pro_message.get("changes").cloned() { Some(__v) if matches!(__v, Value::Arr(_)) => __v, _ => Value::from(vec![]) });
self.handle_deltas(orderbook.clone(), changes);
} else {
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" watchOrderBook() did not recognize message type ".into())).into()), type_var)));
}
add_element_to_object(&mut orderbook, &Value::Str("nonce".into()), timestamp.clone());
add_element_to_object(&mut orderbook, &Value::Str("timestamp".into()), timestamp.clone());
add_element_to_object(&mut orderbook, &Value::Str("datetime".into()), self.iso8601(timestamp));
if let Value::Dict(__d) = &mut self.orderbooks { std::sync::Arc::make_mut(__d).insert(crate::runtime::stringify_param(&symbol), orderbook.clone()); }
client.resolve(&[orderbook, channel]);
}
pub fn handle_delta(&self, mut orderbook: Value, mut delta: Value) {
//
// [ 'BUY', "0.053595", "0" ]
//
let mut bidAsk: Value = self.parse_order_book_bid_ask(delta.clone(), &[Value::Int(1), Value::Int(2)]);
let mut type_var: Option<String> = self.safe_string(delta.clone(), Value::Int(0), &[]).as_str().map(str::to_owned);
if (type_var.as_deref() == Some("BUY")) {
let mut bids: Value = crate::value::get_value_k(&orderbook, "bids");
bids.store_array(bidAsk.clone());
} else if (type_var.as_deref() == Some("SELL")) {
let mut asks: Value = crate::value::get_value_k(&orderbook, "asks");
asks.store_array(bidAsk);
} else {
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" watchOrderBook () received unknown change type ".into())).into()), json_stringify(&delta))));
}
}
pub fn handle_deltas(&self, mut orderbook: Value, mut deltas: Value) {
{
let mut i: Value = Value::Int(0);
let mut __for_first_542: bool = true;
while { if !__for_first_542 { i = (match (&(i), &(Value::Int(1))) { (Value::Int(x), Value::Int(y)) => Value::Int(x + y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 + *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x + *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x + y), _ => Value::Null }); } __for_first_542 = false; i.as_f64().unwrap_or(f64::NAN) < get_array_length(&deltas).as_f64().unwrap_or(f64::NAN) } {
self.handle_delta(orderbook.clone(), get_value(&deltas, &i));
}
}
}
/*
* @method
* @name onetrading#watchOrders
* @see https://developers.bitpanda.com/exchange/#account-history-channel
* @description watches information on multiple orders made by the user
* @param {string} symbol unified market symbol of the market orders were made in
* @param {int} [since] the earliest time in ms to fetch orders for
* @param {int} [limit] the maximum number of order structures to retrieve
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.channel] can listen to orders using ACCOUNT_HISTORY or TRADING
* @returns {object[]} a list of [order structures]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn watch_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 (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut messageHash: Value = Value::Str("orders".into());
if (symbol != Value::Null) {
let mut market: Value = self.market(symbol.clone());
symbol = market.as_map().and_then(|__m| __m.get("symbol")).cloned().unwrap_or(Value::Null);
messageHash = Value::Str(format!("{}{}", messageHash, Value::Str(format!("{}{}", Value::Str(":".into()), symbol).into())).into());
}
self.authenticate(&[params.clone()]).await;
let mut url: Value = self.urls.as_map().and_then(|__m| __m.get("api")).cloned().unwrap_or(Value::Null).as_map().and_then(|__m| __m.get("ws")).cloned().unwrap_or(Value::Null);
let mut subscribeHash: Value = self.safe_string_k(params.clone(), "channel", &[Value::Str("ACCOUNT_HISTORY".into())]);
let mut bpRemainingQuota: Value = self.safe_integer_k(self.options.clone(), "bp_remaining_quota", &[Value::Int(200)]);
let mut subscribe: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("type".to_string(), Value::Str("SUBSCRIBE".into()));
m.insert("bp_remaining_quota".to_string(), bpRemainingQuota);
m.insert("channels".to_string(), Value::from(vec![Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("name".to_string(), subscribeHash.clone());
m
})]));
m
});
let mut request: Value = self.deep_extend(subscribe, &[params.clone()]);
let mut orders: Value = self.watch(url, messageHash, &[request.clone(), subscribeHash, request.clone()]).await;
if is_true(&self.newUpdates) {
limit = orders.get_limit(symbol.clone(), limit.clone());
}
orders = self.filter_by_symbol_since_limit(orders.clone(), &[symbol.clone(), since.clone(), limit.clone()]);
let mut numOrders: Value = get_array_length(&orders);
if is_equal(&numOrders, &Value::Int(0)) {
return Box::pin(self.watch_orders(&[symbol, since, limit, params])).await;
}
return orders;
Value::Null
}
pub fn handle_trading(&mut self, mut client: Value, mut message: Value) {
//
// {
// "order_book_sequence": 892925263,
// "side": "BUY",
// "amount": "0.00046",
// "trade_id": "d67b9b69-ab76-480f-9ba3-b33582202836",
// "matched_as": "TAKER",
// "matched_amount": "0.00046",
// "matched_price": "22231.08",
// "instrument_code": "BTC_EUR",
// "order_id": "7b39f316-0a71-4bfd-adda-3062e6f0bd37",
// "remaining": "0.0",
// "channel_name": "TRADING",
// "type": "FILL",
// "time": "2022-07-21T12:41:22.883341Z"
// }
//
// {
// "status": "CANCELLED",
// "order_book_sequence": 892928424,
// "amount": "0.0003",
// "side": "SELL",
// "price": "50338.65",
// "instrument_code": "BTC_EUR",
// "order_id": "b3994a08-a9e8-4a79-a08b-33e3480382df",
// "remaining": "0.0003",
// "channel_name": "TRADING",
// "type": "DONE",
// "time": "2022-07-21T12:44:24.267000Z"
// }
//
// {
// "order_book_sequence": 892934476,
// "side": "SELL",
// "amount": "0.00051",
// "price": "22349.02",
// "instrument_code": "BTC_EUR",
// "order_id": "1c6c585c-ec3d-4b94-9292-6c3d04a31dc8",
// "remaining": "0.00051",
// "channel_name": "TRADING",
// "type": "BOOKED",
// "time": "2022-07-21T12:50:10.093000Z"
// }
//
if (self.orders.clone() == Value::Null) {
let mut limit: Value = self.safe_integer_k(self.options.clone(), "ordersLimit", &[Value::Int(1000)]);
self.orders = ArrayCacheBySymbolById::new(limit);
}
let mut order: Value = self.parse_trading_order(message, &[]);
let mut orders: Value = self.orders.clone();
orders.append(order.clone());
client.resolve(&[self.orders.clone(), Value::Str(format!("{}{}", Value::Str("orders:".into()), order.as_map().and_then(|__m| __m.get("symbol")).cloned().unwrap_or(Value::Null)).into())]);
client.resolve(&[self.orders.clone(), Value::Str("orders".into())]);
}
pub fn parse_trading_order(&self, mut order: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// {
// "order_book_sequence": 892925263,
// "side": "BUY",
// "amount": "0.00046",
// "trade_id": "d67b9b69-ab76-480f-9ba3-b33582202836",
// "matched_as": "TAKER",
// "matched_amount": "0.00046",
// "matched_price": "22231.08",
// "instrument_code": "BTC_EUR",
// "order_id": "7b39f316-0a71-4bfd-adda-3062e6f0bd37",
// "remaining": "0.0",
// "channel_name": "TRADING",
// "type": "FILL",
// "time": "2022-07-21T12:41:22.883341Z"
// }
//
// {
// "status": "CANCELLED",
// "order_book_sequence": 892928424,
// "amount": "0.0003",
// "side": "SELL",
// "price": "50338.65",
// "instrument_code": "BTC_EUR",
// "order_id": "b3994a08-a9e8-4a79-a08b-33e3480382df",
// "remaining": "0.0003",
// "channel_name": "TRADING",
// "type": "DONE",
// "time": "2022-07-21T12:44:24.267000Z"
// }
//
// {
// "order_book_sequence": 892934476,
// "side": "SELL",
// "amount": "0.00051",
// "price": "22349.02",
// "instrument_code": "BTC_EUR",
// "order_id": "1c6c585c-ec3d-4b94-9292-6c3d04a31dc8",
// "remaining": "0.00051",
// "channel_name": "TRADING",
// "type": "BOOKED",
// "time": "2022-07-21T12:50:10.093000Z"
// }
//
// {
// "type":"UPDATE",
// "channel_name": "TRADING",
// "instrument_code": "BTC_EUR",
// "order_id": "1e842f13-762a-4745-9f3b-07f1b43e7058",
// "client_id": "d75fb03b-b599-49e9-b926-3f0b6d103206",
// "time": "2020-01-11T01:01:01.999Z",
// "remaining": "1.23456",
// "order_book_sequence": 42,
// "status": "APPLIED",
// "amount": "1.35756",
// "amount_delta": "0.123",
// "modification_id": "cc0eed67-aecc-4fb4-a625-ff3890ceb4cc"
// }
// tracked
// {
// "type": "STOP_TRACKED",
// "channel_name": "TRADING",
// "instrument_code": "BTC_EUR",
// "order_id": "1e842f13-762a-4745-9f3b-07f1b43e7058",
// "client_id": "d75fb03b-b599-49e9-b926-3f0b6d103206",
// "time": "2020-01-11T01:01:01.999Z",
// "remaining": "1.23456",
// "order_book_sequence": 42,
// "trigger_price": "12345.67",
// "current_price": "11111.11"
// }
//
// {
// "type": "STOP_TRIGGERED",
// "channel_name": "TRADING",
// "instrument_code": "BTC_EUR",
// "order_id": "1e842f13-762a-4745-9f3b-07f1b43e7058",
// "client_id": "d75fb03b-b599-49e9-b926-3f0b6d103206",
// "time": "2020-01-11T01:01:01.999Z",
// "remaining": "1.23456",
// "order_book_sequence": 42,
// "price": "13333.33"
// }
//
let mut datetime: Value = self.safe_string_k(order.clone(), "time", &[]);
let mut marketId: Value = self.safe_string_k(order.clone(), "instrument_code", &[]);
let mut symbol: Value = self.safe_symbol(marketId, &[market.clone(), Value::Str("_".into())]);
return self.safe_order(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), self.safe_string_k(order.clone(), "order_id", &[]));
m.insert("clientOrderId".to_string(), self.safe_string_k(order.clone(), "client_id", &[]));
m.insert("info".to_string(), order.clone());
m.insert("timestamp".to_string(), self.parse8601(datetime.clone()));
m.insert("datetime".to_string(), datetime);
m.insert("lastTradeTimestamp".to_string(), Value::Null);
m.insert("symbol".to_string(), symbol);
m.insert("type".to_string(), Value::Null);
m.insert("timeInForce".to_string(), Value::Null);
m.insert("postOnly".to_string(), Value::Null);
m.insert("side".to_string(), self.safe_string_lower_k(order.clone(), "side", &[]));
m.insert("price".to_string(), self.safe_number2(order.clone(), Value::Str("price".into()), Value::Str("matched_price".into()), &[]));
m.insert("stopPrice".to_string(), self.safe_number_k(order.clone(), "trigger_price", &[]));
m.insert("amount".to_string(), self.safe_number_k(order.clone(), "amount", &[]));
m.insert("cost".to_string(), Value::Null);
m.insert("average".to_string(), Value::Null);
m.insert("filled".to_string(), Value::Null);
m.insert("remaining".to_string(), self.safe_string_k(order.clone(), "remaining", &[]));
m.insert("status".to_string(), self.parse_trading_order_status(self.safe_string_k(order, "status", &[])).map(|__s| Value::Str(__s.into())).unwrap_or(Value::Null));
m.insert("fee".to_string(), Value::Null);
m.insert("trades".to_string(), Value::Null);
m
}), &[market]);
Value::Null
}
pub fn parse_trading_order_status(&self, mut status: Value) -> Option<String> {
let mut statuses: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("CANCELLED".to_string(), Value::Str("canceled".into()));
m.insert("SELF_TRADE".to_string(), Value::Str("rejected".into()));
m.insert("FILLED_FULLY".to_string(), Value::Str("closed".into()));
m.insert("INSUFFICIENT_FUNDS".to_string(), Value::Str("rejected".into()));
m.insert("INSUFFICIENT_LIQUIDITY".to_string(), Value::Str("rejected".into()));
m.insert("TIME_TO_MARKET_EXCEEDED".to_string(), Value::Str("rejected".into()));
m.insert("LAST_PRICE_UNKNOWN".to_string(), Value::Str("rejected".into()));
m
});
return self.safe_string(statuses, status.clone(), &[status.clone()]).as_str().map(str::to_owned);
}
pub fn handle_orders(&mut self, mut client: Value, mut message: Value) {
let __message_empty = indexmap::IndexMap::new();
let message = message.as_map().unwrap_or(&__message_empty);
//
// snapshot
// {
// "account_id": "4920221a-48dc-423e-b336-bb65baccc7bd",
// "orders": [{
// "order": {
// "order_id": "30e2de8f-9a34-472f-bcf8-3af4b7757626",
// "account_holder": "49202c1a-48dc-423e-b336-bb65baccc7bd",
// "account_id": "49202c1a-48dc-423e-b336-bb65baccc7bd",
// "instrument_code": "BTC_EUR",
// "time": "2022-06-28T06:10:02.587345Z",
// "side": "SELL",
// "price": "19645.48",
// "amount": "0.00052",
// "filled_amount": "0.00052",
// "type": "MARKET",
// "sequence": 7633339971,
// "status": "FILLED_FULLY",
// "average_price": "19645.48",
// "is_post_only": false,
// "order_book_sequence": 866885897,
// "time_last_updated": "2022-06-28T06:10:02.766983Z",
// "update_modification_sequence": 866885897
// },
// "trades": [{
// "fee": {
// "fee_amount": "0.01532347",
// "fee_currency": "EUR",
// "fee_percentage": "0.15",
// "fee_group_id": "default",
// "fee_type": "TAKER",
// "running_trading_volume": "0.0",
// "collection_type": "STANDARD"
// },
// "trade": {
// "trade_id": "d83e302e-0b3a-4269-aa7d-ecf007cbe577",
// "order_id": "30e2de8f-9a34-472f-bcf8-3af4b7757626",
// "account_holder": "49203c1a-48dc-423e-b336-bb65baccc7bd",
// "account_id": "4920221a-48dc-423e-b336-bb65baccc7bd",
// "amount": "0.00052",
// "side": "SELL",
// "instrument_code": "BTC_EUR",
// "price": "19645.48",
// "time": "2022-06-28T06:10:02.693246Z",
// "price_tick_sequence": 0,
// "sequence": 7633339971
// }
// }]
// }],
// "channel_name": "ACCOUNT_HISTORY",
// "type": "INACTIVE_ORDERS_SNAPSHOT",
// "time": "2022-06-28T06:11:52.469242Z"
// }
//
//
if (self.orders.clone() == Value::Null) {
let mut limit: Value = self.safe_integer_k(self.options.clone(), "ordersLimit", &[Value::Int(1000)]);
self.orders = ArrayCacheBySymbolById::new(limit.clone());
}
if (self.myTrades.clone() == Value::Null) {
let mut limit: Value = self.safe_integer_k(self.options.clone(), "tradesLimit", &[Value::Int(1000)]);
self.myTrades = ArrayCacheBySymbolById::new(limit);
}
let mut rawOrders: Value = (match message.get("orders") { Some(__v) if matches!(__v, Value::Arr(_)) => __v.clone(), _ => Value::from(vec![]) });
let mut rawOrdersLength: f64 = ((rawOrders.len() as i64) as f64);
if (rawOrdersLength == 0.0) {
return;
}
let mut orders: Value = self.orders.clone();
{
let mut i: Value = Value::Int(0);
let mut __for_first_544: bool = true;
while { if !__for_first_544 { i = (match (&(i), &(Value::Int(1))) { (Value::Int(x), Value::Int(y)) => Value::Int(x + y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 + *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x + *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x + y), _ => Value::Null }); } __for_first_544 = false; i.as_f64().unwrap_or(f64::NAN) < ((rawOrders.len() as i64) as f64) } {
let mut order: Value = self.parse_order(rawOrders.as_array().and_then(|__arr| match &i { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null), &[]);
let mut symbol: Value = self.safe_string_k(order.clone(), "symbol", &[Value::Str("".into())]);
orders.append(order);
client.resolve(&[self.orders.clone(), Value::Str(format!("{}{}", Value::Str("orders:".into()), symbol).into())]);
let mut rawTrades: Value = self.safe_list(rawOrders.as_array().and_then(|__arr| match &i { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null), Value::Str("trades".into()), &[Value::from(vec![])]);
{
let mut ii: Value = Value::Int(0);
let mut __for_first_543: bool = true;
while { if !__for_first_543 { ii = (match (&(ii), &(Value::Int(1))) { (Value::Int(x), Value::Int(y)) => Value::Int(x + y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 + *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x + *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x + y), _ => Value::Null }); } __for_first_543 = false; ii.as_f64().unwrap_or(f64::NAN) < ((rawTrades.len() as i64) as f64) } {
let mut trade: Value = self.parse_trade(rawTrades.as_array().and_then(|__arr| match &ii { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null), &[]);
symbol = self.safe_string_k(trade.clone(), "symbol", &[symbol.clone()]);
self.myTrades.append(trade);
client.resolve(&[self.myTrades.clone(), Value::Str(format!("{}{}", Value::Str("myTrades:".into()), symbol).into())]);
}
}
}
}
client.resolve(&[self.orders.clone(), Value::Str("orders".into())]);
client.resolve(&[self.myTrades.clone(), Value::Str("myTrades".into())]);
}
pub fn handle_account_update(&mut self, mut client: Value, mut message: Value) {
let __message_empty = indexmap::IndexMap::new();
let message = message.as_map().unwrap_or(&__message_empty);
//
// order created
// {
// "account_id": "49302c1a-48dc-423e-b336-bb65baccc7bd",
// "sequence": 7658332018,
// "update": {
// "type": "ORDER_CREATED",
// "activity": "TRADING",
// "account_holder": "43202c1a-48dc-423e-b336-bb65baccc7bd",
// "account_id": "49202c1a-48dc-423e-b336-bb65baccc7bd",
// "order_id": "8893fd69-5ebd-496b-aaa4-269b4c18aa77",
// "time": "2022-06-29T04:33:29.661257Z",
// "order": {
// "time_in_force": "GOOD_TILL_CANCELLED",
// "is_post_only": false,
// "order_id": "8892fd69-5ebd-496b-aaa4-269b4c18aa77",
// "account_holder": "43202c1a-48dc-423e-b336-bb65baccc7bd",
// "account_id": "49302c1a-48dc-423e-b336-bb65baccc7bd",
// "instrument_code": "BTC_EUR",
// "time": "2022-06-29T04:33:29.656896Z",
// "side": "SELL",
// "price": "50338.65",
// "amount": "0.00021",
// "filled_amount": "0.0",
// "type": "LIMIT"
// },
// "locked": {
// "currency_code": "BTC",
// "amount": "0.00021",
// "new_available": "0.00017",
// "new_locked": "0.00021"
// },
// "id": "26e9c36a-b231-4bb0-a686-aa915a2fc9e6",
// "sequence": 7658332018
// },
// "channel_name": "ACCOUNT_HISTORY",
// "type": "ACCOUNT_UPDATE",
// "time": "2022-06-29T04:33:29.684517Z"
// }
//
// order rejected
// {
// "account_id": "49302c1a-48dc-423e-b336-bb65baccc7bd",
// "sequence": 7658332018,
// "update": {
// "id": "d3fe6025-5b27-4df6-a957-98b8d131cb9d",
// "type": "ORDER_REJECTED",
// "activity": "TRADING",
// "account_id": "b355abb8-aaae-4fae-903c-c60ff74723c6",
// "sequence": 0,
// "timestamp": "2018-08-01T13:39:15.590Z",
// "reason": "INSUFFICIENT_FUNDS",
// "order_id": "6f991342-da2c-45c6-8830-8bf519cfc8cc",
// "client_id": "fb497387-8223-4111-87dc-66a86f98a7cf",
// "unlocked": {
// "currency_code": "BTC",
// "amount": "1.5",
// "new_locked": "2.0",
// "new_available": "1.5"
// }
// }
// }
//
// order closed
// {
// "account_id": "49202c1a-48dc-423e-b336-bb65baccc7bd",
// "sequence": 7658471216,
// "update": {
// "type": "ORDER_CLOSED",
// "activity": "TRADING",
// "account_holder": "49202c1a-48dc-423e-b336-bb65baccc7bd",
// "account_id": "49202c1a-48dc-423e-b336-bb65baccc7bd",
// "time": "2022-06-29T04:43:57.169616Z",
// "order_id": "8892fd69-5ebd-496b-aaa4-269b4c18aa77",
// "unlocked": {
// "currency_code": "BTC",
// "amount": "0.00021",
// "new_available": "0.00038",
// "new_locked": "0.0"
// },
// "order_book_sequence": 867964191,
// "id": "26c5e1d7-65ba-4a11-a661-14c0130ff484",
// "sequence": 7658471216
// },
// "channel_name": "ACCOUNT_HISTORY",
// "type": "ACCOUNT_UPDATE",
// "time": "2022-06-29T04:43:57.182153Z"
// }
//
// trade settled
// {
// "account_id": "49202c1a-48dc-423e-b336-bb65baccc7bd",
// "sequence": 7658502878,
// "update": {
// "type": "TRADE_SETTLED",
// "activity": "TRADING",
// "account_holder": "49202c1a-48dc-423e-b336-bb65baccc7bd",
// "account_id": "49202c1a-48dc-423e-b336-bb65baccc7bd",
// "time": "2022-06-29T04:46:12.933091Z",
// "order_id": "ad19951a-b616-401d-a062-8d0609f038a4",
// "order_book_sequence": 867965579,
// "filled_amount": "0.00052",
// "order": {
// "amount": "0.00052",
// "filled_amount": "0.00052"
// },
// "trade": {
// "trade_id": "21039eb9-2df0-4227-be2d-0ea9b691ac66",
// "order_id": "ad19951a-b616-401d-a062-8d0609f038a4",
// "account_holder": "49202c1a-48dc-423e-b336-bb65baccc7bd",
// "account_id": "49202c1a-48dc-423e-b336-bb65baccc7bd",
// "amount": "0.00052",
// "side": "BUY",
// "instrument_code": "BTC_EUR",
// "price": "19309.29",
// "time": "2022-06-29T04:46:12.870581Z",
// "price_tick_sequence": 0
// },
// "fee": {
// "fee_amount": "0.00000078",
// "fee_currency": "BTC",
// "fee_percentage": "0.15",
// "fee_group_id": "default",
// "fee_type": "TAKER",
// "running_trading_volume": "0.00052",
// "collection_type": "STANDARD"
// },
// "spent": {
// "currency_code": "EUR",
// "amount": "10.0408308",
// "new_available": "0.0",
// "new_locked": "0.15949533"
// },
// "credited": {
// "currency_code": "BTC",
// "amount": "0.00051922",
// "new_available": "0.00089922",
// "new_locked": "0.0"
// },
// "unlocked": {
// "currency_code": "EUR",
// "amount": "0.0",
// "new_available": "0.0",
// "new_locked": "0.15949533"
// },
// "id": "22b40199-2508-4176-8a14-d4785c933444",
// "sequence": 7658502878
// },
// "channel_name": "ACCOUNT_HISTORY",
// "type": "ACCOUNT_UPDATE",
// "time": "2022-06-29T04:46:12.941837Z"
// }
//
// Trade Settled with BEST fee collection enabled
// {
// "account_id": "49302c1a-48dc-423e-b336-bb65baccc7bd",
// "sequence": 7658951984,
// "update": {
// "id": "70e00504-d892-456f-9aae-4da7acb36aac",
// "sequence": 361792,
// "order_book_sequence": 123456,
// "type": "TRADE_SETTLED",
// "activity": "TRADING",
// "account_id": "379a12c0-4560-11e9-82fe-2b25c6f7d123",
// "time": "2019-10-22T12:09:55.731Z",
// "order_id": "9fcdd91c-7f6e-45f4-9956-61cddba55de5",
// "client_id": "fb497387-8223-4111-87dc-66a86f98a7cf",
// "order": {
// "amount": "0.5",
// "filled_amount": "0.5"
// },
// "trade": {
// "trade_id": "a828b63e-b2cb-48f0-8d99-8fc22cf98e08",
// "order_id": "9fcdd91c-7f6e-45f4-9956-61cddba55de5",
// "account_id": "379a12c0-4560-11e9-82fe-2b25c6f7d123",
// "amount": "0.5",
// "side": "BUY",
// "instrument_code": "BTC_EUR",
// "price": "7451.6",
// "time": "2019-10-22T12:09:55.667Z"
// },
// "fee": {
// "fee_amount": "23.28625",
// "fee_currency": "BEST",
// "fee_percentage": "0.075",
// "fee_group_id": "default",
// "fee_type": "TAKER",
// "running_trading_volume": "0.10058",
// "collection_type": "BEST",
// "applied_best_eur_rate": "1.04402"
// },
// "spent": {
// "currency_code": "EUR",
// "amount": "3725.8",
// "new_available": "14517885.0675703028781",
// "new_locked": "2354.882"
// },
// "spent_on_fees": {
// "currency_code": "BEST",
// "amount": "23.28625",
// "new_available": "9157.31375",
// "new_locked": "0.0"
// },
// "credited": {
// "currency_code": "BTC",
// "amount": "0.5",
// "new_available": "5839.89633700481",
// "new_locked": "0.0"
// },
// "unlocked": {
// "currency_code": "EUR",
// "amount": "0.15",
// "new_available": "14517885.0675703028781",
// "new_locked": "2354.882"
// }
// }
// "channel_name": "ACCOUNT_HISTORY",
// "type": "ACCOUNT_UPDATE",
// "time": "2022-06-29T05:18:51.760338Z"
// }
//
if (self.orders.clone() == Value::Null) {
let mut limit: Value = self.safe_integer_k(self.options.clone(), "ordersLimit", &[Value::Int(1000)]);
self.orders = ArrayCacheBySymbolById::new(limit.clone());
}
if (self.myTrades.clone() == Value::Null) {
let mut limit: Value = self.safe_integer_k(self.options.clone(), "tradesLimit", &[Value::Int(1000)]);
self.myTrades = ArrayCacheBySymbolById::new(limit);
}
let mut symbol: Value = Value::Null;
let mut orders: Value = self.orders.clone();
let mut update: Value = (match message.get("update") { Some(__v) if matches!(__v, Value::Dict(_)) => __v.clone(), _ => Value::Map({
let mut m = indexmap::IndexMap::new();
m
}) });
let mut updateType: Value = self.safe_string_k(update.clone(), "type", &[]);
if (updateType.as_str() == Some("ORDER_REJECTED")) || (updateType.as_str() == Some("ORDER_CLOSED")) || (updateType.as_str() == Some("STOP_ORDER_TRIGGERED")) {
let mut orderId: Value = self.safe_string_k(update.clone(), "order_id", &[]);
let mut datetime: Value = self.safe_string2(update.clone(), Value::Str("time".into()), Value::Str("timestamp".into()), &[]);
let mut previousOrderArray: Value = self.filter_by_array(self.orders.clone(), Value::Str("id".into()), &[orderId.clone(), Value::Bool(false)]);
let mut previousOrder: Value = self.safe_dict(previousOrderArray, Value::Int(0), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
symbol = previousOrder.as_map().and_then(|__m| __m.get("symbol")).cloned().unwrap_or(Value::Null);
let mut filled: Value = self.safe_string_k(update.clone(), "filled_amount", &[]);
let mut status: Value = self.parse_ws_order_status(updateType.clone()).map(|__s| Value::Str(__s.into())).unwrap_or(Value::Null);
if (updateType.as_str() == Some("ORDER_CLOSED")) && is_true(&crate::precise::Precise::stringEq(&filled, &Value::Str("0".into()))) {
status = Value::Str("canceled".into());
}
let mut orderObject: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), orderId);
m.insert("symbol".to_string(), symbol.clone());
m.insert("status".to_string(), status);
m.insert("timestamp".to_string(), self.parse8601(datetime.clone()));
m.insert("datetime".to_string(), datetime);
m
});
orders.append(orderObject);
} else {
let mut parsed: Value = self.parse_order(update.clone(), &[]);
symbol = self.safe_string_k(parsed.clone(), "symbol", &[Value::Str("".into())]);
orders.append(parsed.clone());
}
client.resolve(&[self.orders.clone(), Value::Str(format!("{}{}", Value::Str("orders:".into()), symbol).into())]);
client.resolve(&[self.orders.clone(), Value::Str("orders".into())]);
// update balance
let mut balanceKeys: Value = Value::from(vec![Value::Str("locked".into()), Value::Str("unlocked".into()), Value::Str("spent".into()), Value::Str("spent_on_fees".into()), Value::Str("credited".into()), Value::Str("deducted".into())]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_545: bool = true;
while { if !__for_first_545 { i = (match (&(i), &(Value::Int(1))) { (Value::Int(x), Value::Int(y)) => Value::Int(x + y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 + *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x + *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x + y), _ => Value::Null }); } __for_first_545 = false; i.as_f64().unwrap_or(f64::NAN) < ((balanceKeys.len() as i64) as f64) } {
let mut newBalance: Value = self.safe_value(update.clone(), balanceKeys.as_array().and_then(|__arr| match &i { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null), &[]);
if (newBalance != Value::Null) {
self.update_balance(newBalance);
}
}
}
client.resolve(&[self.balance.clone(), Value::Str("balance".into())]);
// update trades
if (updateType.as_str() == Some("TRADE_SETTLED")) {
let mut parsed: Value = self.parse_trade(update, &[]);
symbol = self.safe_string_k(parsed.clone(), "symbol", &[Value::Str("".into())]);
let mut myTrades: Value = self.myTrades.clone();
myTrades.append(parsed);
client.resolve(&[self.myTrades.clone(), Value::Str(format!("{}{}", Value::Str("myTrades:".into()), symbol).into())]);
client.resolve(&[self.myTrades.clone(), Value::Str("myTrades".into())]);
}
}
pub fn parse_ws_order_status(&self, mut status: Value) -> Option<String> {
let mut statuses: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("ORDER_REJECTED".to_string(), Value::Str("rejected".into()));
m.insert("ORDER_CLOSED".to_string(), Value::Str("closed".into()));
m.insert("STOP_ORDER_TRIGGERED".to_string(), Value::Str("triggered".into()));
m
});
return self.safe_string(statuses, status.clone(), &[status.clone()]).as_str().map(str::to_owned);
}
pub fn update_balance(&mut self, mut balance: Value) {
//
// {
// "currency_code": "EUR",
// "amount": "0.0",
// "new_available": "0.0",
// "new_locked": "0.15949533"
// }
//
let mut currencyId: Value = self.safe_string_k(balance.clone(), "currency_code", &[]);
let mut code: Value = self.safe_currency_code(currencyId, &[]);
let mut account: Value = self.account();
if let Value::Dict(__d) = &mut account { std::sync::Arc::make_mut(__d).insert("free".into(), self.safe_string_k(balance.clone(), "new_available", &[])); }
if let Value::Dict(__d) = &mut account { std::sync::Arc::make_mut(__d).insert("used".into(), self.safe_string_k(balance.clone(), "new_locked", &[])); }
if (code != Value::Null) {
if let Value::Dict(__d) = &mut self.balance { std::sync::Arc::make_mut(__d).insert(crate::runtime::stringify_param(&code), account); }
}
{ let __t = self.safe_balance(self.balance.clone()); self.balance = __t; }
}
/*
* @method
* @name onetrading#watchOHLCV
* @see https://developers.bitpanda.com/exchange/#candlesticks-channel
* @description watches historical candlestick data containing the open, high, low, and close price, and the volume of a market
* @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
* @returns {int[][]} A list of candles ordered as timestamp, open, high, low, close, volume
*/
pub async fn watch_ohlcv(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut timeframe = get_arg(optional_args, 0, Value::Str("1m".into()));
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
symbol = market.as_map().and_then(|__m| __m.get("symbol")).cloned().unwrap_or(Value::Null);
let mut marketId: Value = market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null);
let mut url: Value = self.urls.as_map().and_then(|__m| __m.get("api")).cloned().unwrap_or(Value::Null).as_map().and_then(|__m| __m.get("ws")).cloned().unwrap_or(Value::Null);
let mut timeframes: Value = self.safe_dict_k(self.options.clone(), "timeframes", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut timeframeId: Value = self.safe_dict(timeframes.clone(), timeframe.clone(), &[]);
if (timeframeId == Value::Null) {
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" this interval is not supported, please provide one of the supported timeframes".into()))));
}
let mut messageHash: Value = Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str("ohlcv.".into()), symbol).into()), Value::Str(".".into())).into()), timeframe).into());
let mut subscriptionHash: Value = Value::Str("CANDLESTICKS".into());
let mut client: Value = self.safe_value(self.clients.clone(), url.clone(), &[]);
let mut type_var: Value = Value::Str("SUBSCRIBE".into());
let mut subscription: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
if (client != Value::Null) {
subscription = self.safe_value(get_value(&client, &Value::Str("subscriptions".into())), subscriptionHash.clone(), &[]);
if (subscription != Value::Null) {
let mut ohlcvMarket: Value = self.safe_dict(subscription.clone(), marketId.clone(), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut marketSubscribed: Value = self.safe_bool(ohlcvMarket, timeframe.clone(), &[Value::Bool(false)]);
if (marketSubscribed.as_bool() != Some(true)) {
type_var = Value::Str("UPDATE_SUBSCRIPTION".into());
add_element_to_object(&mut get_value(&client, &Value::Str("subscriptions".into())), &subscriptionHash, Value::Null);
}
} else {
subscription = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
}
}
let mut subscriptionMarketId: Value = self.safe_dict(subscription.clone(), marketId.clone(), &[]);
if (subscriptionMarketId == Value::Null) {
if (marketId != Value::Null) {
add_element_to_object(&mut subscription, &marketId, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
}
}
if (marketId != Value::Null) && (timeframe != Value::Null) {
add_element_to_object(get_value_mut(&mut subscription, &marketId), &timeframe, Value::Bool(true));
}
let mut properties: Value = Value::from(vec![]);
let mut marketIds: Value = object_keys(&subscription);
{
let mut i: Value = Value::Int(0);
let mut __for_first_547: bool = true;
while { if !__for_first_547 { i = (match (&(i), &(Value::Int(1))) { (Value::Int(x), Value::Int(y)) => Value::Int(x + y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 + *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x + *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x + y), _ => Value::Null }); } __for_first_547 = false; i.as_f64().unwrap_or(f64::NAN) < ((marketIds.len() as i64) as f64) } {
let mut marketIdtimeframes: Value = object_keys(&get_value(&subscription, &marketIds.as_array().and_then(|__arr| match &i { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null)));
{
let mut ii: Value = Value::Int(0);
let mut __for_first_546: bool = true;
while { if !__for_first_546 { ii = (match (&(ii), &(Value::Int(1))) { (Value::Int(x), Value::Int(y)) => Value::Int(x + y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 + *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x + *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x + y), _ => Value::Null }); } __for_first_546 = false; ii.as_f64().unwrap_or(f64::NAN) < ((marketIdtimeframes.len() as i64) as f64) } {
let mut marketTimeframeId: Value = self.safe_dict(timeframes.clone(), timeframe.clone(), &[]);
let mut property: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("instrument_code".to_string(), marketIds.as_array().and_then(|__arr| match &i { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null));
m.insert("time_granularity".to_string(), marketTimeframeId);
m
});
append_to_array(&mut properties, property);
}
}
}
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("type".to_string(), type_var);
m.insert("channels".to_string(), Value::from(vec![Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("name".to_string(), Value::Str("CANDLESTICKS".into()));
m.insert("properties".to_string(), properties);
m
})]));
m
});
let __ws_arg_0 = self.deep_extend(request, &[params]);
let mut ohlcv: Value = self.watch(url, messageHash, &[__ws_arg_0, subscriptionHash, subscription]).await;
if is_true(&self.newUpdates) {
limit = ohlcv.get_limit(symbol, limit.clone());
}
return self.filter_by_since_limit(ohlcv, &[since, limit, Value::Int(0), Value::Bool(true)]);
Value::Null
}
pub fn handle_ohlcv(&mut self, mut client: Value, mut message: Value) {
let __message_empty = indexmap::IndexMap::new();
let message = message.as_map().unwrap_or(&__message_empty);
//
// snapshot
// {
// "instrument_code": "BTC_EUR",
// "granularity": { unit: "MONTHS", period: 1 },
// "high": "29750.81",
// "low": "16764.59",
// "open": "29556.02",
// "close": "20164.55",
// "volume": "107518944.610659",
// "last_sequence": 2275507,
// "channel_name": "CANDLESTICKS",
// "type": "CANDLESTICK_SNAPSHOT",
// "time": "2022-06-30T23:59:59.999000Z"
// }
//
// update
// {
// "instrument_code": "BTC_EUR",
// "granularity": {
// "unit": "MINUTES",
// "period": 1
// },
// "high": "20164.16",
// "low": "20164.16",
// "open": "20164.16",
// "close": "20164.16",
// "volume": "3645.2768448",
// "last_sequence": 2275511,
// "channel_name": "CANDLESTICKS",
// "type": "CANDLESTICK",
// "time": "2022-06-24T21:20:59.999000Z"
// }
//
let mut marketId: Value = (match message.get("instrument_code") { Some(Value::Str(__s)) if !__s.is_empty() => Value::Str(__s.clone()), Some(Value::Int(__n)) => Value::Str(__n.to_string().into()), Some(Value::Float(__f)) => Value::Str(__f.to_string().into()), _ => Value::Null });
let mut symbol: Value = self.safe_symbol(marketId, &[]);
let mut dateTime: Value = (match message.get("time") { Some(Value::Str(__s)) if !__s.is_empty() => Value::Str(__s.clone()), Some(Value::Int(__n)) => Value::Str(__n.to_string().into()), Some(Value::Float(__f)) => Value::Str(__f.to_string().into()), _ => Value::Null });
let mut timeframeId: Value = (match message.get("granularity") { Some(__v) if matches!(__v, Value::Dict(_)) => __v.clone(), _ => Value::Null });
let mut timeframes: Value = self.safe_dict_k(self.options.clone(), "timeframes", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut timeframe: Value = self.find_timeframe(timeframeId, &[timeframes]);
let mut channel: Value = Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str("ohlcv.".into()), symbol).into()), Value::Str(".".into())).into()), timeframe).into());
let mut parsed: Value = Value::from(vec![self.parse8601(dateTime), (match message.get("open") { Some(Value::Float(__f)) => Value::Float(*__f), Some(Value::Int(__n)) => Value::Float(*__n as f64), Some(Value::Str(__s)) => match __s.parse::<f64>() { Ok(__n) => Value::Float(__n), Err(_) => Value::Null }, _ => Value::Null }), (match message.get("high") { Some(Value::Float(__f)) => Value::Float(*__f), Some(Value::Int(__n)) => Value::Float(*__n as f64), Some(Value::Str(__s)) => match __s.parse::<f64>() { Ok(__n) => Value::Float(__n), Err(_) => Value::Null }, _ => Value::Null }), (match message.get("low") { Some(Value::Float(__f)) => Value::Float(*__f), Some(Value::Int(__n)) => Value::Float(*__n as f64), Some(Value::Str(__s)) => match __s.parse::<f64>() { Ok(__n) => Value::Float(__n), Err(_) => Value::Null }, _ => Value::Null }), (match message.get("close") { Some(Value::Float(__f)) => Value::Float(*__f), Some(Value::Int(__n)) => Value::Float(*__n as f64), Some(Value::Str(__s)) => match __s.parse::<f64>() { Ok(__n) => Value::Float(__n), Err(_) => Value::Null }, _ => Value::Null }), (match message.get("volume") { Some(Value::Float(__f)) => Value::Float(*__f), Some(Value::Int(__n)) => Value::Float(*__n as f64), Some(Value::Str(__s)) => match __s.parse::<f64>() { Ok(__n) => Value::Float(__n), Err(_) => Value::Null }, _ => Value::Null })]);
{ let __be_tmp = self.safe_dict(self.ohlcvs.clone(), symbol.clone(), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]); if let Value::Dict(__d) = &mut self.ohlcvs { std::sync::Arc::make_mut(__d).insert(crate::runtime::stringify_param(&symbol), __be_tmp); } }
let mut stored: Value = self.safe_value(self.safe_dict(self.ohlcvs.clone(), symbol.clone(), &[]), timeframe.clone(), &[]);
if (stored == Value::Null) {
let mut limit: Value = self.safe_integer_k(self.options.clone(), "OHLCVLimit", &[Value::Int(1000)]);
stored = ArrayCacheByTimestamp::new(limit);
}
stored.append(parsed);
if (symbol != Value::Null) && (timeframe != Value::Null) {
add_element_to_object(get_value_mut(&mut self.ohlcvs, &symbol), &timeframe, stored.clone());
}
client.resolve(&[stored, channel]);
}
pub fn find_timeframe(&self, mut timeframe: Value, optional_args: &[Value]) -> Value {
let mut timeframes = get_arg(optional_args, 0, Value::Null);
if (timeframes == Value::Null) {
timeframes = self.timeframes.clone();
}
if (timeframes == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" findTimeframe() timeframes is required".into()))));
}
let mut keys: Value = object_keys(&timeframes);
{
let mut i: Value = Value::Int(0);
let mut __for_first_548: bool = true;
while { if !__for_first_548 { i = (match (&(i), &(Value::Int(1))) { (Value::Int(x), Value::Int(y)) => Value::Int(x + y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 + *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x + *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x + y), _ => Value::Null }); } __for_first_548 = false; i.as_f64().unwrap_or(f64::NAN) < ((keys.len() as i64) as f64) } {
let mut key: Value = keys.as_array().and_then(|__arr| match &i { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null);
if is_equal(&crate::value::get_value_k(&get_value(&timeframes, &key), "unit"), &crate::value::get_value_k(&timeframe, "unit")) && is_equal(&crate::value::get_value_k(&get_value(&timeframes, &key), "period"), &crate::value::get_value_k(&timeframe, "period")) {
return key;
}
}
}
return Value::Null;
Value::Null
}
pub fn handle_subscriptions(&self, mut client: Value, mut message: Value) -> Value {
return message;
Value::Null
}
pub fn handle_heartbeat(&self, mut client: Value, mut message: Value) -> Value {
return message;
Value::Null
}
pub fn handle_error_message(&self, mut client: Value, mut message: Value) -> Value {
panic!("{}", crate::exchange_errors::exchange_error(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" ".into())).into()), json_stringify(&message))));
Value::Null
}
pub fn handle_message(&mut self, mut client: Value, mut message: Value) {
let __pro_message_arc: std::sync::Arc<indexmap::IndexMap<String, Value>> = (match &message { Value::Dict(__d) => __d.clone(), _ => std::sync::Arc::new(indexmap::IndexMap::new()) });
let __pro_message: &indexmap::IndexMap<String, Value> = &__pro_message_arc;
let mut error: Option<String> = (match __pro_message.get("error").cloned() { Some(Value::Str(__s)) if !__s.is_empty() => Value::Str(__s), Some(Value::Int(__n)) => Value::Str(__n.to_string().into()), Some(Value::Float(__f)) => Value::Str(__f.to_string().into()), _ => Value::Null }).as_str().map(str::to_owned);
if (error.is_some()) {
self.handle_error_message(client.clone(), message.clone());
return;
}
let mut type_var: Value = (match __pro_message.get("type").cloned() { Some(Value::Str(__s)) if !__s.is_empty() => Value::Str(__s), Some(Value::Int(__n)) => Value::Str(__n.to_string().into()), Some(Value::Float(__f)) => Value::Str(__f.to_string().into()), _ => Value::Null });
let mut handlers: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("ORDER_BOOK_UPDATE".to_string(), Value::Str("handle_order_book".into()).clone());
m.insert("ORDER_BOOK_SNAPSHOT".to_string(), Value::Str("handle_order_book".into()).clone());
m.insert("ACTIVE_ORDERS_SNAPSHOT".to_string(), Value::Str("handle_orders".into()).clone());
m.insert("INACTIVE_ORDERS_SNAPSHOT".to_string(), Value::Str("handle_orders".into()).clone());
m.insert("ACCOUNT_UPDATE".to_string(), Value::Str("handle_account_update".into()).clone());
m.insert("BALANCES_SNAPSHOT".to_string(), Value::Str("handle_balance_snapshot".into()).clone());
m.insert("SUBSCRIPTIONS".to_string(), Value::Str("handle_subscriptions".into()).clone());
m.insert("SUBSCRIPTION_UPDATED".to_string(), Value::Str("handle_subscriptions".into()).clone());
m.insert("PRICE_TICK".to_string(), Value::Str("handle_ticker".into()).clone());
m.insert("PRICE_TICK_HISTORY".to_string(), Value::Str("handle_subscriptions".into()).clone());
m.insert("HEARTBEAT".to_string(), Value::Str("handle_heartbeat".into()).clone());
m.insert("MARKET_TICKER_UPDATES".to_string(), Value::Str("handle_ticker".into()).clone());
m.insert("PRICE_POINT_UPDATES".to_string(), Value::Str("handle_price_point_updates".into()).clone());
m.insert("CANDLESTICK_SNAPSHOT".to_string(), Value::Str("handle_ohlcv".into()).clone());
m.insert("CANDLESTICK".to_string(), Value::Str("handle_ohlcv".into()).clone());
m.insert("AUTHENTICATED".to_string(), Value::Str("handle_authentication_message".into()).clone());
m.insert("FILL".to_string(), Value::Str("handle_trading".into()).clone());
m.insert("DONE".to_string(), Value::Str("handle_trading".into()).clone());
m.insert("BOOKED".to_string(), Value::Str("handle_trading".into()).clone());
m.insert("UPDATE".to_string(), Value::Str("handle_trading".into()).clone());
m.insert("TRACKED".to_string(), Value::Str("handle_trading".into()).clone());
m.insert("TRIGGERED".to_string(), Value::Str("handle_trading".into()).clone());
m.insert("STOP_TRACKED".to_string(), Value::Str("handle_trading".into()).clone());
m.insert("STOP_TRIGGERED".to_string(), Value::Str("handle_trading".into()).clone());
m
});
let mut handler: Value = self.safe_value(handlers, type_var, &[]);
if (handler != Value::Null) {
self.dispatch_ws_handler(&handler, &[client, message]);
}
}
pub fn handle_price_point_updates(&self, mut client: Value, mut message: Value) -> Value {
return message;
Value::Null
}
pub fn handle_authentication_message(&self, mut client: Value, mut message: Value) -> Value {
//
// {
// "channel_name": "SYSTEM",
// "type": "AUTHENTICATED",
// "time": "2022-06-24T20:45:25.447488Z"
// }
//
let mut future: Value = self.safe_value(get_value(&client, &Value::Str("futures".into())), Value::Str("authenticated".into()), &[]);
if (future != Value::Null) {
future.resolve(&[Value::Bool(true)]);
}
return message;
Value::Null
}
pub async fn watch_many(&mut self, mut messageHash: Value, mut request: Value, mut subscriptionHash: Value, optional_args: &[Value]) -> Value {
let mut symbols = get_arg(optional_args, 0, Value::from(vec![]));
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut marketIds: Value = Value::from(vec![]);
let mut numSymbols: f64 = ((symbols.len() as i64) as f64);
if (numSymbols == 0.0) {
let mut marketsById: Value = self.markets_by_id.clone();
if (marketsById == Value::Null) {
return Value::from(vec![]);
}
marketIds = object_keys(&marketsById);
} else {
marketIds = self.market_ids(&[symbols]);
}
let mut url: Value = self.urls.as_map().and_then(|__m| __m.get("api")).cloned().unwrap_or(Value::Null).as_map().and_then(|__m| __m.get("ws")).cloned().unwrap_or(Value::Null);
let mut client: Value = self.safe_value(self.clients.clone(), url.clone(), &[]);
let mut type_var: Value = Value::Str("SUBSCRIBE".into());
let mut subscription: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
if (client != Value::Null) {
subscription = self.safe_value(get_value(&client, &Value::Str("subscriptions".into())), subscriptionHash.clone(), &[]);
if (subscription != Value::Null) {
{
let mut i: Value = Value::Int(0);
let mut __for_first_549: bool = true;
while { if !__for_first_549 { i = (match (&(i), &(Value::Int(1))) { (Value::Int(x), Value::Int(y)) => Value::Int(x + y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 + *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x + *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x + y), _ => Value::Null }); } __for_first_549 = false; i.as_f64().unwrap_or(f64::NAN) < ((marketIds.len() as i64) as f64) } {
let mut marketId: Value = marketIds.as_array().and_then(|__arr| match &i { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null);
let mut marketSubscribed: Value = self.safe_bool(subscription.clone(), marketId.clone(), &[Value::Bool(false)]);
if (marketSubscribed.as_bool() != Some(true)) {
type_var = Value::Str("UPDATE_SUBSCRIPTION".into());
add_element_to_object(&mut get_value(&client, &Value::Str("subscriptions".into())), &subscriptionHash, Value::Null);
}
}
}
} else {
subscription = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
}
}
{
let mut i: Value = Value::Int(0);
let mut __for_first_550: bool = true;
while { if !__for_first_550 { i = (match (&(i), &(Value::Int(1))) { (Value::Int(x), Value::Int(y)) => Value::Int(x + y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 + *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x + *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x + y), _ => Value::Null }); } __for_first_550 = false; i.as_f64().unwrap_or(f64::NAN) < ((marketIds.len() as i64) as f64) } {
let mut marketId: Value = marketIds.as_array().and_then(|__arr| match &i { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null);
add_element_to_object(&mut subscription, &marketId, Value::Bool(true));
}
}
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("type".into(), type_var); }
add_element_to_object(get_value_mut(get_value_mut(&mut request, &Value::Str("channels".into())), &Value::Int(0)), &Value::Str("instrument_codes".into()), object_keys(&subscription));
let __ws_arg_1 = self.deep_extend(request, &[params]);
return self.watch(url, messageHash, &[__ws_arg_1, subscriptionHash, subscription]).await;
Value::Null
}
pub async fn authenticate(&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 url: Value = self.urls.as_map().and_then(|__m| __m.get("api")).cloned().unwrap_or(Value::Null).as_map().and_then(|__m| __m.get("ws")).cloned().unwrap_or(Value::Null);
let mut client: Value = self.client(&[url.clone()]);
let mut messageHash: Value = Value::Str("authenticated".into());
let mut future: Value = client.reusable_future(Value::Str("authenticated".into()));
let mut authenticated: Value = self.safe_dict(get_value(&client, &Value::Str("subscriptions".into())), messageHash.clone(), &[]);
if (authenticated == Value::Null) {
self.check_required_credentials(&[]);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("type".to_string(), Value::Str("AUTHENTICATE".into()));
m.insert("api_token".to_string(), self.apiKey.clone());
m
});
let __ws_arg_2 = self.extend(request, &[params]);
self.watch(url, messageHash.clone(), &[__ws_arg_2, messageHash.clone()]).await;
}
return crate::exchange_stubs::ws_await_flight(&future).await;
Value::Null
}
}