CCXT
Python Examples

Binance Https Proxy

Binance Https Proxy — CCXT Python code example.

import os
import sys

# PLEASE DO NOT EDIT THIS FILE, IT IS GENERATED AND WILL BE OVERWRITTEN:
# https://github.com/ccxt/ccxt/blob/master/CONTRIBUTING.md#how-to-contribute-code

# AUTO-TRANSPILE #
'use strict'


print('CCXT Version:', ccxt.version)  # eslint-disable-line import/no-named-as-default-member


https_proxy_url = process.env.https_proxy or 'https://username:password@your-proxy.com'


wss_proxy_url = 'same or another'


print('Using proxy server', https_proxy_url)


async def main():
    # eslint-disable-next-line import/no-named-as-default-member
    exchange = ccxt.binance({
        'httpsProxy': https_proxy_url,
        'wssProxy': wss_proxy_url,
    })
    /*
    #
    # you can also use custom agent, like:
    #
    const HttpsProxyAgent = await import ('https-proxy-agent');
    const httpsAgent = new HttpsProxyAgent (httpsProxyUrl);
    const exchange = new ccxt.binance ({
    'httpsAgent': httpsAgent, # you can pass your custom agent
    'options': {
    'ws': {
    'options': { 'agent': httpsAgent },
    },
    },
    });
    """
    symbol = 'BTC/USDT'
    await exchange.load_markets()
    print('Markets loaded')
    # eslint-disable-next-line no-constant-condition
    while True:
        try:
            orderbook = await exchange.watch_order_book(symbol)
            print(exchange.iso8601(exchange.milliseconds()), symbol, orderbook['asks'][0], orderbook['bids'][0])
        except Exception as e:
            print(e)

    await exchange.close()

main()