Skip to main content

mexc-python

Python SDK (sync and async) for Mexc cryptocurrency exchange with Rest and WS capabilities.

Installation

pip install mexc-exchange-api

Usage

Sync

from mexc import MexcSync

def main():
    instance = MexcSync({})
    ob =  instance.fetch_order_book("BTC/USDC")
    print(ob)
    #
    # balance = instance.fetch_balance()
    # order = instance.create_order("BTC/USDC", "limit", "buy", 1, 100000)

main()

Async

import sys
import asyncio
from mexc import MexcAsync

### on Windows, uncomment below:
# if sys.platform == 'win32':
# 	asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())

async def main():
    instance = MexcAsync({})
    ob =  await instance.fetch_order_book("BTC/USDC")
    print(ob)
    #
    # balance = await instance.fetch_balance()
    # order = await instance.create_order("BTC/USDC", "limit", "buy", 1, 100000)

    # once you are done with the exchange
    await instance.close()

asyncio.run(main())

Websockets

import sys
from mexc import MexcWs

### on Windows, uncomment below:
# if sys.platform == 'win32':
# 	asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())

async def main():
    instance = MexcWs({})
    while True:
        ob = await instance.watch_order_book("BTC/USDC")
        print(ob)
        # orders = await instance.watch_orders("BTC/USDC")

    # once you are done with the exchange
    await instance.close()

asyncio.run(main())

Raw call

You can also construct custom requests to available "implicit" endpoints

        request = {
            'type': 'candleSnapshot',
            'req': {
                'coin': coin,
                'interval': tf,
                'startTime': since,
                'endTime': until,
            },
        }
        response = await instance.public_post_info(request)

Available methods

