Giter Site home page Giter Site logo

hypernormalisation / coinblockpro Goto Github PK

View Code? Open in Web Editor NEW
2.0 3.0 0.0 41 KB

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

License: GNU General Public License v3.0

Python 30.39% Shell 0.60% Jupyter Notebook 69.01%

coinblockpro's Introduction

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

Market simulation

The primary purpose of this toy server is to facilitate the development of algorithms to keep real-time information on an exchange's markets.

As such, the information simulated is reduced to a single price per market, initialised randomly between 0 and 10000. A single market is chosen randomly and fluctuated at a random time interval of the order of half a second.

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

Example clients to build up and keep real-time information on markets from the server are given in the Jupyter notebook here.

coinblockpro's People

Contributors

hypernormalisation avatar

Stargazers

 avatar Dr Will Breaden Madden avatar

Watchers

James Cloos avatar  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.