// PLEASE DO NOT EDIT THIS FILE, IT IS GENERATED AND WILL BE OVERWRITTEN:
// https://github.com/ccxt/ccxt/blob/master/CONTRIBUTING.md#how-to-contribute-code
#![allow(unused, non_snake_case, clippy::all)]
use crate::Value;
use crate::get_value;
use crate::runtime::*;
// Base methods are now trait methods (review #1: static dispatch). Bring the
// traits into scope so `self.market(...)`, `self.safe_market(...)`,
// `self.load_markets(...)`, … on this Core resolve to the base defaults.
use crate::exchange_generated::ExchangeBase;
use crate::exchange::ExchangeRuntime;
pub struct BtcturkCore {
pub exchange: crate::exchange::Exchange,
}
impl BtcturkCore {
pub fn new(config: Option<crate::Value>) -> Self {
let mut s = Self { exchange: crate::exchange::Exchange::new(config) };
s.init();
s
}
pub fn init(&mut self) {
let described = BtcturkCore::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 BtcturkCore {
fn nonce(&self, ) -> crate::Value {
// Forward to the inherent method on BtcturkCore.
BtcturkCore::nonce(self, )
}
fn parse_ticker(&self, ticker: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on BtcturkCore.
BtcturkCore::parse_ticker(self, ticker, &[market.clone()])
}
fn parse_trade(&self, trade: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on BtcturkCore.
BtcturkCore::parse_trade(self, trade, &[market.clone()])
}
fn parse_order(&self, order: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on BtcturkCore.
BtcturkCore::parse_order(self, order, &[market.clone()])
}
fn parse_market(&self, market: crate::Value) -> crate::Value {
// Forward to the inherent method on BtcturkCore.
BtcturkCore::parse_market(self, market)
}
fn parse_ohlcv(&self, ohlcv: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on BtcturkCore.
BtcturkCore::parse_ohlcv(self, ohlcv, &[market.clone()])
}
fn parse_balance(&self, response: crate::Value) -> crate::Value {
// Forward to the inherent method on BtcturkCore.
BtcturkCore::parse_balance(self, response)
}
fn sign(&self, path: crate::Value, api: crate::Value, method: crate::Value, params: crate::Value, headers: crate::Value, body: crate::Value) -> crate::Value {
// Forward to the inherent method on BtcturkCore.
BtcturkCore::sign(self, path, &[api.clone(), method.clone(), params.clone(), headers.clone(), body.clone()])
}
fn handle_errors(&self, code: crate::Value, reason: crate::Value, url: crate::Value, method: crate::Value, headers: crate::Value, body: crate::Value, response: crate::Value, request_headers: crate::Value, request_body: crate::Value) -> crate::Value {
// Forward to the inherent method on BtcturkCore.
BtcturkCore::handle_errors(self, code, reason, url, method, headers, body, response, request_headers, request_body)
}
}
impl crate::exchange_generated::ExchangeBase for BtcturkCore {
fn call_dynamic<'a>(&'a mut self, method: &'a str, args: Vec<crate::Value>)
-> std::pin::Pin<Box<dyn std::future::Future<Output = crate::Value> + Send + 'a>>
{
Box::pin(async move {
match method {
"cancel_order" => self.cancel_order(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"create_order" => self.create_order(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), args.get(3).cloned().unwrap_or(crate::Value::Null), &args.get(4..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_balance" => self.fetch_balance(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_markets" => self.fetch_markets(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_my_trades" => self.fetch_my_trades(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_ohlcv" => self.fetch_ohlcv(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_open_orders" => self.fetch_open_orders(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_order_book" => self.fetch_order_book(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_orders" => self.fetch_orders(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_ticker" => self.fetch_ticker(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_tickers" => self.fetch_tickers(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_trades" => self.fetch_trades(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"handle_errors" => self.handle_errors(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), args.get(3).cloned().unwrap_or(crate::Value::Null), args.get(4).cloned().unwrap_or(crate::Value::Null), args.get(5).cloned().unwrap_or(crate::Value::Null), args.get(6).cloned().unwrap_or(crate::Value::Null), args.get(7).cloned().unwrap_or(crate::Value::Null), args.get(8).cloned().unwrap_or(crate::Value::Null)),
"nonce" => self.nonce(),
"parse_balance" => self.parse_balance(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_market" => self.parse_market(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_ohlc_vs" => self.parse_ohlc_vs(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_ohlcv" => self.parse_ohlcv(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_order" => self.parse_order(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_order_status" => self.parse_order_status(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_ticker" => self.parse_ticker(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_trade" => self.parse_trade(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"sign" => self.sign(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
// Fall through to the base-only methods (cancelOrderWithClientOrderId, …).
_ => self.call_dynamic_base(method, args).await,
}
})
}
}
impl std::ops::Deref for BtcturkCore {
type Target = crate::exchange::Exchange;
fn deref(&self) -> &crate::exchange::Exchange { &self.exchange }
}
impl std::ops::DerefMut for BtcturkCore {
fn deref_mut(&mut self) -> &mut crate::exchange::Exchange { &mut self.exchange }
}
impl BtcturkCore {
pub fn describe(&self) -> Value {
return self.deep_extend(self.super_describe(), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), Value::Str("btcturk".to_string()));
m.insert("name".to_string(), Value::Str("BTCTurk".to_string()));
m.insert("countries".to_string(), Value::List(vec![Value::Str("TR".to_string())]));
m.insert("rateLimit".to_string(), Value::Int(100));
m.insert("pro".to_string(), Value::Bool(false));
m.insert("has".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("CORS".to_string(), Value::Bool(true));
m.insert("spot".to_string(), Value::Bool(true));
m.insert("margin".to_string(), Value::Bool(false));
m.insert("swap".to_string(), Value::Bool(false));
m.insert("future".to_string(), Value::Bool(false));
m.insert("option".to_string(), Value::Bool(false));
m.insert("addMargin".to_string(), Value::Bool(false));
m.insert("borrowCrossMargin".to_string(), Value::Bool(false));
m.insert("borrowIsolatedMargin".to_string(), Value::Bool(false));
m.insert("borrowMargin".to_string(), Value::Bool(false));
m.insert("cancelOrder".to_string(), Value::Bool(true));
m.insert("closeAllPositions".to_string(), Value::Bool(false));
m.insert("closePosition".to_string(), Value::Bool(false));
m.insert("createDepositAddress".to_string(), Value::Bool(false));
m.insert("createOrder".to_string(), Value::Bool(true));
m.insert("createOrderWithTakeProfitAndStopLoss".to_string(), Value::Bool(false));
m.insert("createOrderWithTakeProfitAndStopLossWs".to_string(), Value::Bool(false));
m.insert("createPostOnlyOrder".to_string(), Value::Bool(false));
m.insert("createReduceOnlyOrder".to_string(), Value::Bool(false));
m.insert("fetchBalance".to_string(), Value::Bool(true));
m.insert("fetchBorrowInterest".to_string(), Value::Bool(false));
m.insert("fetchBorrowRate".to_string(), Value::Bool(false));
m.insert("fetchBorrowRateHistories".to_string(), Value::Bool(false));
m.insert("fetchBorrowRateHistory".to_string(), Value::Bool(false));
m.insert("fetchBorrowRates".to_string(), Value::Bool(false));
m.insert("fetchBorrowRatesPerSymbol".to_string(), Value::Bool(false));
m.insert("fetchCrossBorrowRate".to_string(), Value::Bool(false));
m.insert("fetchCrossBorrowRates".to_string(), Value::Bool(false));
m.insert("fetchCurrencies".to_string(), Value::Bool(false));
m.insert("fetchDepositAddress".to_string(), Value::Bool(false));
m.insert("fetchDepositAddresses".to_string(), Value::Bool(false));
m.insert("fetchDepositAddressesByNetwork".to_string(), Value::Bool(false));
m.insert("fetchFundingHistory".to_string(), Value::Bool(false));
m.insert("fetchFundingInterval".to_string(), Value::Bool(false));
m.insert("fetchFundingIntervals".to_string(), Value::Bool(false));
m.insert("fetchFundingRate".to_string(), Value::Bool(false));
m.insert("fetchFundingRateHistory".to_string(), Value::Bool(false));
m.insert("fetchFundingRates".to_string(), Value::Bool(false));
m.insert("fetchGreeks".to_string(), Value::Bool(false));
m.insert("fetchIndexOHLCV".to_string(), Value::Bool(false));
m.insert("fetchIsolatedBorrowRate".to_string(), Value::Bool(false));
m.insert("fetchIsolatedBorrowRates".to_string(), Value::Bool(false));
m.insert("fetchIsolatedPositions".to_string(), Value::Bool(false));
m.insert("fetchLeverage".to_string(), Value::Bool(false));
m.insert("fetchLeverages".to_string(), Value::Bool(false));
m.insert("fetchLeverageTiers".to_string(), Value::Bool(false));
m.insert("fetchLiquidations".to_string(), Value::Bool(false));
m.insert("fetchLongShortRatio".to_string(), Value::Bool(false));
m.insert("fetchLongShortRatioHistory".to_string(), Value::Bool(false));
m.insert("fetchMarginAdjustmentHistory".to_string(), Value::Bool(false));
m.insert("fetchMarginMode".to_string(), Value::Bool(false));
m.insert("fetchMarginModes".to_string(), Value::Bool(false));
m.insert("fetchMarketLeverageTiers".to_string(), Value::Bool(false));
m.insert("fetchMarkets".to_string(), Value::Bool(true));
m.insert("fetchMarkOHLCV".to_string(), Value::Bool(false));
m.insert("fetchMarkPrices".to_string(), Value::Bool(false));
m.insert("fetchMyLiquidations".to_string(), Value::Bool(false));
m.insert("fetchMySettlementHistory".to_string(), Value::Bool(false));
m.insert("fetchMyTrades".to_string(), Value::Bool(true));
m.insert("fetchOHLCV".to_string(), Value::Bool(true));
m.insert("fetchOpenInterest".to_string(), Value::Bool(false));
m.insert("fetchOpenInterestHistory".to_string(), Value::Bool(false));
m.insert("fetchOpenInterests".to_string(), Value::Bool(false));
m.insert("fetchOpenOrders".to_string(), Value::Bool(true));
m.insert("fetchOption".to_string(), Value::Bool(false));
m.insert("fetchOptionChain".to_string(), Value::Bool(false));
m.insert("fetchOrderBook".to_string(), Value::Bool(true));
m.insert("fetchOrders".to_string(), Value::Bool(true));
m.insert("fetchPosition".to_string(), Value::Bool(false));
m.insert("fetchPositionHistory".to_string(), Value::Bool(false));
m.insert("fetchPositionMode".to_string(), Value::Bool(false));
m.insert("fetchPositions".to_string(), Value::Bool(false));
m.insert("fetchPositionsForSymbol".to_string(), Value::Bool(false));
m.insert("fetchPositionsHistory".to_string(), Value::Bool(false));
m.insert("fetchPositionsRisk".to_string(), Value::Bool(false));
m.insert("fetchPremiumIndexOHLCV".to_string(), Value::Bool(false));
m.insert("fetchSettlementHistory".to_string(), Value::Bool(false));
m.insert("fetchTicker".to_string(), Value::Bool(true));
m.insert("fetchTickers".to_string(), Value::Bool(true));
m.insert("fetchTrades".to_string(), Value::Bool(true));
m.insert("fetchVolatilityHistory".to_string(), Value::Bool(false));
m.insert("reduceMargin".to_string(), Value::Bool(false));
m.insert("repayCrossMargin".to_string(), Value::Bool(false));
m.insert("repayIsolatedMargin".to_string(), Value::Bool(false));
m.insert("repayMargin".to_string(), Value::Bool(false));
m.insert("setLeverage".to_string(), Value::Bool(false));
m.insert("setMargin".to_string(), Value::Bool(false));
m.insert("setMarginMode".to_string(), Value::Bool(false));
m.insert("setPositionMode".to_string(), Value::Bool(false));
m.insert("ws".to_string(), Value::Bool(false));
m
}));
m.insert("timeframes".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("1m".to_string(), Value::Int(1));
m.insert("15m".to_string(), Value::Int(15));
m.insert("30m".to_string(), Value::Int(30));
m.insert("1h".to_string(), Value::Int(60));
m.insert("4h".to_string(), Value::Int(240));
m.insert("1d".to_string(), Value::Str("1 d".to_string()));
m.insert("1w".to_string(), Value::Str("1 w".to_string()));
m.insert("1y".to_string(), Value::Str("1 y".to_string()));
m
}));
m.insert("urls".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("logo".to_string(), Value::Str("https://github.com/user-attachments/assets/710711ff-1278-4e7a-9b03-b5503dd85b59".to_string()));
m.insert("api".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("public".to_string(), Value::Str("https://api.btcturk.com/api/v2".to_string()));
m.insert("private".to_string(), Value::Str("https://api.btcturk.com/api/v1".to_string()));
m.insert("graph".to_string(), Value::Str("https://graph-api.btcturk.com/v1".to_string()));
m
}));
m.insert("www".to_string(), Value::Str("https://www.btcturk.com".to_string()));
m.insert("doc".to_string(), Value::Str("https://github.com/BTCTrader/broker-api-docs".to_string()));
m
}));
m.insert("api".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("public".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("get".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("orderbook".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("ticker".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(0.1));
m
}));
m.insert("trades".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("ohlc".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("server/exchangeinfo".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m
}));
m
}));
m.insert("private".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("get".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("users/balances".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("openOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("allOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("users/transactions/trade".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m
}));
m.insert("post".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("users/transactions/crypto".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("users/transactions/fiat".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("cancelOrder".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m
}));
m.insert("delete".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m
}));
m
}));
m.insert("graph".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("get".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("ohlcs".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("klines/history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m
}));
m
}));
m
}));
m.insert("features".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("spot".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("sandbox".to_string(), Value::Bool(false));
m.insert("createOrder".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("marginMode".to_string(), Value::Bool(false));
m.insert("triggerPrice".to_string(), Value::Bool(true));
m.insert("triggerPriceType".to_string(), Value::Null);
m.insert("triggerDirection".to_string(), Value::Bool(false));
m.insert("stopLossPrice".to_string(), Value::Bool(false));
m.insert("takeProfitPrice".to_string(), Value::Bool(false));
m.insert("attachedStopLossTakeProfit".to_string(), Value::Null);
m.insert("timeInForce".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("IOC".to_string(), Value::Bool(false));
m.insert("FOK".to_string(), Value::Bool(false));
m.insert("PO".to_string(), Value::Bool(false));
m.insert("GTD".to_string(), Value::Bool(false));
m
}));
m.insert("hedged".to_string(), Value::Bool(false));
m.insert("leverage".to_string(), Value::Bool(false));
m.insert("marketBuyRequiresPrice".to_string(), Value::Bool(false));
m.insert("marketBuyByCost".to_string(), Value::Bool(false));
m.insert("selfTradePrevention".to_string(), Value::Bool(false));
m.insert("trailing".to_string(), Value::Bool(false));
m.insert("iceberg".to_string(), Value::Bool(false));
m
}));
m.insert("createOrders".to_string(), Value::Null);
m.insert("fetchMyTrades".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("marginMode".to_string(), Value::Bool(false));
m.insert("limit".to_string(), Value::Int(100));
m.insert("daysBack".to_string(), Value::Int(100000));
m.insert("untilDays".to_string(), Value::Int(30));
m.insert("symbolRequired".to_string(), Value::Bool(true));
m
}));
m.insert("fetchOrder".to_string(), Value::Null);
m.insert("fetchOpenOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("marginMode".to_string(), Value::Bool(false));
m.insert("limit".to_string(), Value::Null);
m.insert("trigger".to_string(), Value::Bool(false));
m.insert("trailing".to_string(), Value::Bool(false));
m.insert("symbolRequired".to_string(), Value::Bool(true));
m
}));
m.insert("fetchOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("marginMode".to_string(), Value::Bool(false));
m.insert("limit".to_string(), Value::Int(1000));
m.insert("daysBack".to_string(), Value::Int(100000));
m.insert("untilDays".to_string(), Value::Int(30));
m.insert("trigger".to_string(), Value::Bool(false));
m.insert("trailing".to_string(), Value::Bool(false));
m.insert("symbolRequired".to_string(), Value::Bool(true));
m
}));
m.insert("fetchClosedOrders".to_string(), Value::Null);
m.insert("fetchOHLCV".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("limit".to_string(), Value::Null);
m
}));
m
}));
m.insert("swap".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("linear".to_string(), Value::Null);
m.insert("inverse".to_string(), Value::Null);
m
}));
m.insert("future".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("linear".to_string(), Value::Null);
m.insert("inverse".to_string(), Value::Null);
m
}));
m
}));
m.insert("fees".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("trading".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("maker".to_string(), self.parse_number(Value::Str("0.0005".to_string()), &[]));
m.insert("taker".to_string(), self.parse_number(Value::Str("0.0009".to_string()), &[]));
m
}));
m
}));
m.insert("exceptions".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("exact".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("FAILED_ORDER_WITH_OPEN_ORDERS".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m.insert("FAILED_LIMIT_ORDER".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("FAILED_MARKET_ORDER".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m
}));
m
}));
m.insert("precisionMode".to_string(), Value::Int(crate::runtime::TICK_SIZE));
m
})]);
Value::Null
}
/*
* @method
* @name btcturk#fetchMarkets
* @description retrieves data on all markets for btcturk
* @see https://docs.btcturk.com/public-endpoints/exchange-info
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object[]} an array of objects representing market data
*/
pub async fn fetch_markets(&mut self, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut response: Value = self.public_get_server_exchangeinfo(&[params.clone()]).await;
//
// {
// "data": {
// "timeZone": "UTC",
// "serverTime": "1618826678404",
// "symbols": [
// {
// "id": "1",
// "name": "BTCTRY",
// "nameNormalized": "BTC_TRY",
// "status": "TRADING",
// "numerator": "BTC",
// "denominator": "TRY",
// "numeratorScale": "8",
// "denominatorScale": "2",
// "hasFraction": false,
// "filters": [
// {
// "filterType": "PRICE_FILTER",
// "minPrice": "0.0000000000001",
// "maxPrice": "10000000",
// "tickSize": "10",
// "minExchangeValue": "99.92",
// "minAmount": null,
// "maxAmount": null
// }
// ],
// "orderMethods": [
// "MARKET",
// "LIMIT",
// "STOP_MARKET",
// "STOP_LIMIT"
// ],
// "displayFormat": "#,###",
// "commissionFromNumerator": false,
// "order": "1000",
// "priceRounding": false
// },
// ...
// },
// ],
// }
//
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut markets: Value = self.safe_list_k(data.clone(), "symbols", &[Value::List(vec![])]);
return self.parse_markets(markets.clone());
Value::Null
}
pub fn parse_market(&self, mut entry: Value) -> Value {
let mut id: Value = self.safe_string_k(entry.clone(), "name", &[]);
let mut baseId: Value = self.safe_string_k(entry.clone(), "numerator", &[]);
let mut quoteId: Value = self.safe_string_k(entry.clone(), "denominator", &[]);
let mut base: Value = self.safe_currency_code(baseId.clone(), &[]);
let mut quote: Value = self.safe_currency_code(quoteId.clone(), &[]);
let mut filters: Value = self.safe_list_k(entry.clone(), "filters", &[Value::List(vec![])]);
let mut minPrice: Value = Value::Null;
let mut maxPrice: Value = Value::Null;
let mut minAmount: Value = Value::Null;
let mut maxAmount: Value = Value::Null;
let mut minCost: Value = Value::Null;
{
let mut j: Value = Value::Int(0);
let mut __for_first_452: bool = true;
while { if !__for_first_452 { j = add(&j, &Value::Int(1)); } __for_first_452 = false; is_less_than(&j, &get_array_length(&filters)) } {
let mut filter: Value = get_value(&filters, &j);
let mut filter: Value = get_value(&filters, &j);
let mut filterType: Value = self.safe_string_k(filter.clone(), "filterType", &[]);
if is_equal(&filterType, &Value::Str("PRICE_FILTER".to_string())) {
minPrice = self.safe_number_k(filter.clone(), "minPrice", &[]);
maxPrice = self.safe_number_k(filter.clone(), "maxPrice", &[]);
minAmount = self.safe_number_k(filter.clone(), "minAmount", &[]);
maxAmount = self.safe_number_k(filter.clone(), "maxAmount", &[]);
minCost = self.safe_number_k(filter.clone(), "minExchangeValue", &[]);
}
}
}
let mut status: Value = self.safe_string_k(entry.clone(), "status", &[]);
return self.safe_market_structure(&[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), id.clone());
m.insert("symbol".to_string(), add(&add(&base, &Value::Str("/".to_string())), "e));
m.insert("base".to_string(), base.clone());
m.insert("quote".to_string(), quote.clone());
m.insert("settle".to_string(), Value::Null);
m.insert("baseId".to_string(), baseId.clone());
m.insert("quoteId".to_string(), quoteId.clone());
m.insert("settleId".to_string(), Value::Null);
m.insert("type".to_string(), Value::Str("spot".to_string()));
m.insert("spot".to_string(), Value::Bool(true));
m.insert("margin".to_string(), Value::Bool(false));
m.insert("swap".to_string(), Value::Bool(false));
m.insert("future".to_string(), Value::Bool(false));
m.insert("option".to_string(), Value::Bool(false));
m.insert("active".to_string(), Value::Bool((is_equal(&status, &Value::Str("TRADING".to_string())))));
m.insert("contract".to_string(), Value::Bool(false));
m.insert("linear".to_string(), Value::Null);
m.insert("inverse".to_string(), Value::Null);
m.insert("contractSize".to_string(), Value::Null);
m.insert("expiry".to_string(), Value::Null);
m.insert("expiryDatetime".to_string(), Value::Null);
m.insert("strike".to_string(), Value::Null);
m.insert("optionType".to_string(), Value::Null);
m.insert("precision".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("amount".to_string(), self.parse_number(self.parse_precision(&[self.safe_string_k(entry.clone(), "numeratorScale", &[])]), &[]));
m.insert("price".to_string(), self.parse_number(self.parse_precision(&[self.safe_string_k(entry.clone(), "denominatorScale", &[])]), &[]));
m
}));
m.insert("limits".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("leverage".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), Value::Null);
m.insert("max".to_string(), Value::Null);
m
}));
m.insert("amount".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), minAmount.clone());
m.insert("max".to_string(), maxAmount.clone());
m
}));
m.insert("price".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), minPrice.clone());
m.insert("max".to_string(), maxPrice.clone());
m
}));
m.insert("cost".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), minCost.clone());
m.insert("max".to_string(), Value::Null);
m
}));
m
}));
m.insert("created".to_string(), Value::Null);
m.insert("info".to_string(), entry.clone());
m
})]);
Value::Null
}
pub fn parse_balance(&self, mut response: Value) -> Value {
let mut data: Value = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
let mut result: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), response.clone());
m.insert("timestamp".to_string(), Value::Null);
m.insert("datetime".to_string(), Value::Null);
m
});
{
let mut i: Value = Value::Int(0);
let mut __for_first_453: bool = true;
while { if !__for_first_453 { i = add(&i, &Value::Int(1)); } __for_first_453 = false; is_less_than(&i, &get_array_length(&data)) } {
let mut entry: Value = get_value(&data, &i);
let mut entry: Value = get_value(&data, &i);
let mut currencyId: Value = self.safe_string_k(entry.clone(), "asset", &[]);
let mut code: Value = self.safe_currency_code(currencyId.clone(), &[]);
let mut account: Value = self.account();
add_element_to_object(&mut account, &Value::Str("total".to_string()), self.safe_string_k(entry.clone(), "balance", &[]));
add_element_to_object(&mut account, &Value::Str("free".to_string()), self.safe_string_k(entry.clone(), "free", &[]));
add_element_to_object(&mut account, &Value::Str("used".to_string()), self.safe_string_k(entry.clone(), "locked", &[]));
if !is_equal(&code, &Value::Null) {
add_element_to_object(&mut result, &code, account.clone());
}
}
}
return self.safe_balance(result.clone());
Value::Null
}
/*
* @method
* @name btcturk#fetchBalance
* @description query for balance and get the amount of funds available for trading or funds locked in orders
* @see https://docs.btcturk.com/private-endpoints/account-balance
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a [balance structure]{@link https://docs.ccxt.com/?id=balance-structure}
*/
pub async fn fetch_balance(&mut self, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut response: Value = self.private_get_users_balances(&[params.clone()]).await;
return self.parse_balance(response.clone());
Value::Null
}
/*
* @method
* @name btcturk#fetchOrderBook
* @description fetches information on open orders with bid (buy) and ask (sell) prices, volumes and other data
* @see https://docs.btcturk.com/public-endpoints/orderbook
* @param {string} symbol unified symbol of the market to fetch the order book for
* @param {int} [limit] the maximum amount of order book entries to return
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} an [order book structure]{@link https://docs.ccxt.com/?id=order-book-structure}
*/
pub async fn fetch_order_book(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut limit = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("pairSymbol".to_string(), get_value(&market, &Value::Str("id".to_string())));
m
});
let __ws_arg_0 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.public_get_orderbook(&[__ws_arg_0]).await;
// {
// "data": {
// "timestamp": 1618827901241,
// "bids": [
// [
// "460263.00",
// "0.04244000"
// ]
// ]
// }
// }
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut timestamp: Value = self.safe_integer_k(data.clone(), "timestamp", &[]);
return self.parse_order_book(data.clone(), get_value(&market, &Value::Str("symbol".to_string())), &[timestamp.clone(), Value::Str("bids".to_string()), Value::Str("asks".to_string()), Value::Int(0), Value::Int(1)]);
Value::Null
}
pub fn parse_ticker(&self, mut ticker: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// {
// "pair": "BTCTRY",
// "pairNormalized": "BTC_TRY",
// "timestamp": 1618826361234,
// "last": 462485,
// "high": 473976,
// "low": 444201,
// "bid": 461928,
// "ask": 462485,
// "open": 456915,
// "volume": 917.41368645,
// "average": 462868.29574589,
// "daily": 5570,
// "dailyPercent": 1.22,
// "denominatorSymbol": "TRY",
// "numeratorSymbol": "BTC",
// "order": 1000
// }
//
let mut marketId: Value = self.safe_string_k(ticker.clone(), "pair", &[]);
market = self.safe_market(&[marketId.clone(), market.clone()]);
let mut symbol: Value = get_value(&market, &Value::Str("symbol".to_string()));
let mut timestamp: Value = self.safe_integer_k(ticker.clone(), "timestamp", &[]);
let mut last: Value = self.safe_string_k(ticker.clone(), "last", &[]);
return self.safe_ticker(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), symbol.clone());
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
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(), self.safe_string_k(ticker.clone(), "bid", &[]));
m.insert("bidVolume".to_string(), Value::Null);
m.insert("ask".to_string(), self.safe_string_k(ticker.clone(), "ask", &[]));
m.insert("askVolume".to_string(), Value::Null);
m.insert("vwap".to_string(), Value::Null);
m.insert("open".to_string(), self.safe_string_k(ticker.clone(), "open", &[]));
m.insert("close".to_string(), last.clone());
m.insert("last".to_string(), last.clone());
m.insert("previousClose".to_string(), Value::Null);
m.insert("change".to_string(), self.safe_string_k(ticker.clone(), "daily", &[]));
m.insert("percentage".to_string(), self.safe_string_k(ticker.clone(), "dailyPercent", &[]));
m.insert("average".to_string(), self.safe_string_k(ticker.clone(), "average", &[]));
m.insert("baseVolume".to_string(), self.safe_string_k(ticker.clone(), "volume", &[]));
m.insert("quoteVolume".to_string(), Value::Null);
m.insert("info".to_string(), ticker.clone());
m
}), &[market.clone()]);
Value::Null
}
/*
* @method
* @name btcturk#fetchTickers
* @description fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market
* @see https://docs.btcturk.com/public-endpoints/ticker
* @param {string[]|undefined} symbols unified symbols of the markets to fetch the ticker for, all market tickers are returned if not assigned
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a dictionary of [ticker structures]{@link https://docs.ccxt.com/?id=ticker-structure}
*/
pub async fn fetch_tickers(&mut self, optional_args: &[Value]) -> Value {
let mut symbols = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut response: Value = self.public_get_ticker(&[params.clone()]).await;
let mut tickers: Value = self.safe_list_k(response.clone(), "data", &[]);
return self.parse_tickers(tickers.clone(), &[symbols.clone()]);
Value::Null
}
/*
* @method
* @name btcturk#fetchTicker
* @description fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
* @see https://docs.btcturk.com/public-endpoints/ticker
* @param {string} symbol unified symbol of the market to fetch the ticker for
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a [ticker structure]{@link https://docs.ccxt.com/?id=ticker-structure}
*/
pub async fn fetch_ticker(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut tickers: Value = self.fetch_tickers(&[Value::List(vec![symbol.clone()]), params.clone()]).await;
return self.safe_value(tickers.clone(), symbol.clone(), &[]);
Value::Null
}
pub fn parse_trade(&self, mut trade: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// fetchTrades
// {
// "pair": "BTCUSDT",
// "pairNormalized": "BTC_USDT",
// "numerator": "BTC",
// "denominator": "USDT",
// "date": "1618916879083",
// "tid": "637545136790672520",
// "price": "55774",
// "amount": "0.27917100",
// "side": "buy"
// }
//
// fetchMyTrades
// {
// "price": "56000",
// "numeratorSymbol": "BTC",
// "denominatorSymbol": "USDT",
// "orderType": "buy",
// "orderId": "2606935102",
// "id": "320874372",
// "timestamp": "1618916479593",
// "amount": "0.00020000",
// "fee": "0",
// "tax": "0"
// }
//
let mut timestamp: Value = self.safe_integer2(trade.clone(), Value::Str("date".to_string()), Value::Str("timestamp".to_string()), &[]);
let mut id: Value = self.safe_string2(trade.clone(), Value::Str("tid".to_string()), Value::Str("id".to_string()), &[]);
let mut order: Value = self.safe_string_k(trade.clone(), "orderId", &[]);
let mut priceString: Value = self.safe_string_k(trade.clone(), "price", &[]);
let mut amountString: Value = crate::precise::Precise::stringAbs(&self.safe_string_k(trade.clone(), "amount", &[]));
let mut marketId: Value = self.safe_string_k(trade.clone(), "pair", &[]);
let mut symbol: Value = self.safe_symbol(marketId.clone(), &[market.clone()]);
let mut side: Value = self.safe_string2(trade.clone(), Value::Str("side".to_string()), Value::Str("orderType".to_string()), &[]);
let mut fee: Value = Value::Null;
let mut feeAmountString: Value = self.safe_string_k(trade.clone(), "fee", &[]);
if !is_equal(&feeAmountString, &Value::Null) {
let mut feeCurrency: Value = self.safe_string_k(trade.clone(), "denominatorSymbol", &[]);
fee = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), crate::precise::Precise::stringAbs(&feeAmountString));
m.insert("currency".to_string(), self.safe_currency_code(feeCurrency.clone(), &[]));
m
});
}
return self.safe_trade(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), trade.clone());
m.insert("id".to_string(), id.clone());
m.insert("order".to_string(), order.clone());
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("symbol".to_string(), symbol.clone());
m.insert("type".to_string(), Value::Null);
m.insert("side".to_string(), side.clone());
m.insert("takerOrMaker".to_string(), Value::Null);
m.insert("price".to_string(), priceString.clone());
m.insert("amount".to_string(), amountString.clone());
m.insert("cost".to_string(), Value::Null);
m.insert("fee".to_string(), fee.clone());
m
}), &[market.clone()]);
Value::Null
}
/*
* @method
* @name btcturk#fetchTrades
* @description get the list of most recent trades for a particular symbol
* @see https://docs.btcturk.com/public-endpoints/trades
* @param {string} symbol unified symbol of the market to fetch trades for
* @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 {Trade[]} a list of [trade structures]{@link https://docs.ccxt.com/?id=public-trades}
*/
pub async fn fetch_trades(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut since = get_arg(optional_args, 0, Value::Null);
let mut limit = get_arg(optional_args, 1, Value::Null);
let mut params = get_arg(optional_args, 2, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
// let maxCount = 50;
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("pairSymbol".to_string(), get_value(&market, &Value::Str("id".to_string())));
m
});
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("last".to_string()), limit.clone());
}
let __ws_arg_1 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.public_get_trades(&[__ws_arg_1]).await;
//
// {
// "data": [
// {
// "pair": "BTCTRY",
// "pairNormalized": "BTC_TRY",
// "numerator": "BTC",
// "denominator": "TRY",
// "date": 1618828421497,
// "tid": "637544252214980918",
// "price": "462585.00",
// "amount": "0.01618411",
// "side": "sell"
// }
// ]
// }
//
let mut data: Value = self.safe_list_k(response.clone(), "data", &[]);
let mut dataList: Value = Value::List(vec![]);
if !is_equal(&data, &Value::Null) {
dataList = data.clone();
}
return self.parse_trades(dataList.clone(), &[market.clone(), since.clone(), limit.clone()]);
Value::Null
}
pub fn parse_ohlcv(&self, mut ohlcv: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
return Value::List(vec![self.safe_timestamp(ohlcv.clone(), Value::Str("timestamp".to_string()), &[]), self.safe_number_k(ohlcv.clone(), "open", &[]), self.safe_number_k(ohlcv.clone(), "high", &[]), self.safe_number_k(ohlcv.clone(), "low", &[]), self.safe_number_k(ohlcv.clone(), "close", &[]), self.safe_number_k(ohlcv.clone(), "volume", &[])]);
Value::Null
}
/*
* @method
* @name btcturk#fetchOHLCV
* @description fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market
* @see https://docs.btcturk.com/public-endpoints/get-kline-data
* @param {string} symbol unified symbol of the market to fetch OHLCV data for
* @param {string} timeframe the length of time each candle represents
* @param {int} [since] timestamp in ms of the earliest candle to fetch
* @param {int} [limit] the maximum amount of candles to fetch
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {int} [params.until] timestamp in ms of the latest candle to fetch
* @returns {int[][]} A list of candles ordered as timestamp, open, high, low, close, volume
*/
pub async fn fetch_ohlcv(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut timeframe = get_arg(optional_args, 0, Value::Str("1h".to_string()));
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), get_value(&market, &Value::Str("id".to_string())));
m.insert("resolution".to_string(), self.safe_value(self.timeframes.clone(), timeframe.clone(), &[timeframe.clone()]));
m
});
let mut until: Value = self.safe_integer_k(params.clone(), "until", &[self.milliseconds()]);
add_element_to_object(&mut request, &Value::Str("to".to_string()), self.parse_to_int((divide(&until, &Value::Int(1000)))));
if !is_equal(&since, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("from".to_string()), self.parse_to_int(divide(&since, &Value::Int(1000))));
} else if is_equal(&limit, &Value::Null) {
limit = Value::Int(100); // default value
}
if !is_equal(&limit, &Value::Null) {
limit = crate::runtime::Math::min(&limit, &Value::Int(11000)); // max 11000 candles diapason can be covered
if is_equal(&timeframe, &Value::Str("1y".to_string())) {
panic!("{}", crate::exchange_errors::bad_request(add(&self.id, &Value::Str(" fetchOHLCV () does not accept a limit parameter when timeframe == \"1y\"".to_string()))));
}
let mut seconds: Value = self.parse_timeframe(timeframe.clone());
let mut limitSeconds: Value = multiply(&seconds, &(subtract(&limit, &Value::Int(1))));
if !is_equal(&since, &Value::Null) {
let mut to: Value = add(&self.parse_to_int(divide(&since, &Value::Int(1000))), &limitSeconds);
{ let __be_tmp = crate::runtime::Math::min(&get_value(&request, &Value::Str("to".to_string())), &to); add_element_to_object(&mut request, &Value::Str("to".to_string()), __be_tmp); };
} else {
add_element_to_object(&mut request, &Value::Str("from".to_string()), subtract(&self.parse_to_int(divide(&Value::Int(0), &Value::Int(1000))), &limitSeconds));
}
}
let __ws_arg_2 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.graph_get_klines_history(&[__ws_arg_2]).await;
return self.parse_ohlc_vs(response.clone(), &[market.clone(), timeframe.clone(), since.clone(), limit.clone()]);
Value::Null
}
pub fn parse_ohlc_vs(&self, mut ohlcvs: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
let mut timeframe = get_arg(optional_args, 1, Value::Str("1m".to_string()));
let mut since = get_arg(optional_args, 2, Value::Null);
let mut limit = get_arg(optional_args, 3, Value::Null);
let mut tail = get_arg(optional_args, 4, Value::Bool(false));
let mut results: Value = Value::List(vec![]);
let mut timestamp: Value = self.safe_list_k(ohlcvs.clone(), "t", &[Value::List(vec![])]);
let mut high: Value = self.safe_list_k(ohlcvs.clone(), "h", &[Value::List(vec![])]);
let mut open: Value = self.safe_list_k(ohlcvs.clone(), "o", &[Value::List(vec![])]);
let mut low: Value = self.safe_list_k(ohlcvs.clone(), "l", &[Value::List(vec![])]);
let mut close: Value = self.safe_list_k(ohlcvs.clone(), "c", &[Value::List(vec![])]);
let mut volume: Value = self.safe_list_k(ohlcvs.clone(), "v", &[Value::List(vec![])]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_454: bool = true;
while { if !__for_first_454 { i = add(&i, &Value::Int(1)); } __for_first_454 = false; is_less_than(&i, &get_array_length(×tamp)) } {
let mut ohlcv: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("timestamp".to_string(), self.safe_integer(timestamp.clone(), i.clone(), &[]));
m.insert("high".to_string(), self.safe_number(high.clone(), i.clone(), &[]));
m.insert("open".to_string(), self.safe_number(open.clone(), i.clone(), &[]));
m.insert("low".to_string(), self.safe_number(low.clone(), i.clone(), &[]));
m.insert("close".to_string(), self.safe_number(close.clone(), i.clone(), &[]));
m.insert("volume".to_string(), self.safe_number(volume.clone(), i.clone(), &[]));
m
});
append_to_array(&mut results, self.parse_ohlcv(ohlcv.clone(), &[market.clone()]));
}
}
let mut sorted: Value = self.sort_by(results.clone(), Value::Int(0), &[]);
return self.filter_by_since_limit(sorted.clone(), &[since.clone(), limit.clone(), Value::Int(0), tail.clone()]);
Value::Null
}
/*
* @method
* @name btcturk#createOrder
* @description create a trade order
* @see https://docs.btcturk.com/private-endpoints/submit-order
* @param {string} symbol unified symbol of the market to create an order in
* @param {string} type 'market' or 'limit'
* @param {string} side 'buy' or 'sell'
* @param {float} amount how much of currency you want to trade in units of base currency
* @param {float} [price] the price at which the order is to be fulfilled, in units of the quote currency, ignored in market orders
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} an [order structure]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn create_order(&mut self, mut symbol: Value, mut type_var: Value, mut side: Value, mut amount: Value, optional_args: &[Value]) -> Value {
let mut price = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("orderType".to_string(), side.clone());
m.insert("orderMethod".to_string(), type_var.clone());
m.insert("pairSymbol".to_string(), get_value(&market, &Value::Str("id".to_string())));
m.insert("quantity".to_string(), self.amount_to_precision(symbol.clone(), amount.clone()));
m
});
if !is_equal(&type_var, &Value::Str("market".to_string())) {
add_element_to_object(&mut request, &Value::Str("price".to_string()), self.price_to_precision(symbol.clone(), price.clone()));
}
if is_true(&Value::Bool(in_op(¶ms, &Value::Str("clientOrderId".to_string())))) {
add_element_to_object(&mut request, &Value::Str("newClientOrderId".to_string()), get_value(¶ms, &Value::Str("clientOrderId".to_string())));
} else if !is_true(&(Value::Bool(in_op(¶ms, &Value::Str("newClientOrderId".to_string()))))) {
add_element_to_object(&mut request, &Value::Str("newClientOrderId".to_string()), self.uuid(&[]));
}
let __ws_arg_3 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_post_order(&[__ws_arg_3]).await;
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_order(data.clone(), &[market.clone()]);
Value::Null
}
/*
* @method
* @name btcturk#cancelOrder
* @description cancels an open order
* @see https://docs.btcturk.com/private-endpoints/cancel-order
* @param {string} id order id
* @param {string} symbol not used by cancelOrder ()
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} An [order structure]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn cancel_order(&mut self, mut id: Value, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), id.clone());
m
});
let __ws_arg_4 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_delete_order(&[__ws_arg_4]).await;
return self.safe_order(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), response.clone());
m
}), &[]);
Value::Null
}
/*
* @method
* @name btcturk#fetchOpenOrders
* @description fetch all unfilled currently open orders
* @see https://docs.btcturk.com/private-endpoints/open-orders
* @param {string} symbol unified market symbol
* @param {int} [since] the earliest time in ms to fetch open orders for
* @param {int} [limit] the maximum number of open orders structures to retrieve
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {Order[]} a list of [order structures]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn fetch_open_orders(&mut self, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut market: Value = Value::Null;
if !is_equal(&symbol, &Value::Null) {
market = self.market(symbol.clone());
add_element_to_object(&mut request, &Value::Str("pairSymbol".to_string()), get_value(&market, &Value::Str("id".to_string())));
}
let __ws_arg_5 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_get_open_orders(&[__ws_arg_5]).await;
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut bids: Value = self.safe_list_k(data.clone(), "bids", &[Value::List(vec![])]);
let mut asks: Value = self.safe_list_k(data.clone(), "asks", &[Value::List(vec![])]);
return self.parse_orders(self.array_concat(bids.clone(), asks.clone()), &[market.clone(), since.clone(), limit.clone()]);
Value::Null
}
/*
* @method
* @name btcturk#fetchOrders
* @description fetches information on multiple orders made by the user
* @see https://docs.btcturk.com/private-endpoints/all-orders
* @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
* @returns {Order[]} a list of [order structures]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn fetch_orders(&mut self, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("pairSymbol".to_string(), get_value(&market, &Value::Str("id".to_string())));
m
});
if !is_equal(&limit, &Value::Null) {
// default 100 max 1000
add_element_to_object(&mut request, &Value::Str("last".to_string()), limit.clone());
}
if !is_equal(&since, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("startTime".to_string()), math_floor(÷(&since, &Value::Int(1000))));
}
let __ws_arg_6 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_get_all_orders(&[__ws_arg_6]).await;
// {
// "data": [
// {
// "id": "2606012912",
// "price": "55000",
// "amount": "0.0003",
// "quantity": "0.0003",
// "stopPrice": "0",
// "pairSymbol": "BTCUSDT",
// "pairSymbolNormalized": "BTC_USDT",
// "type": "buy",
// "method": "limit",
// "orderClientId": "2ed187bd-59a8-4875-a212-1b793963b85c",
// "time": "1618913189253",
// "updateTime": "1618913189253",
// "status": "Untouched",
// "leftAmount": "0.0003000000000000"
// }
// ]
// }
let mut data: Value = self.safe_list_k(response.clone(), "data", &[]);
return self.parse_orders(data.clone(), &[market.clone(), since.clone(), limit.clone()]);
Value::Null
}
pub fn parse_order_status(&self, mut status: Value) -> Value {
let mut statuses: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("Untouched".to_string(), Value::Str("open".to_string()));
m.insert("Partial".to_string(), Value::Str("open".to_string()));
m.insert("Canceled".to_string(), Value::Str("canceled".to_string()));
m.insert("Closed".to_string(), Value::Str("closed".to_string()));
m
});
return self.safe_string(statuses.clone(), status.clone(), &[status.clone()]);
Value::Null
}
pub fn parse_order(&self, mut order: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// fetchOrders / fetchOpenOrders
// {
// "id": 2605984008,
// "price": "55000",
// "amount": "0.00050000",
// "quantity": "0.00050000",
// "stopPrice": "0",
// "pairSymbol": "BTCUSDT",
// "pairSymbolNormalized": "BTC_USDT",
// "type": "buy",
// "method": "limit",
// "orderClientId": "f479bdb6-0965-4f03-95b5-daeb7aa5a3a5",
// "time": 0,
// "updateTime": 1618913083543,
// "status": "Untouched",
// "leftAmount": "0.00050000"
// }
//
// createOrder
// {
// "id": "2606935102",
// "quantity": "0.0002",
// "price": "56000",
// "stopPrice": null,
// "newOrderClientId": "98e5c491-7ed9-462b-9666-93553180fb28",
// "type": "buy",
// "method": "limit",
// "pairSymbol": "BTCUSDT",
// "pairSymbolNormalized": "BTC_USDT",
// "datetime": "1618916479523"
// }
//
let mut id: Value = self.safe_string_k(order.clone(), "id", &[]);
let mut price: Value = self.safe_string_k(order.clone(), "price", &[]);
let mut amountString: Value = self.safe_string2(order.clone(), Value::Str("amount".to_string()), Value::Str("quantity".to_string()), &[]);
let mut amount: Value = crate::precise::Precise::stringAbs(&amountString);
let mut remaining: Value = self.safe_string_k(order.clone(), "leftAmount", &[]);
let mut marketId: Value = self.safe_string_k(order.clone(), "pairSymbol", &[]);
let mut symbol: Value = self.safe_symbol(marketId.clone(), &[market.clone()]);
let mut side: Value = self.safe_string_k(order.clone(), "type", &[]);
let mut type_var: Value = self.safe_string_k(order.clone(), "method", &[]);
let mut clientOrderId: Value = self.safe_string_k(order.clone(), "orderClientId", &[]);
let mut timestamp: Value = self.safe_integer2(order.clone(), Value::Str("updateTime".to_string()), Value::Str("datetime".to_string()), &[]);
let mut rawStatus: Value = self.safe_string_k(order.clone(), "status", &[]);
let mut status: Value = self.parse_order_status(rawStatus.clone());
return self.safe_order(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), order.clone());
m.insert("id".to_string(), id.clone());
m.insert("price".to_string(), price.clone());
m.insert("amount".to_string(), amount.clone());
m.insert("remaining".to_string(), remaining.clone());
m.insert("filled".to_string(), Value::Null);
m.insert("cost".to_string(), Value::Null);
m.insert("average".to_string(), Value::Null);
m.insert("status".to_string(), status.clone());
m.insert("side".to_string(), side.clone());
m.insert("type".to_string(), type_var.clone());
m.insert("clientOrderId".to_string(), clientOrderId.clone());
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("symbol".to_string(), symbol.clone());
m.insert("fee".to_string(), Value::Null);
m
}), &[market.clone()]);
Value::Null
}
/*
* @method
* @name btcturk#fetchMyTrades
* @description fetch all trades made by the user
* @see https://docs.btcturk.com/private-endpoints/user-transactions
* @param {string} symbol unified market symbol
* @param {int} [since] the earliest time in ms to fetch trades for
* @param {int} [limit] the maximum number of trades structures to retrieve
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {Trade[]} a list of [trade structures]{@link https://docs.ccxt.com/?id=trade-structure}
*/
pub async fn fetch_my_trades(&mut self, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = Value::Null;
if !is_equal(&symbol, &Value::Null) {
market = self.market(symbol.clone());
}
let mut response: Value = self.private_get_users_transactions_trade(&[]).await;
//
// {
// "data": [
// {
// "price": "56000",
// "numeratorSymbol": "BTC",
// "denominatorSymbol": "USDT",
// "orderType": "buy",
// "orderId": "2606935102",
// "id": "320874372",
// "timestamp": "1618916479593",
// "amount": "0.00020000",
// "fee": "0",
// "tax": "0"
// }
// ],
// "success": true,
// "message": "SUCCESS",
// "code": "0"
// }
//
let mut data: Value = self.safe_list_k(response.clone(), "data", &[]);
let mut dataList: Value = Value::List(vec![]);
if !is_equal(&data, &Value::Null) {
dataList = data.clone();
}
return self.parse_trades(dataList.clone(), &[market.clone(), since.clone(), limit.clone()]);
Value::Null
}
pub fn nonce(&self) -> Value {
return self.milliseconds();
Value::Null
}
pub fn sign(&self, mut path: Value, optional_args: &[Value]) -> Value {
let mut api = get_arg(optional_args, 0, Value::Str("public".to_string()));
let mut method = get_arg(optional_args, 1, Value::Str("GET".to_string()));
let mut params = get_arg(optional_args, 2, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut headers = get_arg(optional_args, 3, Value::Null);
let mut body = get_arg(optional_args, 4, Value::Null);
if is_equal(&self.id, &Value::Str("btctrader".to_string())) {
panic!("{}", crate::exchange_errors::exchange_error(add(&self.id, &Value::Str(" is an abstract base API for BTCExchange, BTCTurk".to_string()))));
}
let mut url: Value = add(&add(&get_value(&get_value(&self.urls, &Value::Str("api".to_string())), &api), &Value::Str("/".to_string())), &path);
if is_true(&(is_equal(&method, &Value::Str("GET".to_string())))) || is_true(&(is_equal(&method, &Value::Str("DELETE".to_string())))) {
if is_greater_than(&get_array_length(&object_keys(¶ms)), &Value::Int(0)) {
url = add(&url, &add(&Value::Str("?".to_string()), &self.urlencode(params.clone(), &[])));
}
} else {
body = self.json(params.clone());
}
if is_equal(&api, &Value::Str("private".to_string())) {
self.check_required_credentials(&[]);
let mut nonce: Value = to_string_val(&self.nonce());
let mut secret: Value = self.base64_to_binary(self.secret.clone(), &[]);
let mut auth: Value = add(&self.apiKey, &nonce);
headers = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("X-PCK".to_string(), self.apiKey.clone());
m.insert("X-Stamp".to_string(), nonce.clone());
m.insert("X-Signature".to_string(), self.hmac(self.encode(auth.clone()), secret.clone(), Value::Str("sha256".to_string()), &[Value::Str("base64".to_string())]));
m.insert("Content-Type".to_string(), Value::Str("application/json".to_string()));
m
});
}
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("url".to_string(), url.clone());
m.insert("method".to_string(), method.clone());
m.insert("body".to_string(), body.clone());
m.insert("headers".to_string(), headers.clone());
m
});
Value::Null
}
pub fn handle_errors(&self, mut code: Value, mut reason: Value, mut url: Value, mut method: Value, mut headers: Value, mut body: Value, mut response: Value, mut requestHeaders: Value, mut requestBody: Value) -> Value {
let mut errorCode: Value = self.safe_string_k(response.clone(), "code", &[Value::Str("0".to_string())]);
let mut message: Value = self.safe_string_k(response.clone(), "message", &[]);
let mut output: Value = ternary(is_true(&(is_equal(&message, &Value::Null))), body.clone(), message.clone());
self.throw_exactly_matched_exception(get_value(&self.exceptions, &Value::Str("exact".to_string())), message.clone(), add(&add(&self.id, &Value::Str(" ".to_string())), &output));
if is_true(&(!is_equal(&errorCode, &Value::Str("0".to_string())))) && is_true(&(!is_equal(&errorCode, &Value::Str("SUCCESS".to_string())))) {
panic!("{}", crate::exchange_errors::exchange_error(add(&add(&self.id, &Value::Str(" ".to_string())), &output)));
}
return Value::Null;
Value::Null
}
}