REST Unified

  • create_deposit_address(self, code: str, params: dict = {})
  • create_market_buy_order_with_cost(self, symbol: str, cost: float, params: dict = {})
  • create_market_sell_order_with_cost(self, symbol: str, cost: float, params: dict = {})
  • create_order(self, symbol: str, type: OrderType, side: OrderSide, amount: float, price: Num = None, params: dict = {})
  • create_orders(self, orders: list[OrderRequest], params: dict = {})
  • create_spot_order_request(self, market: object, type: Str, side: Str, amount: object, price: Num = None, marginMode: Str = None, params: dict = {})
  • create_spot_order(self, market: object, type: OrderType, side: object, amount: object, price: Num = None, marginMode: Str = None, params: dict = {})
  • create_swap_order(self, market: object, type: object, side: OrderSide, amount: object, price: Num = None, marginMode: Str = None, params: dict = {})
  • fetch_account_helper(self, type: Str, params: dict)
  • fetch_accounts(self, params: dict = {})
  • fetch_balance(self, params: dict = {})
  • fetch_bids_asks(self, symbols: Strings = None, params: dict = {})
  • fetch_canceled_orders(self, symbol: Str = None, since: Int = None, limit: Int = None, params: dict = {})
  • fetch_closed_orders(self, symbol: Str = None, since: Int = None, limit: Int = None, params: dict = {})
  • fetch_currencies(self, params: dict = {})
  • fetch_deposit_address(self, code: str, params: dict = {})
  • fetch_deposit_addresses_by_network(self, code: str, params: dict = {})
  • fetch_deposit_withdraw_fees(self, codes: Strings = None, params: dict = {})
  • fetch_deposits(self, code: Str = None, since: Int = None, limit: Int = None, params: dict = {})
  • fetch_funding_history(self, symbol: Str = None, since: Int = None, limit: Int = None, params: dict = {})
  • fetch_funding_interval(self, symbol: str, params: dict = {})
  • fetch_funding_rate_history(self, symbol: Str = None, since: Int = None, limit: Int = None, params: dict = {})
  • fetch_funding_rate(self, symbol: str, params: dict = {})
  • fetch_leverage_tiers(self, symbols: Strings = None, params: dict = {})
  • fetch_leverage(self, symbol: str, params: dict = {})
  • fetch_markets(self, params: dict = {})
  • fetch_my_trades(self, symbol: Str = None, since: Int = None, limit: Int = None, params: dict = {})
  • fetch_ohlcv(self, symbol: str, timeframe: str = '1m', since: Int = None, limit: Int = None, params: dict = {})
  • fetch_open_orders(self, symbol: Str = None, since: Int = None, limit: Int = None, params: dict = {})
  • fetch_order_book(self, symbol: str, limit: Int = None, params: dict = {})
  • fetch_order_trades(self, id: str, symbol: Str = None, since: Int = None, limit: Int = None, params: dict = {})
  • fetch_order(self, id: str, symbol: Str = None, params: dict = {})
  • fetch_orders_by_ids(self, ids: list[str], symbol: Str = None, params: dict = {})
  • fetch_orders_by_state(self, state: float, symbol: Str = None, since: Int = None, limit: Int = None, params: dict = {})
  • fetch_orders(self, symbol: Str = None, since: Int = None, limit: Int = None, params: dict = {})
  • fetch_position_mode(self, symbol: Str = None, params: dict = {})
  • fetch_position(self, symbol: str, params: dict = {})
  • fetch_positions_history(self, symbols: Strings = None, since: Int = None, limit: Int = None, params: dict = {})
  • fetch_positions(self, symbols: Strings = None, params: dict = {})
  • fetch_spot_markets(self, params: dict = {})
  • fetch_status(self, params: dict = {})
  • fetch_swap_markets(self, params: dict = {})
  • fetch_ticker(self, symbol: str, params: dict = {})
  • fetch_tickers(self, symbols: Strings = None, params: dict = {})
  • fetch_time(self, params: dict = {})
  • fetch_trades(self, symbol: str, since: Int = None, limit: Int = None, params: dict = {})
  • fetch_trading_fee(self, symbol: str, params: dict = {})
  • fetch_transaction_fees(self, codes: Strings = None, params: dict = {})
  • fetch_transfer(self, id: str, code: Str = None, params: dict = {})
  • fetch_transfers(self, code: Str = None, since: Int = None, limit: Int = None, params: dict = {})
  • fetch_withdrawals(self, code: Str = None, since: Int = None, limit: Int = None, params: dict = {})
  • add_margin(self, symbol: str, amount: float, params: dict = {})
  • cancel_all_orders(self, symbol: Str = None, params: dict = {})
  • cancel_order(self, id: str, symbol: Str = None, params: dict = {})
  • cancel_orders(self, ids: list[str], symbol: Str = None, params: dict = {})
  • close_all_positions(self, params: dict = {})
  • custom_parse_balance(self, response: dict, marketType: Str)
  • describe(self)
  • get_tif_from_raw_order_type(self, orderType: Str = None)
  • modify_margin_helper(self, symbol: str, amount: Num, addOrReduce: Str, params: dict = {})
  • nonce(self)
  • reduce_margin(self, symbol: str, amount: float, params: dict = {})
  • set_leverage(self, leverage: int, symbol: Str = None, params: dict = {})
  • set_margin_mode(self, marginMode: str, symbol: Str = None, params: dict = {})
  • set_position_mode(self, hedged: bool, symbol: Str = None, params: dict = {})
  • transfer(self, code: str, amount: float, fromAccount: str, toAccount: str, params: dict = {})
  • withdraw(self, code: str, amount: float, address: str, params: dict = {})

