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

0 Members and 1 Guest are viewing this topic.

Offline xeroc

  • Board Moderator
  • Hero Member
  • *****
  • Posts: 12922
  • ChainSquad GmbH
    • View Profile
    • ChainSquad GmbH
  • BitShares: xeroc
  • GitHub: xeroc
I just pushed another update that add's @alt 's TCNY asset .. the configuration file has changed slightly

Offline xeroc

  • Board Moderator
  • Hero Member
  • *****
  • Posts: 12922
  • ChainSquad GmbH
    • View Profile
    • ChainSquad GmbH
  • BitShares: xeroc
  • GitHub: xeroc
Quite some updates happend to the feed script ... I recommend to upgrade to it, update the configuration and give it a try ..

Offline xeroc

  • Board Moderator
  • Hero Member
  • *****
  • Posts: 12922
  • ChainSquad GmbH
    • View Profile
    • ChainSquad GmbH
  • BitShares: xeroc
  • GitHub: xeroc
5e11e12: [Price Feed] Add OkcoinUSD and OkcoinCNY

Offline xeroc

  • Board Moderator
  • Hero Member
  • *****
  • Posts: 12922
  • ChainSquad GmbH
    • View Profile
    • ChainSquad GmbH
  • BitShares: xeroc
  • GitHub: xeroc
New Script just now:
Code: [Select]
+--------+---------------+------------+------------------+-------------------+---------------+-----------------------+---------------------------------+---------+
|  asset | price per BTS |    my mean | median exchanges | blockchain median | % change (my) | % change (blockchain) |                     last update | publish |
+--------+---------------+------------+------------------+-------------------+---------------+-----------------------+---------------------------------+---------+
|    BTC |    0.00000846 | 0.00000835 |       0.00000836 |   119221.63120567 |    -100.00085 |               0.83770 | 16769 days, 12:27:42.994040 ago |       X |
| SILVER |    0.00022716 | 0.00022735 |       0.00022599 |     4384.50000000 |    -100.02272 |              -0.40338 | 16769 days, 12:27:42.995337 ago |       X |
|   GOLD |    0.00000300 | 0.00000300 |       0.00000299 |   330863.33333333 |    -100.00030 |              -0.70050 | 16769 days, 12:27:42.996345 ago |       X |
|    TRY |    0.00925493 | 0.00926271 |       0.00920743 |      107.55272727 |    -100.92549 |              -0.46065 | 16769 days, 12:27:42.997357 ago |       X |
|    SGD |    0.00449285 | 0.00449663 |       0.00446936 |      221.52592593 |    -100.44929 |              -0.47163 | 16769 days, 12:27:42.998336 ago |       X |
|    HKD |    0.02466519 | 0.02468597 |       0.02453521 |       40.38370044 |    -102.46652 |              -0.39283 | 16769 days, 12:27:42.999340 ago |       X |
|    NZD |    0.00484322 | 0.00484729 |       0.00481832 |      205.45500000 |    -100.48432 |              -0.49358 | 16769 days, 12:27:43.000903 ago |       X |
|    CNY |    0.02084914 | 0.02037820 |       0.02025377 |       48.87259259 |    -102.08491 |               1.89517 | 16769 days, 12:27:43.001887 ago |       X |
|    MXN |    0.05274312 | 0.05278742 |       0.05246750 |       18.87548544 |    -105.27431 |              -0.44480 | 16769 days, 12:27:43.003357 ago |       X |
|    CAD |    0.00425188 | 0.00425545 |       0.00423002 |      234.01052632 |    -100.42519 |              -0.50158 | 16769 days, 12:27:43.004386 ago |       X |
|    CHF |    0.00327817 | 0.00328093 |       0.00326127 |      303.58227080 |    -100.32782 |              -0.48043 | 16769 days, 12:27:43.005380 ago |       X |
|    AUD |    0.00440713 | 0.00441084 |       0.00438424 |      225.61395349 |    -100.44071 |              -0.56894 | 16769 days, 12:27:43.006382 ago |       X |
|    GBP |    0.00211750 | 0.00211928 |       0.00210666 |      469.70408643 |    -100.21175 |              -0.53993 | 16769 days, 12:27:43.007386 ago |       X |
|    JPY |    0.39161229 | 0.39194194 |       0.38957115 |        2.54252778 |    -139.16123 |              -0.43149 | 16769 days, 12:27:43.008366 ago |       X |
|    EUR |    0.00300677 | 0.00300930 |       0.00299121 |      331.03750000 |    -100.30068 |              -0.46460 | 16769 days, 12:27:43.010122 ago |       X |
|    USD |    0.00318283 | 0.00318551 |       0.00316563 |      312.79324367 |    -100.31828 |              -0.44330 | 16769 days, 12:27:43.011630 ago |       X |
|    KRW |    3.66409018 | 3.66915853 |       3.67206229 |        0.27129753 |    -466.40902 |              -0.59414 | 16769 days, 12:27:43.013094 ago |       X |
+--------+---------------+------------+------------------+-------------------+---------------+-----------------------+---------------------------------+---------+


