Skip to main content

A Python framework for accessing multiple cryptocurrency exchanges APIs

Project description

Crypto Exchange API

A Python framework for accessing multiple cryptocurrency exchanges' APIs.

Supported Exchanges

  • Binance
  • OKX
  • Bitget
  • Kucoin
  • MEXC
  • Gate.io
  • Bybit
  • Kraken
  • BTSE

Installation

pip install crypto_exchange_api

Usage

First, import the necessary modules and set up your API configurations:

from crypto_exchange import CryptoAPIManager, ExchangeConfig, ExchangeName

# Create a manager instance
manager = CryptoAPIManager()

# Set up your API configurations
binance_config = ExchangeConfig(api_key='your_binance_api_key', api_secret='your_binance_api_secret')
okx_config = ExchangeConfig(api_key='your_okx_api_key', api_secret='your_okx_api_secret', api_passphrase='your_okx_api_passphrase')
bitget_config = ExchangeConfig(api_key='your_bitget_api_key', api_secret='your_bitget_api_secret', api_passphrase='your_bitget_api_passphrase')
kucoin_config = ExchangeConfig(api_key='your_kucoin_api_key', api_secret='your_kucoin_api_secret', api_passphrase='your_kucoin_api_passphrase')
mexc_config = ExchangeConfig(api_key='your_mexc_api_key', api_secret='your_mexc_api_secret')
gateio_config = ExchangeConfig(api_key='your_gateio_api_key', api_secret='your_gateio_api_secret')
bybit_config = ExchangeConfig(api_key='your_bybit_api_key', api_secret='your_bybit_api_secret')
kraken_config = ExchangeConfig(api_key='your_kraken_api_key', api_secret='your_kraken_api_secret')

# get exchanges to the manager
binance = manager.add_exchange(ExchangeName.BINANCE, binance_config).get_exchange()
okx = manager.add_exchange(ExchangeName.OKX, okx_config).get_exchange()
bitget = manager.add_exchange(ExchangeName.BITGET, bitget_config).get_exchange()
kucoin= manager.add_exchange(ExchangeName.KUCOIN, kucoin_config).get_exchange()
mexc = manager.add_exchange(ExchangeName.MEXC, mexc_config).get_exchange()
gate = manager.add_exchange(ExchangeName.GATEIO, gateio_config).get_exchange()
bybit = manager.add_exchange(ExchangeName.BYBIT, bybit_config).get_exchange()
kraken = manager.add_exchange(ExchangeName.KRAKEN,kraken_config).get_exchange()

Explanation of the signed Parameter

The signed parameter indicates whether the request requires authentication. Public endpoints (such as market data) do not require authentication and can be accessed with signed=False. Private endpoints (such as account data or trading) require authentication and must be accessed with signed=True.

Examples

Binance

Public Endpoint (Market Data)

# Get the latest price of BTC/USDT
response = binance.send_request( 'GET', '/api/v3/ticker/price', params={'symbol': 'BTCUSDT'}, signed=False)
print(response)

Private Endpoint (Withdraw Funds)

# Withdraw funds from your Binance account
params = {
    'coin': 'USDT',
    'withdrawOrderId': '123456',
    'amount': 10,
    'network': 'BSC',
    'address': 'your_usdt_address'
}
response = binance.send_request('POST', '/sapi/v1/capital/withdraw/apply', params=params, signed=True)
print(response)

OKX

Public Endpoint (Market Data)

# Get the ticker information for BTC/USDT
response = okx.send_request('GET', '/api/v5/market/ticker', params={'instId': 'BTC-USDT'}, signed=False)
print(response)

Private Endpoint (Withdraw Funds)

# Withdraw funds from your OKX account
params = {
    'ccy': 'USDT',
    'amt': '10',
    'dest': '4',  # 4 means withdrawal to external address
    'toAddr': 'your_usdt_address',
    'fee': '0.5'
}
response = okx.send_request('POST', '/api/v5/asset/withdrawal', params=params, signed=True)
print(response)

Bitget

Public Endpoint (Market Data)

# Get the latest price of BTC/USDT
response = bitget.send_request('GET', '/api/v2/spot/market/tickers', params={'symbol': 'BTCUSDT'}, signed=False)
print(response)

Private Endpoint (Withdraw Funds)

# Withdraw funds from your Bitget account
params = {
    'coin': 'USDT',
    'address': 'your_usdt_address',
    'size': '10',
    'tag': '',
    'chain': 'TRX',
    'clientOid': '123456'
}
response = bitget.send_request('POST', '/api/v2/spot/wallet/withdrawal', params=params, signed=True)
print(response)

