skka3134

skka3134

email
telegram

Cryptocurrency quantification cctx

  1. Install Anaconda and PyCharm. Anaconda is a Python environment and PyCharm is a Python editor.
    https://anaconda.org/anaconda/conda
    https://www.jetbrains.com/pycharm/
  2. Open the terminal and check which environments are available.
conda env list

image
3. Delete the environment "py1".

conda env remove -n py1
  1. Open PyCharm and create a new project. Choose Python version 3.8.
    image
  2. Install the package "ccxt". ccxt encapsulates the APIs of most exchanges worldwide.
pip install ccxt
  1. Create a new .py file and get all exchanges.
import ccxt
print(ccxt.exchanges)
  1. Instantiate a Binance exchange.
binance_exchange = ccxt.binance({
})
print('Exchange ID:', binance_exchange.id)
print('Exchange Name:', binance_exchange.name)
print('Supports Public API:', binance_exchange.has['publicAPI'])
print('Supports Private API:', binance_exchange.has['privateAPI'])
print('Supported Timeframes:', binance_exchange.timeframes)
print('Maximum Wait Time (s):', binance_exchange.timeout/1000)
print('Request Rate Limit (s):', binance_exchange.rateLimit/1000)
print('Current Time:', binance_exchange.iso8601(ccxt.binance.milliseconds()))

If using the OKEX exchange, it would be ccxt.okex().
The apiKey and secret are the API key we applied for on the exchange.
For OKEX, a password is also required, but not for other exchanges.

binance_exchange = ccxt.binance({
    'apiKey': '',
    'secret': '',
    'timeout': 15000,
    'enableRateLimit': True,
})
  1. Get market information.
binance_markets = binance_exchange.load_markets()
print(binance_exchange.id, binance_markets) 
  1. Get order book information.
symbol = 'BTC/USDT'
orderbook = exchange.fetch_order_book(symbol)
print('Order Book:', orderbook)
print('Bids:', orderbook['bids'])
print('Asks:', orderbook['asks'])
  1. Get ticker information.
if (exchange.has['fetchTicker']):
    print(exchange.fetch_ticker(symbol))
  1. Get candlestick data.
kline_data = exchange.fetch_ohlcv(symbol, '1d')
print('Candlestick Data:', kline_data)
  1. Get public trades.
public_trade = exchange.fetch_trades(symbol)
print('Public Trades:', public_trade)
  1. Get balance.
balance = exchange.fetch_balance()
print('Balance:', balance)
print('USDT Balance:', balance['USDT'])
print('Free USDT Balance:', balance['USDT']['free'])
  1. Get trades.
all_orders = exchange.fetch_orders(symbol=symbol)
print('All Orders:', all_orders)
open_orders = exchange.fetch_open_orders(symbol=symbol)
print('Open Orders:', open_orders)
  1. Get specific order information.
order_info = exchange.fetch_order('545646', 'BTC/USDT')
print('Order Info:', order_info) 
  1. Place an order. The second parameter is the quantity and the third parameter is the price.
exchange.create_limit_buy_order('BTC/USDT', 1, 2)
exchange.cancel_order('54646554')
Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.