Old Script just now:
Code: [Select]
+--------+-----------------+-----------------+------------------+-------------------+---------------+-----------------------+---------------------------------+---------+
|  asset |        BTS/base |         my mean | median exchanges | blockchain median | % change (my) | % change (blockchain) |                     last update | publish |
+--------+-----------------+-----------------+------------------+-------------------+---------------+-----------------------+---------------------------------+---------+
|    BTC | 119216.08068607 | 114454.37729791 |  117191.43976981 |   119221.63120567 |    -100.00084 |               0.00466 | 16769 days, 12:29:04.809748 ago |       X |
| SILVER |   4389.63472314 |   4214.00511904 |    4336.09411615 |     4384.50000000 |    -100.02278 |              -0.11697 | 16769 days, 12:29:04.811758 ago |       X |
|   GOLD | 332187.16101836 | 318896.32835105 |  328135.91972626 |   330863.33333333 |    -100.00030 |              -0.39852 | 16769 days, 12:29:04.813422 ago |       X |
|    TRY |    107.73831660 |    103.42769311 |     106.43144741 |      107.55272727 |    -100.92817 |              -0.17226 | 16769 days, 12:29:04.815258 ago |       X |
|    SGD |    221.95726058 |    213.07673182 |     219.25636479 |      221.52592593 |    -100.45054 |              -0.19433 | 16769 days, 12:29:04.817057 ago |       X |
|    HKD |     40.42935227 |     38.81179660 |      39.93904179 |       40.38370044 |    -102.47345 |              -0.11292 | 16769 days, 12:29:04.818777 ago |       X |
|    NZD |    205.90370171 |    197.66548773 |     203.39884748 |      205.45500000 |    -100.48566 |              -0.21792 | 16769 days, 12:29:04.822876 ago |       X |
|    CNY |     48.97623126 |     47.01676585 |      48.38379477 |       48.87259259 |    -102.04181 |              -0.21161 | 16769 days, 12:29:04.824554 ago |       X |
|    MXN |     18.90547887 |     18.14906523 |      18.67736392 |       18.87548544 |    -105.28947 |              -0.15865 | 16769 days, 12:29:04.827384 ago |       X |
|    CAD |    234.50768905 |    225.12501645 |     231.65069325 |      234.02761526 |    -100.42643 |              -0.20472 | 16769 days, 12:29:04.829030 ago |       X |
|    CHF |    304.22114225 |    292.04923508 |     300.51447300 |      303.58227080 |    -100.32871 |              -0.21000 | 16769 days, 12:29:04.830673 ago |       X |
|    AUD |    226.23304985 |    217.18143600 |     223.47995048 |      225.63333333 |    -100.44202 |              -0.26509 | 16769 days, 12:29:04.832348 ago |       X |
|    GBP |    470.91486712 |    452.07351535 |     465.17936621 |      469.82307692 |    -100.21235 |              -0.23184 | 16769 days, 12:29:04.834049 ago |       X |
|    JPY |      2.54642466 |      2.44454411 |       2.51577086 |        2.54252778 |    -139.27075 |              -0.15303 | 16769 days, 12:29:04.835712 ago |       X |
|    EUR |    331.66484625 |    318.39521260 |     327.59833068 |      331.03750000 |    -100.30151 |              -0.18915 | 16769 days, 12:29:04.840230 ago |       X |
|    USD |    313.35383170 |    300.81683155 |     309.55429825 |      312.79324367 |    -100.31913 |              -0.17890 | 16769 days, 12:29:04.843851 ago |       X |
|    KRW |      0.27164239 |      0.26090843 |       0.26717324 |        0.27129753 |    -468.13105 |              -0.12695 | 16769 days, 12:29:04.847094 ago |       X |
+--------+-----------------+-----------------+------------------+-------------------+---------------+-----------------------+---------------------------------+---------+


Note the difference in CNY that comes from asking the BTC/CNY price from huobi and bitcoinchina instead of bitcoinaverage