Kucoin

Public Endpoint (Market Data)

# Get all ticker information
response = kucoin.send_request('GET', '/api/v1/market/allTickers', signed=False)
print(response)

Private Endpoint (Withdraw Funds)

# Withdraw funds from your Kucoin account
params = {
    'currency': 'BTC',
    'address': 'your_btc_address',
    'amount': '0.01',
    'memo': '',
    'chain': 'BTC'
}
response = kucoin.send_request('POST', '/api/v1/withdrawals', params=params, signed=True)
print(response)

MEXC

Public Endpoint (Market Data)

# Get the latest price of BTC/USDT
response = mexc.send_request('GET', '/api/v3/ticker/price', params={'symbol': 'BTCUSDT'}, signed=False)
print(response)

Private Endpoint (Withdraw Funds)

# Withdraw funds from your MEXC account
params = {
    'coin': 'BTC',
    'withdrawOrderId': 'xxxx',
    'address': 'your_btc_address',
    'amount': '0.01',
    'netWork': 'BTC'
}
response = mexc.send_request('POST', '/api/v3/capital/withdraw', params=params, signed=True)
print(response)

Gate.io

Public Endpoint (Market Data)

# Get the ticker information for BTC/USDT
response = gate.send_request('GET', 'v4/spot/currency_pairs/BTC_USDT', signed=False)
print(response)

Private Endpoint (Withdraw Funds)

# Withdraw funds from your Gate.io account
params = {
    'withdraw_order_id':'123456', 
    'currency': 'BTC',
    'address': 'your_btc_address',
    'amount': '0.01',
    'chain': 'BTC',
}
response = gate.send_request('POST', '/api/v4/withdrawals', params=params, signed=True)
print(response)

Bybit

Public Endpoint (Market Data)

# Get the latest price of BTC/USDT
response = bybit.send_request('GET', '/v5/market/tickers', params={'symbol': 'BTCUSDT', 'category': 'spot'},
                                  signed=False)
print(response)

Private Endpoint (Withdraw Funds)

# Withdraw funds from your Bybit account
params = {
    'coin': 'BTC',
    'chain': 'BTC',
    'address': 'your_btc_address',
    'amount': '0.01',
    'timestamp': 1672196561407,
    'forceChain': 0,
    'accountType': 'FUND'
}
response = bybit.send_request('POST', '/v5/asset/withdraw/create', params=params, signed=True)
print(response)

Kraken

Public Endpoint (Market Data)

# Get the latest price of BTC/USD
response = kraken.send_request('GET', '/0/public/Ticker', params={'pair': 'XBTUSD'}, signed=False)
print(response)

Private Endpoint (Withdraw Funds)

# Withdraw funds from your Kraken account
params = {
    'asset': 'BTC',
    'key': 'your_withdrawal_key',
    'amount': '0.01',
    'address':'your_btc_address'
}
response = kraken.send_request('POST', '/0/private/Withdraw', params=params, signed=True)
print(response)

...

License

This project is licensed under the MIT License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

crypto_exchange_api-0.1.9.tar.gz (7.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

crypto_exchange_api-0.1.9-py3-none-any.whl (7.4 kB view details)

Uploaded Python 3

File details

Details for the file crypto_exchange_api-0.1.9.tar.gz.

File metadata

  • Download URL: crypto_exchange_api-0.1.9.tar.gz
  • Upload date:
  • Size: 7.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.8

File hashes

Hashes for crypto_exchange_api-0.1.9.tar.gz
Algorithm Hash digest
SHA256 38247b664f940af543cd3315d2f36156c0ca1738864f4d949388a985bfe33ff9
MD5 fc340dec05eee980ea073e5e7d8a01a6
BLAKE2b-256 6f435451a9ba07f3a0f7d7af2e0cf57969eea34ee894b7dcb9e75aa529a5836b

See more details on using hashes here.

File details

Details for the file crypto_exchange_api-0.1.9-py3-none-any.whl.

File metadata

File hashes

Hashes for crypto_exchange_api-0.1.9-py3-none-any.whl
Algorithm Hash digest
SHA256 780b57e48f4a0239b1bae86044412bab2170b2c2212b711dc1b74ab2fa8d95f1
MD5 3cedcf5268d04690a9b5a2dfb696027d
BLAKE2b-256 b01f123305646d238df95d84f9ec18dcbdb9b8a7f84789d70d49a20d5c0d1a33

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page