Code Monkey home page Code Monkey logo

bitcoinde_api's Introduction

bitcoinDE_API

Collection of functions to use bitcoin.de API in python, using twisted as asynchronous framework.

API

  • Tested in python2.7
  • Implements all API-calls

Classes

  • BitcoinDeAPI: Encapsulates the basic encryption handling nesseccary to communicate with the bitcoin.de API. Hooks for different error and success handlers are build in, following the async model of twisted.
  • BitcoinDeAPINonce: Adds an Error Handler in case the nonce is wrong. Tries to reset it to a sensible value
  • QueuedBitcoinDeAPI: Adds queueing support for requests to reflect bitcoin.de's credit system
  • PriorityBitcoinDeAPI: Adds priority awareness for requests

Queueing

As the bitcoin.de API restricts spamming using a credit-system, with requests costing between 2 and 3 credits each, a queueing system is added that tracks available credits and throttles requests accordingly. In case a retryperiode is returned, no requests are send out until the system has recovered. Requests are not send out back-to-back, but with a .2s gap. Otherwise bitcoin.de's nonce system might get confused, as proper order of delivery doesn't seem to be guaranteed. Connection pooling helps with this issue, otherwise a .4s gap has to be applied.

If the same request is already enqueued, waiting for execution, it doesn't get enqueued, but the callback is added to the first request's callback chain.

Responses

In addition the JSON dict containing the response-body, the following fields are added: {code': 200, u'credits': 18, u'errors': [], 'phrase': 'OK'}

socket.io

bitoin.de supplies a 'websocket' interface to inform in realtime about changes to the marketplace. It's based on socket.io (version 09.16 for ws. and ws1.bitcoin.de) and doesn't provide simple websocket connectivity. ws2. and ws3.bitcoin.de use version 2.0.11 of socket.io

Compatibility

Tested in both python2.7 and python3.7 with latest twisted library

Procedure

  • https Get request to base address returns connection-options (websocket,longpolling,...)
  • Switch to desired Protocol using the same https connection
  • Receive websocket packages, send heartbeat to keep connection open

Implementations for 09.16 and 2.0.11 differ slightly.

Implementation

bitcoinDEws implementation uses twisted basic.LineReceiver to make the GET request to the base-address, some crude line-magic to process the response and initiate the protocol-switching. No real websocket implementation is used, but a line-oriented bare minimum.

  • ClientIo0916Protocol/ClientIo2011Protocol encapsulates the basic connection handling
  • WSjsonBitcoinDEProtocol and -2 add JSON data handling
  • BitcoinWSSourceV09 and BitcoinWSSourceV20 implement Factories to handle each source
  • BitcoinWSmulti processes input from multiple sources (ws., ws1., ...)
  • Each event-type (add/rm/skn/po/spr) is implemented in it's own class
  • Each event-type is handled through a bitcoinWSeventstream, only forwarding first reception of an event from the sources
  • BitcoinDESubscribe offers a subscription service to add 'callbacks' for each event type, delivered through BitcoinWSmulti.Deliver, for use in async apps

bitcoinde_api's People

Contributors

matthiaslinden avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

bitcoinde_api's Issues

bitcoinDEws.py loses connection due to SSL error

The implementation of the websocket client seems to be broken (when executed on Windows 10, Linux/Docker works); it reports the following error(s):

WSSource1 09 started
WSSource2 09 started
WSSource3 20 started
WSSource4 20 started
('WSjson connectionLost', <twisted.python.failure.Failure OpenSSL.SSL.Error: [('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')]>)
('WSjson connectionLost', <twisted.python.failure.Failure OpenSSL.SSL.Error: [('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')]>)
('WSjson connectionLost', <twisted.python.failure.Failure OpenSSL.SSL.Error: [('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')]>)
('WSjson connectionLost', <twisted.python.failure.Failure OpenSSL.SSL.Error: [('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')]>)````

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.