REST Raw

  • spot_public_get_announcements(request)
  • spot_public_get_ping(request)
  • spot_public_get_time(request)
  • spot_public_get_defaultsymbols(request)
  • spot_public_get_symbol_offline(request)
  • spot_public_get_exchangeinfo(request)
  • spot_public_get_depth(request)
  • spot_public_get_trades(request)
  • spot_public_get_historicaltrades(request)
  • spot_public_get_aggtrades(request)
  • spot_public_get_klines(request)
  • spot_public_get_avgprice(request)
  • spot_public_get_ticker_24hr(request)
  • spot_public_get_ticker_price(request)
  • spot_public_get_ticker_bookticker(request)
  • spot_public_get_etf_info(request)
  • spot_private_get_kyc_status(request)
  • spot_private_get_uid(request)
  • spot_private_get_apikeyinfo(request)
  • spot_private_get_order(request)
  • spot_private_get_openorders(request)
  • spot_private_get_allorders(request)
  • spot_private_get_account(request)
  • spot_private_get_mytrades(request)
  • spot_private_get_strategy_group(request)
  • spot_private_get_strategy_group_uid(request)
  • spot_private_get_tradefee(request)
  • spot_private_get_sub_account_list(request)
  • spot_private_get_sub_account_apikey(request)
  • spot_private_get_sub_account_asset(request)
  • spot_private_get_capital_config_getall(request)
  • spot_private_get_capital_deposit_hisrec(request)
  • spot_private_get_capital_withdraw_history(request)
  • spot_private_get_capital_withdraw_address(request)
  • spot_private_get_capital_deposit_address(request)
  • spot_private_get_capital_transfer(request)
  • spot_private_get_capital_transfer_tranid(request)
  • spot_private_get_capital_transfer_internal(request)
  • spot_private_get_capital_sub_account_universaltransfer(request)
  • spot_private_get_capital_convert(request)
  • spot_private_get_capital_convert_list(request)
  • spot_private_get_margin_loan(request)
  • spot_private_get_margin_allorders(request)
  • spot_private_get_margin_mytrades(request)
  • spot_private_get_margin_openorders(request)
  • spot_private_get_margin_maxtransferable(request)
  • spot_private_get_margin_priceindex(request)
  • spot_private_get_margin_order(request)
  • spot_private_get_margin_isolated_account(request)
  • spot_private_get_margin_maxborrowable(request)
  • spot_private_get_margin_repay(request)
  • spot_private_get_margin_isolated_pair(request)
  • spot_private_get_margin_forceliquidationrec(request)
  • spot_private_get_margin_isolatedmargindata(request)
  • spot_private_get_margin_isolatedmargintier(request)
  • spot_private_get_rebate_taxquery(request)
  • spot_private_get_rebate_detail(request)
  • spot_private_get_rebate_detail_kickback(request)
  • spot_private_get_rebate_refercode(request)
  • spot_private_get_rebate_affiliate_commission(request)
  • spot_private_get_rebate_affiliate_withdraw(request)
  • spot_private_get_rebate_affiliate_commission_detail(request)
  • spot_private_get_rebate_affiliate_campaign(request)
  • spot_private_get_rebate_affiliate_referral(request)
  • spot_private_get_rebate_affiliate_subaffiliates(request)
  • spot_private_get_rebate_affiliate_list(request)
  • spot_private_get_mxdeduct_enable(request)
  • spot_private_get_userdatastream(request)
  • spot_private_get_selfsymbols(request)
  • spot_private_get_asset_internal_transfer_record(request)
  • spot_private_post_order(request)
  • spot_private_post_order_test(request)
  • spot_private_post_apikeyinfo(request)
  • spot_private_post_sub_account_virtualsubaccount(request)
  • spot_private_post_sub_account_apikey(request)
  • spot_private_post_sub_account_futures(request)
  • spot_private_post_sub_account_margin(request)
  • spot_private_post_batchorders(request)
  • spot_private_post_strategy_group(request)
  • spot_private_post_strategy_group_uid(request)
  • spot_private_post_capital_withdraw_apply(request)
  • spot_private_post_capital_withdraw(request)
  • spot_private_post_capital_transfer(request)
  • spot_private_post_capital_transfer_internal(request)
  • spot_private_post_capital_deposit_address(request)
  • spot_private_post_capital_sub_account_universaltransfer(request)
  • spot_private_post_capital_convert(request)
  • spot_private_post_mxdeduct_enable(request)
  • spot_private_post_userdatastream(request)
  • spot_private_put_userdatastream(request)
  • spot_private_delete_order(request)
  • spot_private_delete_openorders(request)
  • spot_private_delete_order_all(request)
  • spot_private_delete_sub_account_apikey(request)
  • spot_private_delete_strategy_group(request)
  • spot_private_delete_strategy_group_uid(request)
  • spot_private_delete_margin_order(request)
  • spot_private_delete_margin_openorders(request)
  • spot_private_delete_userdatastream(request)
  • spot_private_delete_capital_withdraw(request)
  • contract_public_get_ping(request)
  • contract_public_get_detail(request)
  • contract_public_get_support_currencies(request)
  • contract_public_get_depth_symbol(request)
  • contract_public_get_depth_commits_symbol_limit(request)
  • contract_public_get_index_price_symbol(request)
  • contract_public_get_fair_price_symbol(request)
  • contract_public_get_funding_rate_symbol(request)
  • contract_public_get_kline_symbol(request)
  • contract_public_get_kline_index_price_symbol(request)
  • contract_public_get_kline_fair_price_symbol(request)
  • contract_public_get_deals_symbol(request)
  • contract_public_get_ticker(request)
  • contract_public_get_risk_reverse(request)
  • contract_public_get_risk_reverse_history(request)
  • contract_public_get_funding_rate_history(request)
  • contract_private_get_account_assets(request)
  • contract_private_get_account_asset_currency(request)
  • contract_private_get_account_transfer_record(request)
  • contract_private_get_account_profit_rate_type(request)
  • contract_private_get_account_asset_analysis_type(request)
  • contract_private_get_account_feedeductconfigs(request)
  • contract_private_get_account_asset_analysis_yesterday_pnl(request)
  • contract_private_get_account_asset_analysis_today_pnl(request)
  • contract_private_get_account_config_contractfeediscountconfig(request)
  • contract_private_get_order_fee_details(request)
  • contract_private_get_account_discounttype(request)
  • contract_private_get_account_asset_analysis_export(request)
  • contract_private_get_account_asset_book_order_deal_fee_total(request)
  • contract_private_get_account_contract_fee_rate(request)
  • contract_private_get_account_contract_zero_fee_rate(request)
  • contract_private_get_position_list_history_positions(request)
  • contract_private_get_position_open_positions(request)
  • contract_private_get_position_funding_records(request)
  • contract_private_get_position_position_mode(request)
  • contract_private_get_order_list_open_orders_symbol(request)
  • contract_private_get_order_list_open_orders(request)
  • contract_private_get_order_list_history_orders(request)
  • contract_private_get_order_list_order_deals_v3(request)
  • contract_private_get_order_external_symbol_external_oid(request)
  • contract_private_get_order_get_order_id(request)
  • contract_private_get_order_batch_query(request)
  • contract_private_get_order_deal_details_order_id(request)
  • contract_private_get_order_list_order_deals(request)
  • contract_private_get_order_list_close_orders(request)
  • contract_private_get_planorder_list_orders(request)
  • contract_private_get_stoporder_list_orders(request)
  • contract_private_get_stoporder_open_orders(request)
  • contract_private_get_stoporder_order_details_stop_order_id(request)
  • contract_private_get_account_risk_limit(request)
  • contract_private_get_account_tiered_fee_rate(request)
  • contract_private_get_position_leverage(request)
  • contract_private_get_account_tiered_fee_rate_v2(request)
  • contract_private_get_trackorder_list_orders(request)
  • contract_private_get_market_maker_self_trade_blacklist(request)
  • contract_private_get_market_maker_self_trade_blacklist_search(request)
  • contract_private_post_account_asset_analysis_v3(request)
  • contract_private_post_account_asset_analysis_calendar_daily_v3(request)
  • contract_private_post_account_asset_analysis_calendar_monthly_v3(request)
  • contract_private_post_account_asset_analysis_recent_v3(request)
  • contract_private_post_position_change_margin(request)
  • contract_private_post_position_change_auto_add_im(request)
  • contract_private_post_position_change_leverage(request)
  • contract_private_post_position_change_position_mode(request)
  • contract_private_post_position_reverse(request)
  • contract_private_post_position_close_all(request)
  • contract_private_post_order_create(request)
  • contract_private_post_order_submit(request)
  • contract_private_post_order_submit_batch(request)
  • contract_private_post_order_chase_limit_order(request)
  • contract_private_post_order_change_limit_order(request)
  • contract_private_post_order_cancel(request)
  • contract_private_post_order_batch_cancel_with_external(request)
  • contract_private_post_order_cancel_with_external(request)
  • contract_private_post_order_cancel_all(request)
  • contract_private_post_order_open_order_total_count(request)
  • contract_private_post_order_batch_query_with_external(request)
  • contract_private_post_account_change_risk_level(request)
  • contract_private_post_planorder_place(request)
  • contract_private_post_planorder_place_v2(request)
  • contract_private_post_planorder_cancel(request)
  • contract_private_post_planorder_cancel_all(request)
  • contract_private_post_planorder_change_stop_order(request)
  • contract_private_post_stoporder_place(request)
  • contract_private_post_stoporder_cancel(request)
  • contract_private_post_stoporder_cancel_all(request)
  • contract_private_post_stoporder_change_price(request)
  • contract_private_post_stoporder_change_plan_price(request)
  • contract_private_post_trackorder_place(request)
  • contract_private_post_trackorder_cancel(request)
  • contract_private_post_trackorder_change_order(request)
  • contract_private_post_market_maker_self_trade_blacklist_create(request)
  • contract_private_post_market_maker_self_trade_blacklist_update(request)
  • contract_private_post_market_maker_self_trade_blacklist_delete(request)
  • spot2_public_get_market_symbols(request)
  • spot2_public_get_market_coin_list(request)
  • spot2_public_get_common_timestamp(request)
  • spot2_public_get_common_ping(request)
  • spot2_public_get_market_ticker(request)
  • spot2_public_get_market_depth(request)
  • spot2_public_get_market_deals(request)
  • spot2_public_get_market_kline(request)
  • spot2_public_get_market_api_default_symbols(request)
  • spot2_private_get_account_info(request)
  • spot2_private_get_order_open_orders(request)
  • spot2_private_get_order_list(request)
  • spot2_private_get_order_query(request)
  • spot2_private_get_order_deals(request)
  • spot2_private_get_order_deal_detail(request)
  • spot2_private_get_asset_deposit_address_list(request)
  • spot2_private_get_asset_deposit_list(request)
  • spot2_private_get_asset_address_list(request)
  • spot2_private_get_asset_withdraw_list(request)
  • spot2_private_get_asset_internal_transfer_record(request)
  • spot2_private_get_account_balance(request)
  • spot2_private_get_asset_internal_transfer_info(request)
  • spot2_private_get_market_api_symbols(request)
  • spot2_private_post_order_place(request)
  • spot2_private_post_order_place_batch(request)
  • spot2_private_post_order_advanced_place_batch(request)
  • spot2_private_post_asset_withdraw(request)
  • spot2_private_post_asset_internal_transfer(request)
  • spot2_private_delete_order_cancel(request)
  • spot2_private_delete_order_cancel_by_symbol(request)
  • spot2_private_delete_asset_withdraw(request)
  • broker_private_get_sub_account_universaltransfer(request)
  • broker_private_get_sub_account_list(request)
  • broker_private_get_sub_account_status(request)
  • broker_private_get_sub_account_apikey(request)
  • broker_private_get_capital_deposit_subaddress(request)
  • broker_private_get_capital_deposit_subhisrec(request)
  • broker_private_get_capital_deposit_subhisrec_getall(request)
  • broker_private_get_rebate_taxquery(request)
  • broker_private_post_sub_account_virtualsubaccount(request)
  • broker_private_post_sub_account_apikey(request)
  • broker_private_post_capital_deposit_subaddress(request)
  • broker_private_post_capital_withdraw_apply(request)
  • broker_private_post_sub_account_universaltransfer(request)
  • broker_private_post_sub_account_futures(request)
  • broker_private_delete_sub_account_apikey(request)

