{"id":42772619,"url":"https://github.com/vispar-tech/aiotrade","last_synced_at":"2026-04-26T11:03:10.201Z","repository":{"id":335303509,"uuid":"1145140680","full_name":"vispar-tech/aiotrade","owner":"vispar-tech","description":"High-performance async exchanges API clients for Python with intelligent session and cache management.","archived":false,"fork":false,"pushed_at":"2026-04-24T11:41:31.000Z","size":450,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-04-24T13:33:25.840Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/vispar-tech.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-01-29T13:29:56.000Z","updated_at":"2026-04-24T11:41:33.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/vispar-tech/aiotrade","commit_stats":null,"previous_names":["vispar-tech/aiotrade"],"tags_count":36,"template":false,"template_full_name":null,"purl":"pkg:github/vispar-tech/aiotrade","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vispar-tech%2Faiotrade","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vispar-tech%2Faiotrade/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vispar-tech%2Faiotrade/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vispar-tech%2Faiotrade/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vispar-tech","download_url":"https://codeload.github.com/vispar-tech/aiotrade/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vispar-tech%2Faiotrade/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32294592,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-26T09:34:17.070Z","status":"ssl_error","status_checked_at":"2026-04-26T09:34:00.993Z","response_time":129,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2026-01-29T22:00:30.801Z","updated_at":"2026-04-26T11:03:10.188Z","avatar_url":"https://github.com/vispar-tech.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# aiotrade\n\n[![PyPI version](https://badge.fury.io/py/aiotrade-sdk.svg)](https://pypi.org/project/aiotrade-sdk/) [![Python versions](https://img.shields.io/pypi/pyversions/aiotrade-sdk.svg)](https://pypi.org/project/aiotrade-sdk/) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n\n[![BingX](https://img.shields.io/badge/BingX-supported-blue?logo=bingx)](https://bingx.com) [![Bybit](https://img.shields.io/badge/Bybit-supported-gold?logo=bybit)](https://bybit.com) [![OKX](https://img.shields.io/badge/OKX-supported-black?logo=okx)](https://okx.com) [![Bitget](https://img.shields.io/badge/Bitget-supported-teal?logo=bitget)](https://www.bitget.com/) [![Binance](https://img.shields.io/badge/Binance-supported-yellow?logo=binance)](https://www.binance.com/) [![KuCoin](https://img.shields.io/badge/KuCoin-supported-lightgreen?logo=kucoin)](https://www.kucoin.com/) [![Gate](https://img.shields.io/badge/Gate-supported-red?logo=gate)](https://www.gate.io/)\n\nHigh-performance async trading API client for Python supporting BingX, Bybit, OKX, Bitget, Binance and Kucoin exchanges with intelligent session and cache management.\n\n## Architecture\n\nThe library uses a sophisticated architecture for optimal performance:\n\n### Session Management\n\n- **Shared Session**: `SharedSessionManager` creates a single aiohttp session with high-performance connection pooling\n- **Individual Sessions**: Clients automatically create individual sessions if shared session isn't initialized\n- **Connection Pooling**: Up to 2000 concurrent connections with smart distribution per host\n\n### Client Caching\n\n- **TTL Cache**: `BingxClientsCache`, `BybitClientsCache` and etc. cache client instances with 10-minute lifetime\n- **Lock-Free**: No blocking operations for maximum performance\n- **Lazy Cleanup**: Expired entries removed on access, not proactively\n\n#### Implemented methods\n\n1. **Use Shared Session** for applications creating many clients\n2. **Enable Caching** for repeated API credential usage\n3. **Configure Connection Limits** based on your throughput needs\n4. **Use Background Cleanup** for long-running applications\n\n#### Available clients methods\n\n```text\nBybitClient methods (42):\n    batch_cancel_order                     get_server_time\n    batch_place_order                      get_smp_group_id\n    batch_set_collateral_coin              get_trade_behaviour_setting\n    cancel_all_orders                      get_transaction_log\n    cancel_order                           get_transferable_amount\n    get_account_info                       get_wallet_balance\n    get_account_instruments_info           manual_borrow\n    get_api_key_info                       manual_repay\n    get_borrow_history                     manual_repay_without_asset_conversion\n    get_closed_pnl                         place_order\n    get_coin_greeks                        repay_liability\n    get_collateral_info                    reset_mmp\n    get_dcp_info                           set_collateral_coin\n    get_fee_rate                           set_leverage\n    get_instruments_info                   set_limit_price_behaviour\n    get_kline                              set_margin_mode\n    get_mmp_state                          set_mmp\n    get_open_and_closed_orders             set_spot_hedging\n    get_order_history                      set_trading_stop\n    get_position_info                      switch_position_mode\n    get_risk_limit                         upgrade_to_unified_account_pro\n\nBingxClient methods (47):\n    cancel_all_spot_open_orders                get_spot_profit_overview\n    cancel_all_swap_open_orders                get_spot_symbols\n    cancel_spot_batch_orders                   get_spot_trade_details\n    cancel_swap_batch_orders                   get_swap_account_balance\n    change_swap_margin_type                    get_swap_contracts\n    close_perpetual_trader_position_by_order   get_swap_full_orders\n    close_swap_position                        get_swap_klines\n    get_account_asset_overview                 get_swap_leverage_and_available_positions\n    get_account_uid                            get_swap_margin_type\n    get_api_permissions                        get_swap_open_orders\n    get_perpetual_copy_trading_pairs           get_swap_order_details\n    get_perpetual_current_trader_order         get_swap_order_history\n    get_perpetual_personal_trading_overview    get_swap_position_history\n    get_perpetual_profit_details               get_swap_position_mode\n    get_perpetual_profit_overview              get_swap_positions\n    get_server_time                            place_spot_order\n    get_spot_account_assets                    place_swap_batch_orders\n    get_spot_history_orders                    place_swap_order\n    get_spot_klines                            sell_spot_asset_by_order\n    get_spot_open_orders                       set_perpetual_commission_rate\n    get_spot_order_details                     set_perpetual_trader_tpsl_by_order\n    get_spot_order_history                     set_swap_leverage\n    get_spot_personal_trading_overview         set_swap_position_mode\n    get_spot_profit_details\n\nOkxClient methods (23):\n    batch_place_order        get_order\n    cancel_algo_orders       get_orders_history\n    cancel_batch_orders      get_orders_pending\n    close_position           get_position_tiers\n    get_account_config       get_positions\n    get_algo_order           get_positions_history\n    get_algo_orders_history  get_server_time\n    get_algo_orders_pending  place_algo_order\n    get_balance              set_isolated_mode\n    get_funding_balance      set_leverage\n    get_instruments          set_position_mode\n    get_leverage_info\n\nBitgetClient methods (34):\n    batch_cancel_futures_orders  get_order_detail\n    batch_cancel_spot_orders     get_pending_orders\n    batch_place_futures_orders   get_pending_trigger_orders\n    batch_place_spot_orders      get_server_time\n    cancel_all_futures_orders    get_single_account\n    cancel_order                 get_spot_history_orders\n    cancel_order_by_symbol       get_symbol_info\n    cancel_trigger_orders        get_trade_rate\n    flash_close_position         get_unfilled_orders\n    get_account_assets           place_futures_order\n    get_account_info             place_spot_order\n    get_account_list             place_tpsl_plan_order\n    get_all_positions            place_trigger_order\n    get_contract_config          set_asset_mode\n    get_futures_history_orders   set_leverage\n    get_historical_position      set_margin_mode\n    get_isolated_symbols         set_position_mode\n\nBinanceClient methods (35):\n    cancel_algo_order            get_api_key_permissions\n    cancel_all_algo_open_orders  get_exchange_info\n    cancel_all_open_orders       get_income_history\n    cancel_batch_orders          get_klines\n    cancel_order                 get_multi_assets_mode\n    change_leverage              get_open_algo_orders\n    change_margin_type           get_open_order\n    change_multi_assets_mode     get_open_orders\n    change_position_mode         get_order\n    create_algo_order            get_position_info\n    create_batch_orders          get_position_info_v3\n    create_order                 get_position_mode\n    get_account_balance          get_spot_account_info\n    get_account_config           get_spot_all_orders\n    get_account_info             get_spot_open_orders\n    get_algo_order               get_symbol_config\n    get_all_algo_orders          get_user_trades\n    get_all_orders\n\nKuCoinClient methods (32):\n    add_order                       get_margin_mode\n    add_order_test                  get_order_by_client_oid\n    add_tp_sl_order                 get_order_by_order_id\n    batch_add_orders                get_order_list\n    batch_cancel_orders             get_position_details\n    batch_switch_margin_mode        get_position_mode\n    cancel_all_orders               get_positions\n    cancel_all_stop_orders          get_positions_history\n    cancel_order_by_client_oid      get_recent_closed_orders\n    cancel_order_by_id              get_recent_trade_history\n    get_all_symbols                 get_server_time\n    get_all_tickers                 get_service_status\n    get_api_key_info                get_stop_orders\n    get_futures_account             get_trade_history\n    get_isolated_margin_risk_limit  switch_margin_mode\n    get_klines                      switch_position_mode\n\nGateClient methods (31):\n    cancel_batch_future_orders          get_user_leverage_currency_setting\n    cancel_price_triggered_order        list_futures_candlesticks\n    create_batch_futures_order          list_futures_orders\n    create_futures_order                list_futures_risk_limit_tiers\n    create_price_triggered_order        list_futures_tickers\n    create_trailing_order               list_position_close\n    get_account_detail                  list_positions\n    get_account_main_keys               list_price_triggered_orders\n    get_futures_account                 list_trailing_orders\n    get_futures_contract                set_dual_mode\n    get_futures_contracts               set_unified_mode\n    get_futures_risk_limit_table        set_user_leverage_currency_setting\n    get_position                        terminate_trail_order\n    get_unified_account                 update_position_cross_mode\n    get_unified_mode                    update_position_leverage\n    get_user_leverage_currency_config\n```\n\n## Installation\n\n```bash\npoetry add aiotrade-sdk\n```\n\n## Quick Start\n\n### Option 1: Shared Session (Recommended for Production)\n\n```python\nfrom aiotrade import SharedSessionManager, BybitClient\n\n# Initialize shared session at startup (once per application)\nSharedSessionManager.setup(max_connections=2000)\n\n# Create Bybit client - will use the shared session\nbybit_client = BybitClient(api_key=\"bybit_key\", api_secret=\"bybit_secret\", testnet=True)\n\ntry:\n    # Use client for API calls\n    bybit_tickers = await bybit_client.get_tickers(category=\"spot\")\nfinally:\n    # Close shared session at shutdown\n    await SharedSessionManager.close()\n```\n\n### Option 2: Individual Bybit Session\n\n```python\nfrom aiotrade import BybitClient\n\n# Bybit client with individual session\nasync with BybitClient(api_key=\"your_key\", api_secret=\"your_secret\", testnet=True) as client:\n    tickers = await client.get_tickers(category=\"spot\")\n    print(f\"Bybit tickers: {tickers}\")\n```\n\n### Option 3: Cached Bybit Client\n\n```python\nfrom aiotrade import BybitClientsCache\n\n# Get cached Bybit client (creates new if doesn't exist)\nbybit_client = BybitClientsCache.get_or_create(\n    api_key=\"your_key\",\n    api_secret=\"your_secret\",\n    testnet=True\n)\n\n# Use cached client (session management is automatic)\nasync with bybit_client:\n    tickers = await bybit_client.get_tickers(category=\"spot\")\n\n# Same parameters return the same cached instance\ncached_bybit = BybitClientsCache.get_or_create(\n    api_key=\"your_key\",\n    api_secret=\"your_secret\",\n    testnet=True\n)\nassert bybit_client is cached_bybit  # True\n```\n\n## Session Behavior\n\n| Scenario                              | Session Type              | When Used              |\n| ------------------------------------- | ------------------------- | ---------------------- |\n| `SharedSessionManager.setup()` called | Shared session            | All clients            |\n| No shared session initialized         | Individual session        | Each client            |\n| Cached clients                        | Depends on initialization | Cached per credentials |\n\n## Cache Features\n\n- **Automatic TTL**: 10 minutes default, configurable\n- **Memory Safe**: Prevents client accumulation\n- **High Performance**: Lock-free operations\n- **Background Cleanup**: Optional periodic cleanup task\n\n```python\n# Configure cache lifetime for each exchange\nBingxClientsCache.configure(lifetime_seconds=1800)  # 30 minutes\nBybitClientsCache.configure(lifetime_seconds=1800)  # 30 minutes\nOkxClientsCache.configure(lifetime_seconds=1800)    # 30 minutes\nBitgetClientsCache.configure(lifetime_seconds=1800) # 30 minutes\n\n# Start background cleanup\nbingx_cleanup = BingxClientsCache.create_cleanup_task(interval_seconds=300)\nbybit_cleanup = BybitClientsCache.create_cleanup_task(interval_seconds=300)\nokx_cleanup = OkxClientsCache.create_cleanup_task(interval_seconds=300)\nbitget_cleanup = BitgetClientsCache.create_cleanup_task(interval_seconds=300)\n\n# Manual cleanup\nbingx_removed = BingxClientsCache.cleanup_expired()\nbybit_removed = BybitClientsCache.cleanup_expired()\nokx_removed = OkxClientsCache.cleanup_expired()\nbitget_removed = BitgetClientsCache.cleanup_expired()\n```\n\n## Requirements\n\n- Python \u003e= 3.12\n- aiohttp\n- High-performance connection pooling for production use\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvispar-tech%2Faiotrade","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvispar-tech%2Faiotrade","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvispar-tech%2Faiotrade/lists"}