Author Topic: [Python] Price Feed Script for BitShares 2.0  (Read 21338 times)

0 Members and 1 Guest are viewing this topic.

Offline abit

  • Committee member
  • Hero Member
  • *
  • Posts: 4592
    • View Profile
    • Abit's Hive Blog
  • BitShares: abit
  • GitHub: abitmore
For forced settlement what about using the average BTS price over the following 24 hours as opposed to the BTS price in 24 hours?

I think it would be much harder for someone who wanted to manipulate their settlement price if they had to do it for an entire day as opposed to at a specific point in time. (Circa 24 hours after requesting forced settlement.)
It's not a price feeding issue. It's a core issue. We just don't have such a feature which will tracks average price of last 24 hours.
BitShares committee member: abit
BitShares witness: in.abit

Offline Empirical1.2

  • Hero Member
  • *****
  • Posts: 1366
    • View Profile
For forced settlement what about using the average BTS price over the following 24 hours as opposed to the BTS price in 24 hours?

I think it would be much harder for someone who wanted to manipulate their settlement price if they had to do it for an entire day as opposed to at a specific point in time. (Circa 24 hours after requesting forced settlement.)
If you want to take the island burn the boats

Offline xeroc

  • Board Moderator
  • Hero Member
  • *****
  • Posts: 12920
  • ChainSquad GmbH
    • View Profile
    • ChainSquad GmbH
  • BitShares: xeroc
  • GitHub: xeroc
I have updated the price feed slightly to make it easier (later) to add privatized bitassets ...
It can now also poll the BitShares DEX and include its volume/price.
I also changed some syntax and style stuff in the configuration, which makes the comparison a little more tricky. Anyway, here is the diff of the example config file:
https://github.com/xeroc/python-graphenelib/compare/master...develop#diff-4343e1580d24c0ed7ff42021df7495f3L1
As you can see, the FeedSources are now way more flexible to use..


NOTE: this is still in the development branch but you can run it (if you want) by

git fetch
git checkout develop
git rebase develop
« Last Edit: February 08, 2016, 11:23:06 am by xeroc »

Offline Empirical1.2

  • Hero Member
  • *****
  • Posts: 1366
    • View Profile
Does the BitShares price feed reference last traded prices at weighted exchanges or does it average last traded prices over a certain amount of time?

What I mean is there is that there is usually a 1-2% spread between buy and sell prices for BTS on BTC38 and Polo.

If you are force settling and you know it will reference last traded prices at a specific time then it would be in your interest to make tiny sell trades so that the last traded price is in your favour by 1-2%. It your force settle is going through at a thinly traded time it may also be in your interest & very cheap to move the price by another 1-2%.
That would assume that you know when witnesses publish a price and how many witnesses publish it ..
This could be fixed by tracking trades over time or running a weighted average over time but that involves alot of work to upgrade the feed script into a time-sensitive feed script.
Fortunately, this time-sensivity is also achieved by different witnesses running their scripts at different time instants.

We may consider replacing the last price with the "(highest bid + lowest ask)/ 2" that would make it a little more "fair"

Cool, yeah I'm just wondering if the forced settlement at 100% can currently be exploited.

I think your other suggestion of introducing a 1-2% forced settlement fee could also help address that if it was a potential issue...