WS Unified

  • describe(self)
  • watch_ticker(self, symbol: str, params: dict = {})
  • watch_tickers(self, symbols: Strings = None, params: dict = {})
  • watch_bids_asks(self, symbols: Strings = None, params: dict = {})
  • watch_spot_public(self, channel: str, messageHash: str, params: dict = {})
  • watch_spot_private(self, channel: str, messageHash: str, params: dict = {})
  • watch_swap_public(self, channel: str, messageHash: str, requestParams: dict, params: dict = {})
  • watch_swap_private(self, messageHash: str, params: dict = {})
  • watch_ohlcv(self, symbol: str, timeframe: str = '1m', since: Int = None, limit: Int = None, params: dict = {})
  • watch_order_book(self, symbol: str, limit: Int = None, params: dict = {})
  • get_cache_index(self, orderbook: object, cache: object)
  • watch_trades(self, symbol: str, since: Int = None, limit: Int = None, params: dict = {})
  • watch_my_trades(self, symbol: Str = None, since: Int = None, limit: Int = None, params: dict = {})
  • watch_orders(self, symbol: Str = None, since: Int = None, limit: Int = None, params: dict = {})
  • watch_balance(self, params: dict = {})
  • watch_funding_rate(self, symbol: str, params: dict = {})
  • un_watch_funding_rate(self, symbol: str, params: dict = {})
  • un_watch_ticker(self, symbol: str, params: dict = {})
  • un_watch_tickers(self, symbols: Strings = None, params: dict = {})
  • un_watch_bids_asks(self, symbols: Strings = None, params: dict = {})
  • un_watch_ohlcv(self, symbol: str, timeframe: str = '1m', params: dict = {})
  • un_watch_order_book(self, symbol: str, params: dict = {})
  • un_watch_trades(self, symbol: str, params: dict = {})
  • authenticate(self, subscriptionHash: Str, params: dict = {})
  • keep_alive_listen_key(self, listenKey: Str, params: dict = {})

