Loading ...

山寨币指数(2018.02.22基点1000)

Author: 小草, Date: 2018-02-07 17:24:00
Tags:

疼痛及了山寨币对BTC价格指数,2018.02.22基点1000。新加入的山寨币会列出。


#!/usr/bin/env python
# -*- coding: utf-8 -*-coding
import time
import urllib2
import json
import pickle
            
def updateTicker():
    global index,initPrice
    ticker = json.loads(urllib2.urlopen('https://api.binance.com/api/v3/ticker/price',timeout=10).read())
    change = []
    for t in ticker:
        if t['symbol'][-3:] == 'BTC':
            if t['symbol'][:-3] in initPrice.keys():
                change.append(float(t['price'])/initPrice[t['symbol'][:-3]])
            else:
                initPrice[t['symbol'][:-3]] = float(t['price'])
                f=open('price.pkl','w')
                pickle.dump(initPrice,f,0)
                f.close()
                Log(t['symbol'][:-3],' added')
    if len(change)>0:
        index = 1000*sum(change)/len(change)
    


initPrice = {}
price = {}
index = 1000
try:
    f=open('price.pkl','r')  
    initPrice=pickle.load(f)  
    f.close()
except:
    initPrice = {}
Log('共计入山寨币:', len(initPrice))
def main():
    while True:
        try:
            updateTicker()
            LogProfit(round(index,4))
        except Exception as e:
            pass
        Sleep(3600000)


More