Back to Ccxt

https://github.com/ccxt/ccxt/blob/master/CONTRIBUTING.md#how-to-contribute-code

wiki/examples/py/binance-https-proxy.md

4.5.561.5 KB
Original Source
python
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:[email protected]'


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()