Contribution

  • Give us a star ⭐
  • Fork and Clone! Awesome
  • Select existing issues or create a new issue.

Metadata

Release files for mexc-exchange-api 0.0.166

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mexc-exchange-api 0.0.166
File Size Uploaded Provenance Actions
mexc_exchange_api-0.0.166.tar.gz 352.7 kB Without provenance Details for mexc_exchange_api-0.0.166.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for mexc-exchange-api 0.0.166
File Interpreter ABI Platform Actions
mexc_exchange_api-0.0.166-py3-none-any.whl Python 3 none any Details for mexc_exchange_api-0.0.166-py3-none-any.whl

Total release size: 746.8 kB

Release files / mexc_exchange_api-0.0.166.tar.gz

Download URL mexc_exchange_api-0.0.166.tar.gz
Size 352.7 kB
Tags Source
SHA-256 checksum
How to use checksums
7ee6b814b9b7e6e99df137a19e44f40398432d9f2eba28dd12e8c7e7e6b72717
BLAKE2b-256 checksum
How to use checksums
7784f1ed73d901c3b334753e95cac53108502056a0d69b9b71e267e89565505a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.8

Release files / mexc_exchange_api-0.0.166-py3-none-any.whl

Download URL mexc_exchange_api-0.0.166-py3-none-any.whl
Size 394.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a3e5997b94acaa49c2f912397cba4351f1758109dee3eff62d06061b5e5e4e01
BLAKE2b-256 checksum
How to use checksums
ce256f0fa686442ed5a5ec51e660f98df8702a1e0f3f95ba1d4b85eaf8037d14
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.8

Security for mexc-exchange-api 0.0.166

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.0.166 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page