- Settlement can be discouraged by asking for a percentage fee (1-2%) (this will move the peg AROUND parity. Flat fee for settlement can also be increase which has some negative effects on pred. markets

If you want to take the island burn the boats

Offline xeroc

  • Board Moderator
  • Hero Member
  • *****
  • Posts: 12920
  • ChainSquad GmbH
    • View Profile
    • ChainSquad GmbH
  • BitShares: xeroc
  • GitHub: xeroc
Does the BitShares price feed reference last traded prices at weighted exchanges or does it average last traded prices over a certain amount of time?

What I mean is there is that there is usually a 1-2% spread between buy and sell prices for BTS on BTC38 and Polo.

If you are force settling and you know it will reference last traded prices at a specific time then it would be in your interest to make tiny sell trades so that the last traded price is in your favour by 1-2%. It your force settle is going through at a thinly traded time it may also be in your interest & very cheap to move the price by another 1-2%.
That would assume that you know when witnesses publish a price and how many witnesses publish it ..
This could be fixed by tracking trades over time or running a weighted average over time but that involves alot of work to upgrade the feed script into a time-sensitive feed script.
Fortunately, this time-sensivity is also achieved by different witnesses running their scripts at different time instants.

We may consider replacing the last price with the "(highest bid + lowest ask)/ 2" that would make it a little more "fair"

Offline Empirical1.2

  • Hero Member
  • *****
  • Posts: 1366
    • View Profile
Does the BitShares price feed reference last traded prices at weighted exchanges or does it average last traded prices over a certain amount of time?

What I mean is there is that there is usually a 1-2% spread between buy and sell prices for BTS on BTC38 and Polo.

If you are force settling and you know it will reference last traded prices at a specific time then it would be in your interest to make tiny sell trades so that the last traded price is in your favour by 1-2%. If your force settle is going through at a thinly traded time it may also be in your interest & very cheap to move the price temporarily by another 1-2%.

« Last Edit: February 02, 2016, 04:11:21 pm by Empirical1.2 »
If you want to take the island burn the boats

Offline xeroc

  • Board Moderator
  • Hero Member
  • *****
  • Posts: 12920
  • ChainSquad GmbH
    • View Profile
    • ChainSquad GmbH
  • BitShares: xeroc
  • GitHub: xeroc
With the newest release, the only real change is that you will need to rename "witness_name" into "producer_name". This change facilitates that non-witnesses are allowed to publish prices for privatized bitassets aswell

Offline abit

  • Committee member
  • Hero Member
  • *
  • Posts: 4592
    • View Profile
    • Abit's Hive Blog
  • BitShares: abit
  • GitHub: abitmore
@xeroc latest version (commit 3c7b2ca1b68e33fbf47aa9d66005613b83ca1f51) with Btc38's BTS/BTC market enabled by default causes a 10% off on BTS/CNY price.
Code: [Select]
|  CNY   | 0.02429415 | 0.02342230 (+3.72%) | 0.02433542 (-0.17%) | 0.02429415 (+0.00%) |  0.03% ( 5)  | 0.02209000 (+9.98%) | 0.02209988 (+9.93%) | 1:48:02.671795 ago |    X    |
blame file here: https://drive.google.com/open?id=0B3xrm70jSHn4V2dBX1duaEZ5OEE

Another minor error on my server:
Code: [Select]
Error fetching results from Ccedk! ('bool' object is not subscriptable)
The script is a deterministic one, so it does not "cause" a wrong price. I will investigate what the reason for this is, but I assume some exchange may have published an "off"-price .. We do see some volatility right now..
It's sure caused by Btc38's BTS/BTC market, but I don't think there is enough volume to cause a 10% change on weighted average price. Maybe I'm wrong.. However I disabled that market in my production script.
BitShares committee member: abit
BitShares witness: in.abit

Offline xeroc

  • Board Moderator
  • Hero Member
  • *****
  • Posts: 12920
  • ChainSquad GmbH
    • View Profile
    • ChainSquad GmbH
  • BitShares: xeroc
  • GitHub: xeroc
@xeroc latest version (commit 3c7b2ca1b68e33fbf47aa9d66005613b83ca1f51) with Btc38's BTS/BTC market enabled by default causes a 10% off on BTS/CNY price.
Code: [Select]
|  CNY   | 0.02429415 | 0.02342230 (+3.72%) | 0.02433542 (-0.17%) | 0.02429415 (+0.00%) |  0.03% ( 5)  | 0.02209000 (+9.98%) | 0.02209988 (+9.93%) | 1:48:02.671795 ago |    X    |
blame file here: https://drive.google.com/open?id=0B3xrm70jSHn4V2dBX1duaEZ5OEE

Another minor error on my server:
Code: [Select]
Error fetching results from Ccedk! ('bool' object is not subscriptable)
The script is a deterministic one, so it does not "cause" a wrong price. I will investigate what the reason for this is, but I assume some exchange may have published an "off"-price .. We do see some volatility right now..

Offline abit

  • Committee member
  • Hero Member
  • *
  • Posts: 4592
    • View Profile
    • Abit's Hive Blog
  • BitShares: abit
  • GitHub: abitmore
@xeroc latest version (commit 3c7b2ca1b68e33fbf47aa9d66005613b83ca1f51) with Btc38's BTS/BTC market enabled by default causes a 10% off on BTS/CNY price.
Code: [Select]
|  CNY   | 0.02429415 | 0.02342230 (+3.72%) | 0.02433542 (-0.17%) | 0.02429415 (+0.00%) |  0.03% ( 5)  | 0.02209000 (+9.98%) | 0.02209988 (+9.93%) | 1:48:02.671795 ago |    X    |
blame file here: https://drive.google.com/open?id=0B3xrm70jSHn4V2dBX1duaEZ5OEE

Another minor error on my server:
Code: [Select]
Error fetching results from Ccedk! ('bool' object is not subscriptable)
BitShares committee member: abit
BitShares witness: in.abit

Offline abit

  • Committee member
  • Hero Member
  • *
  • Posts: 4592
    • View Profile
    • Abit's Hive Blog
  • BitShares: abit
  • GitHub: abitmore
The blame price is the price you have calculated and published .. the recalculated prices takes the same fetched data from exchanges (stored in the blame file as well) and recalculates the price .. this is useful for me to compare implementations .. the blame file also contains a git hash of your code base bit i havent compared the hash to figure out which version you are running ...

Could you update your script and try to run on the blame file?
Perhaps it's caused by a bug which you've fixed. Will try. Thanks.

//Update:
The latest version of script works fine. Result is same to that on your picture.
Thank you.
« Last Edit: January 05, 2016, 10:14:30 pm by abit »
BitShares committee member: abit
BitShares witness: in.abit

Offline xeroc

  • Board Moderator
  • Hero Member
  • *****
  • Posts: 12920
  • ChainSquad GmbH
    • View Profile
    • ChainSquad GmbH
  • BitShares: xeroc
  • GitHub: xeroc
The blame price is the price you have calculated and published .. the recalculated prices takes the same fetched data from exchanges (stored in the blame file as well) and recalculates the price .. this is useful for me to compare implementations .. the blame file also contains a git hash of your code base bit i havent compared the hash to figure out which version you are running ...

Could you update your script and try to run on the blame file?

Offline abit

  • Committee member
  • Hero Member
  • *
  • Posts: 4592
    • View Profile
    • Abit's Hive Blog
  • BitShares: abit
  • GitHub: abitmore
Hi @xeroc would you please help check this log file?
https://drive.google.com/file/d/0B3xrm70jSHn4VmpvdE15UEJnWUk/view

The prices in USD / EUR / TUSD / KRW are off by 100x.

Some logs here:
Code: [Select]
"USD": {"mean": 0.0680436848863721, "median": 0.0034588223011641013, "weighted": 0.32804216106003525}

If I use your file and run it in blame mode I get the correct prices:


See "recalculated price" ..
What's "blame price" and what's "recalculated price"? Is the "recalculated price" newly fetched from the markets?

I did published those off-100x prices to block chain, same as the "blame price" in above picture, wondering what's wrong..

Quote
However, I see that the median price is quite of from the weighted median .. which (so I assume) is because of "dead" markets ..
I should maybe skip markets entirely that have 0 24h trading
BitShares committee member: abit
BitShares witness: in.abit

Offline xeroc

  • Board Moderator
  • Hero Member
  • *****
  • Posts: 12920
  • ChainSquad GmbH
    • View Profile
    • ChainSquad GmbH
  • BitShares: xeroc
  • GitHub: xeroc
Hi @xeroc would you please help check this log file?
https://drive.google.com/file/d/0B3xrm70jSHn4VmpvdE15UEJnWUk/view

The prices in USD / EUR / TUSD / KRW are off by 100x.

Some logs here:
Code: [Select]
"USD": {"mean": 0.0680436848863721, "median": 0.0034588223011641013, "weighted": 0.32804216106003525}

If I use your file and run it in blame mode I get the correct prices:


See "recalculated price" ..

However, I see that the median price is quite of from the weighted median .. which (so I assume) is because of "dead" markets ..
I should maybe skip markets entirely that have 0 24h trading

Offline abit

  • Committee member
  • Hero Member
  • *
  • Posts: 4592
    • View Profile
    • Abit's Hive Blog
  • BitShares: abit
  • GitHub: abitmore
Hi @xeroc would you please help check this log file?
https://drive.google.com/file/d/0B3xrm70jSHn4VmpvdE15UEJnWUk/view

The prices in USD / EUR / TUSD / KRW are off by 100x.

Some logs here:
Code: [Select]
"USD": {"mean": 0.0680436848863721, "median": 0.0034588223011641013, "weighted": 0.32804216106003525}
BitShares committee member: abit
BitShares witness: in.abit