7 个版本

0.1.6 2021 年 12 月 15 日
0.1.5 2021 年 12 月 15 日

#114 in #exchange

MIT/Apache

61KB
1.5K SLoC

ftx-rs

FTX API 的非官方 Rust 库

用法

将此添加到您的 Cargo.toml

[dependencies]
ftx-rs = "0.1.6"

REST

    let api = Ftx::new(Some("api_key".into()), Some("secret_key".into());

    // subaccounts
    // api.subaccounts.get_subaccounts
    // api.subaccounts.create_subaccount
    // api.subaccounts.change_subaccount_name
    // api.subaccounts.delete_subaccount
    // api.subaccounts.get_subaccount_balances
    // api.subaccounts.transfer_subaccounts

    // markets
    // api.markets.get_markets
    // api.markets.get_market
    // api.markets.get_orderbook
    // api.markets.get_trades
    // api.markets.get_historical_prices

    // futures
    // api.futures.get_futures
    // api.futures.get_future
    // api.futures.get_stats
    // api.futures.get_funding_rates
    // api.futures.get_indexes_weights
    // api.futures.get_expired_futures

    // account
    // api.account.get_account
    // api.account.get_positions
    // api.account.change_account_leverage

    // wallet
    // api.wallet.get_coins
    // api.wallet.get_balances
    // api.wallet.get_all_balances
    // api.wallet.get_deposit_address
    // api.wallet.get_deposits
    // api.wallet.get_withdrawals
    // api.wallet.get_airdrops

    // orders
    // api.orders.get_open_orders
    // api.orders.get_order_history
    // api.orders.get_open_trigger_orders
    // api.orders.place_order
    // api.orders.modify_order
    // api.orders.modify_order_by_client_id
    // api.orders.get_order_status
    // api.orders.get_order_status_by_client_id
    // api.orders.cancel_order
    // api.orders.cancel_order_by_client_id
    // api.orders.cancel_all_orders
    // ...

    // fills
    // api.fills.get_fills
        
        

市场数据

use chrono::Local;
use ftx_rs::api::*;

fn main() {
    let api = Ftx::new(None, None);

    let markets = api.markets.get_markets();
    match markets {
        Ok(m) => {
            println!("markets: {:?}", m);
        }
        Err(e) => {
            println!("Error: {}", e);
        }
    }

    let market = api.markets.get_market("BTC-PERP");
    match market {
        Ok(m) => {
            println!("market: {:?}", m);
        }
        Err(e) => {
            println!("Error: {}", e);
        }
    }

    let orderbook = api.markets.get_orderbook("BTC-PERP", 20);
    match orderbook {
        Ok(ob) => {
            println!("orderbook: {:?}", ob);
        }
        Err(e) => {
            println!("Error: {}", e);
        }
    }

    let trades = api.markets.get_trades("BTC-PERP");
    match trades {
        Ok(t) => {
            println!("trades: {:?}", t);
        }
        Err(e) => {
            println!("Error: {}", e);
        }
    }

    let candles = api
        .markets
        .get_historical_prices("BTC-PERP", 300, 0, Local::now().timestamp());
    match candles {
        Ok(c) => {
            println!("candles: {:?}", c);
        }
        Err(e) => {
            println!("Error: {}", e);
        }
    }
    
    // ...
}

FTX_ENDPOINTS

API,请参阅 示例

FTX_WEBSOCKETS

WebSocket,请参阅 示例

依赖项

~27–42MB
~857K SLoC