Giter VIP home page Giter VIP logo

bts-volume-feed's Introduction

Volume-Aware Price Feed

What is this?

This is a price feed generator which calculates the average price of BTS exchange pairs based on volume at a per-trade basis, for use by BitShares delegates. The script is capable of sorting trades across multiple exchanges by their execution time, and then taking an average price of the most recent trades in a user-specified BTS amount window.

Why was this made?

Current price feed implementations use spot prices, which are much more easily manipulated. Futher, they are arbitrarily weighing these exchange's spot prices, based on an average volume over 24 hours. By considering every trade at a set of exchanges, the place the exchange took place becomes irrelevant, and only the trade amount and time become important.

How is this accomplished?

The script currently supports one current pair (BTS/CNY) on three exchanges (BTC38, Bter, Yunbi). Fortunately, all these exchanges have a public API for listing recent individual trades. Every 10 seconds, this script fetches, formats, combines, and sorts the data by time. It then runs through all the most recent trades, calculating the average price until the user-specified volume window is filled. If the last order pushes the total over this window, this last order is truncated, and the rest of the transactions are not included. The average price is displayed in the terminal, and saved to the price.json file. The trades used to calculate this are saved in the trades.json file.

If you start the script and on the initial iteration there is not enough volume across the exchanges to fill the volume window, no price feed will be output, and a partial trades.json file will be created. Every time new orders are detected, it will add to this file until the window is matched, at which point it will begin generating a price feed.

Usage?

You can change the config settings at the top of the file, changing the WINDOW, as well as disable/enable the exchanges.

After you have changed these settings, you can simply run the script like this:

$ python price_feed.py

Know issues?

  • The Yunbi exchange's timestamp is not parsed correctly by the ISO8601 date parser, as it does not factor in the timezone offset. Additionally, it seems that their timestamps are off by 9 hours. For this reason, I have disabled the Yunbi exchange by default until I can confirm that this is indeed correct.
  • When you stop running the script, and run it again after much time has passed, it is possible that it will use old trade information until they are pushed out by new orders.
  • Queries to the APIs are not done exactly every 10 seconds, it is actually 10s + (time it takes to retrieve all data).

Future plans?

The current code is only a proof-of-concept to guage interest in this kind of price feed. If there is indeed interest, the next steps are:

  • Implement more exchange pairs (need to figure out rate-limiting from exchanges)
  • Integration with bitshares RPC

bts-volume-feed's People

Contributors

flux627 avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

bts-volume-feed's Issues

yunbi updated market code

Yunbi has updated market code from 'btsxcny' to 'btscny' recently.

btw. the timestamp in trade json is time of GMT+08.

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.