BitShares Forum

Main => Stakeholder Proposals => Topic started by: fluxer555 on December 30, 2014, 05:36:02 pm

Title: New Delegate Feed Script
Post by: fluxer555 on December 30, 2014, 05:36:02 pm
I have just thrown together a proof-of-concept feed generator, which uses a volume window and individual trades to calculate price.

https://github.com/flux627/bts-volume-feed

Copy-pasted from the README.md:

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?
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:
Title: Re: New Delegate Feed Script
Post by: toast on December 30, 2014, 05:47:03 pm
Sending you a tip! Diversity in price feed scripts is important.
Title: Re: New Delegate Feed Script
Post by: fluxer555 on December 30, 2014, 06:08:58 pm
Much appreciated toast! This is actually the first BitUSD that I own... feels cool :)

I welcome anyone to contribute to the code, please send me your pull requests!
Title: Re: New Delegate Feed Script
Post by: emski on February 05, 2015, 10:14:09 pm
I'd recommend against such frequent pooling of exchanges.
You might get a ban if you have so much requests.
You dont need to update the feeds that often anyway.
Title: Re: New Delegate Feed Script
Post by: fluxer555 on February 05, 2015, 10:46:41 pm
They are all comfortably within their published rate-limits. Polling frequently is needed if you want to confidently account for all trades taking place.
Title: Re: New Delegate Feed Script
Post by: xeroc on February 06, 2015, 08:35:27 am
Sweet script .. thx for sharing!