Offline xeroc

  • Board Moderator
  • Hero Member
  • *****
  • Posts: 12922
  • ChainSquad GmbH
    • View Profile
    • ChainSquad GmbH
  • BitShares: xeroc
  • GitHub: xeroc
Mega Update in order to improve price.
https://github.com/xeroc/python-graphenelib/commit/16b9ca16c9044cc751605e0276d3223a9ef00f7b

 [Price Feed] Megaupdate

* Per Asset parameters include exchanges to consider
* Exchange fetch methods are moved outside the feed script
* Python Futures

This update can now also consider prices from Huobi and BitcoinChina.

Configuration has changes

Demo configuration:
Code: [Select]
import feedsources
################################################################################
## RPC-client connection information (required)
################################################################################
host   = "localhost"     # machine that runs a cli-wallet with -H parameter
port   = 8092            # RPC port, e.g.`-H 127.0.0.1:8092`
user   = ""              # API user (optional)
passwd = ""              # API user passphrase (optional)
unlock = ""              # password to unlock the wallet if the cli-wallet is locked

################################################################################
## Script runtime parameters
################################################################################
ask_confirmation             = True # if true, a manual confirmation is required

################################################################################
## Witness Feed Publish Parameters
################################################################################
witness_name                 = "init0"
maxAgeFeedInSeconds          = 60*60  # A feed should be at most 1hour old
change_min                   = 0.5    # Percentage of price change to force an update
change_max                   = 5.0    # Percentage of price change to cause a warning

################################################################################
## Fine tuning
################################################################################
discount                     = 0.995       # discount for borrowing of an asset
minValidAssetPriceInBTC      = 100 * 1e-8  # minimum valid price for BTS in BTC

################################################################################
## Asset specific Settings
################################################################################
asset_config = {
                   "default" : { ## DEFAULT BEHAVIOR
                       # "median", "mean", or "weighted" (by volume)
                       "metric" : "weighted",
                       # all:* , or array of: "yahoo", "btcid", "ccedk", "yunbi", "btc38", "bter", "poloniex", "bittrex", "btcavg"
                       "sources" : ["*"],
                       # Core exchange rate for paying transaction fees in non-BTS assets
                       "core_exchange_factor" : 0.95,
                       # Call when collateral only pays off 175% the debt
                       "maintenance_collateral_ratio" : 1750,
                       # Stop calling when collateral only pays off 110% of the debt
                       "maximum_short_squeeze_ratio" : 1100,
                   },
                   "CNY" : {
                       "metric" : "median",
                       "sources" : ["poloniex","bittrex","huobi","btcchina"]
                   }
               }

################################################################################
## Exchanges and settings
################################################################################
feedSources = {}
feedSources["yahoo"]    = feedsources.Yahoo(trust=1.0)
feedSources["btcavg"]   = feedsources.BitcoinAverage(trust=1.0)

feedSources["poloniex"] = feedsources.Poloniex(trust=1.0)
feedSources["bittrex"]  = feedsources.Bittrex(trust=1.0)
feedSources["ccedk"]    = feedsources.Ccedk(trust=1.0)
feedSources["btcchina"] = feedsources.BtcChina(trust=1.0)
feedSources["huobi"]    = feedsources.Huobi(trust=1.0)
feedSources["yunbi"]    = feedsources.Yunbi(trust=0.5)
feedSources["btc38"]    = feedsources.Btc38(trust=0.5)

#feedSources["btcid"]    = feedsources.BitcoinIndonesia(trust=0.0)
#feedSources["bter"]     = feedsources.Bter(trust=0.0)

Offline xeroc

  • Board Moderator
  • Hero Member
  • *****
  • Posts: 12922
  • ChainSquad GmbH
    • View Profile
    • ChainSquad GmbH
  • BitShares: xeroc
  • GitHub: xeroc
Oh .. btw .. the last update also only publishes those feeds that need update .. hence you could spare some tx fees here

Offline xeroc

  • Board Moderator
  • Hero Member
  • *****
  • Posts: 12922
  • ChainSquad GmbH
    • View Profile
    • ChainSquad GmbH
  • BitShares: xeroc
  • GitHub: xeroc
Another update:

* [2015-11-26][ea91778] | [Price Feed] Make default price parameters more clean {{Fabian Schuh}} (HEAD -> master, origin/master)
* [2015-11-26][4db1f0a] | [Price Feed] Delegate->Witness rename / More comments in configuration file {{Fabian Schuh}}
* [2015-11-26][fa0fbf9] | [Price Feed] Reduce transaction costs by only publishing individually required prices, not all {{Fabian Schuh}}
* [2015-11-26][54cb51d] | [Price Feed] Allow for asset-specific core_exchange_rate_factor {{Fabian Schuh}}

