Skip to main content

A toy server written in Sanic to mimic an online currency exchange, with a REST and websocket API.

Project description

coinblockpro

A toy server written in Sanic to mimic an online currency exchange, with REST and websocket APIs.

Installation

coinblockpro is available on the Python Package Index (PyPI).

pip install coinblockpro

Run

The bash script run_cbp_server is placed in the user's bin when the package is installed. Running:

./run_cbp_server

will produce output like the following:

[2020-10-05 19:19:37 +0100] [34227] [INFO] Creating ticker db at /tmp/tickers.db.
[2020-10-05 19:19:37 +0100] [34227] [INFO] Created db.
[2020-10-05 19:19:37 +0100] [34227] [INFO] Running websocket server.
[2020-10-05 19:19:37 +0100] [34227] [INFO] Goin' Fast @ http://0.0.0.0:8001
[2020-10-05 19:19:37 +0100] [34227] [INFO] Starting modulation coroutine.
[2020-10-05 19:19:37 +0100] [34227] [INFO] Starting worker [34227]
[2020-10-05 19:19:38 +0100] [34228] [INFO] Running REST server.
[2020-10-05 19:19:38 +0100] [34228] [INFO] Goin' Fast @ http://0.0.0.0:8000
[2020-10-05 19:19:38 +0100] [34228] [INFO] Starting worker [34228]
[2020-10-05 19:19:43 +0100] [34227] [INFO] update to market btc_ltc: 3350.505 -> 3292.16
[2020-10-05 19:19:49 +0100] [34227] [INFO] update to market ltc_dot: 2752.763 -> 2708.661

Connecting to the server

The server runs on the localhost.

The REST API is available on port 8000, while the websocket API is available on port 8001.

REST endpoints:

/full_ticker - no parameters, returns a json response of the form:

{ 'result':  
    {'btc_eur':  2134.12, 'btc_usd': 2245.76} ... }
}

/single_ticker - single parameter "market", must be given. Returns a json response of the form:

{ 'result':
    {'btc_eur': 2134.12}
}

The list of available markets can be found at:

import coinblockpro
coinblockpro._markets

Some example requests are given below:

import requests
r1 = requests.get('http://0.0.0.0:8000/full_ticker')
r2 = requests.get('http://0.0.0.0:8000/singler_ticker', params={'market': 'btc_eur'})

Websocket API

The websocket API runs on the localhost, on port 8001, and gives real-time information on markets as they change at the /ticker_feed endpoint.

An example configuration using the websockets library is given below.

import websockets
import asyncio
import websockets


async def subscribe():
    async with websockets.connect('ws://0.0.0.0:8001/ticker_feed') as ws:
        while True:
            resp = await ws.recv()
            print(resp)

if __name__ == '__main__':
    asyncio.run(subscribe())

Example client

UNDER CONSTRUCTION

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

coinblockpro-0.0.1.tar.gz (5.2 kB view details)

Uploaded Source

Built Distribution

coinblockpro-0.0.1-py3-none-any.whl (18.2 kB view details)

Uploaded Python 3

File details

Details for the file coinblockpro-0.0.1.tar.gz.

File metadata

  • Download URL: coinblockpro-0.0.1.tar.gz
  • Upload date:
  • Size: 5.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.6.0.post20200917 requests-toolbelt/0.9.1 tqdm/4.50.0 CPython/3.8.5

File hashes

Hashes for coinblockpro-0.0.1.tar.gz
Algorithm Hash digest
SHA256 7bc0ca2fbbf484013301a12efa4da5eb6ce548819082796db74ef29db8f9286e
MD5 cc96690eaa608ed9723da96ea0f2bddb
BLAKE2b-256 2d395fc4f5efb4300829d650014d38270cd7de53512f3437519a845535b312d0

See more details on using hashes here.

File details

Details for the file coinblockpro-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: coinblockpro-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 18.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.6.0.post20200917 requests-toolbelt/0.9.1 tqdm/4.50.0 CPython/3.8.5

File hashes

Hashes for coinblockpro-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b05bed0f91b16891dcc80775c4b9ac9d0c3461421e8907de5d6f884355a3125d
MD5 20e9501d2074f08bd0037d5c6ca2a9d6
BLAKE2b-256 f77f5eaf29e387f0b96a9af02b7895bb1bd4c04e824dc3f87f22912b312bedfc

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page