GithubHelp home page GithubHelp logo

leobouloc / bitfinex_wss Goto Github PK

View Code? Open in Web Editor NEW

This project forked from crypto-toolbox/btfxwss

0.0 2.0 0.0 42 KB

Bitfinex Websocket API Client written in Python3

License: MIT License

Python 100.00%

bitfinex_wss's Introduction

bitfinex_wss

Client for Bitfinex Websocket API written in Python

Currently supports all public endpoints; authenticated channels are a work in progress.

Offers graceful exception handling of common server errors.

Data is stored within the object's attributes for BtfxWss; BtfxWssRaw dumps data to a given folder on the disk.

Sample Code:

Starting a session and subscribing to channels.

    from btfxwss import BtfxWss
    
    logging.basicConfig(level=logging.DEBUG, filename='test.log')
    log = logging.getLogger(__name__)

    fh = logging.FileHandler('test.log')
    fh.setLevel(logging.DEBUG)
    sh = logging.StreamHandler(sys.stdout)
    sh.setLevel(logging.DEBUG)

    log.addHandler(sh)
    log.addHandler(fh)
    
    wss = BtfxWss(key='my_api_key', secret='my_api_secret')
    wss.start()
    time.sleep(1)  # give the client some prep time to set itself up.
    
    # Subscribe to some channels
    wss.ticker('BTCUSD')
    wss.order_book('BTCUSD')
    
    # Send a ping - if this returns silently, everything's fine.
    wss.ping()
    
    # Do something else
    t = time.time()
    while time.time() - t < 10:
        pass

subscribing to authenticated channels:

    # Sub to all account channels (auth channels)
    wss.authenticate()
    
    # You may pass specific channels you want to subscribe to; However, this requires 
    # you to unauthenticate before, since filters cannot be updated on the fly
    wss.unauth()
    filters = ['trading', 'funding']
    wss.authenticate(*filters)

Accessing data stored in BtfxWss:

    print(wss.tickers['BTCUSD])
    print(wss.books['BTCUSD'].bids())  # prints all current bids for the BTCUSD order book
    print(wss.books['BTCUSD'].asks())  # prints all current asks for the BTCUSD order book

Unsubscribing from channels:

    wss.ticker('BTCUSD', unsubscribe=True)
    wss.ticker('BTCEUR', unsubscribe=True)

Shutting down the client:

    wss.stop()

Your help is required

If you find any bugs, error or have feature requests, please don't hesitate to open an issue. Be as descriptive as possible, and I'll look into the matter as soon as I can.

Donations Welcome!

BTC @ 3D4yuyf84eQUauyZLoQKyouPuThoxMMRZa

bitfinex_wss's People

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.