The parameters are now asset specific and can be used as follows
Code: [Select]
################################################################################
## Asset specific Borrow/Short parameters
################################################################################
# Core exchange rate for paying transaction fees in non-BTS assets
core_exchange_factor = {
                                  "default" : 0.95, # default value
                                  "USD"     : 0.95, # asset-specific overwrite
                       }

# Call when collateral only pays off 175% the debt
maintenance_collateral_ratio = {
                                  "default" : 1750, # default value
                                  "USD"     : 1750, # asset-specific overwrite
                               }

# Stop calling when collateral only pays off 110% of the debt
maximum_short_squeeze_ratio  = {
                                  "default" : 1100, # default value
                                  "USD"     : 1100, # asset-specific overwrite
                               }

Please note that the configuration has changed, changed some variable names (also delegate_name->witness_name)

Offline xeroc

  • Board Moderator
  • Hero Member
  • *****
  • Posts: 12922
  • ChainSquad GmbH
    • View Profile
    • ChainSquad GmbH
  • BitShares: xeroc
  • GitHub: xeroc

Offline xeroc

  • Board Moderator
  • Hero Member
  • *****
  • Posts: 12922
  • ChainSquad GmbH
    • View Profile
    • ChainSquad GmbH
  • BitShares: xeroc
  • GitHub: xeroc
Oh .. no one told me .. then you can put a 1.0 as trust factor for bittrex aswell

Offline cube

  • Hero Member
  • *****
  • Posts: 1404
  • Bit by bit, we will get there!
    • View Profile
  • BitShares: bitcube
I also noticed that yunbi has volume in the BTS/CNY market but not in the BTS/BTC market .. thus you can also enable yunbi again .. althoug I would advice a trust factor of less than 1 since they have not yet finished integrating BTS2, similar to bittrex ..

FYI, Bittrex has enabled bts deposit.
« Last Edit: October 30, 2015, 01:02:50 pm by cube »
ID: bitcube
bitcube is a dedicated witness and committe member. Please vote for bitcube.

Offline xeroc

  • Board Moderator
  • Hero Member
  • *****
  • Posts: 12922
  • ChainSquad GmbH
    • View Profile
    • ChainSquad GmbH
  • BitShares: xeroc
  • GitHub: xeroc
I have pushed some more commits that mainly fixed the volume issue with CCEDK (which was my fault) ..
after upgrading the code, you can safely set the trust value back to 1.0 again

I also noticed that yunbi has volume in the BTS/CNY market but not in the BTS/BTC market .. thus you can also enable yunbi again .. althoug I would advice a trust factor of less than 1 since they have not yet finished integrating BTS2, similar to bittrex ..

Offline xeroc

  • Board Moderator
  • Hero Member
  • *****
  • Posts: 12922
  • ChainSquad GmbH
    • View Profile
    • ChainSquad GmbH
  • BitShares: xeroc
  • GitHub: xeroc
yes,I have see these two scripts, monitor through witness port and transfer through cli_wallet right?
yup

Offline alt

  • Hero Member
  • *****
  • Posts: 2821
    • View Profile
  • BitShares: baozi
yes,I have see these two scripts, monitor through witness port and transfer through cli_wallet right?

Offline xeroc

  • Board Moderator
  • Hero Member
  • *****
  • Posts: 12922
  • ChainSquad GmbH
    • View Profile
    • ChainSquad GmbH
  • BitShares: xeroc
  • GitHub: xeroc
hi, xeroc
if I want to monitor my account's transaction and execute some call such as transfer.
should I subscribe transaction event from witness_node(port 8090) and execute transfer from cli_wallet(port 8092)?
so I need to declair GrapheneAPI instanse with port 8092, and declair a  GrapheneWebSocket instanse with port 8090?
thanks
Take a look at this script:
https://github.com/xeroc/python-graphenelib/blob/master/scripts/monitor-deposits/monitor.py

In order to initiate a transfer you need to also interface with a cli-wallet similar to this:
https://github.com/xeroc/python-graphenelib/blob/master/scripts/flood/flood.py

Offline alt

  • Hero Member
  • *****
  • Posts: 2821
    • View Profile
  • BitShares: baozi
hi, xeroc
if I want to monitor my account's transaction and execute some call such as transfer.
should I subscribe transaction event from witness_node(port 8090) and execute transfer from cli_wallet(port 8092)?
so I need to declair GrapheneAPI instanse with port 8092, and declair a  GrapheneWebSocket instanse with port 8090?
thanks