Esempio n. 1
0
    def mtgox(self):
        mt_usd = Mtgox(currency='USD')
        mt_usd.get_ticker()

        if mt_usd.error:
            return self.response_txt(mt_usd.error)

        usd_cny_currency = get_usd_cny_currency()

        content = u"""MtGox比特币实时行情
---------------
最新成交价:$%.2f,合¥%.2f
日交量:%s
最高成交价:$%.2f,合¥%.2f
最低成交价:$%.2f,合¥%.2f
最新买入价:$%.2f,合¥%.2f
最新卖出价:$%.2f,合¥%.2f
加权平均价:$%.2f,合¥%.2f""" %\
            (mt_usd.last_all,
             mt_usd.last_all * usd_cny_currency,
             mt_usd.volume,
             mt_usd.high,
             mt_usd.high * usd_cny_currency,
             mt_usd.low,
             mt_usd.low * usd_cny_currency,
             mt_usd.last_buy,
             mt_usd.last_buy * usd_cny_currency,
             mt_usd.last_sell,
             mt_usd.last_sell * usd_cny_currency,
             mt_usd.vwap,
             mt_usd.vwap * usd_cny_currency)
        return self.response_txt(content)
Esempio n. 2
0
    def btc(self):
        mt_usd = Mtgox(currency='USD')
        #mt_cny = Mtgox(currency='CNY')
        btce = BTCE()
        btcc = BTCChina()
        fxbtc = Fxbtc()
        cn42btc = CN42BTC()
        list_instance = [mt_usd, btce, btcc, fxbtc, cn42btc]

        list_thread = []
        for instance in list_instance:
            t = FetcherThread(instance)
            list_thread.append(t)
            t.daemon = True
            t.start()

        # wait for all thread finish
        for t in list_thread:
            t.join()

        for instance in list_instance:
            if instance.error:
                instance = None

        usd_cny_currency = get_usd_cny_currency()

        content = u"""比特币实时行情汇总
----------------
Mtgox价格:$%.2f,合¥%.2f
MtGox日交量:%s

BTC-E价格:$%.2f,合¥%.2f
BTC-E日交量:%.4f BTC

BTCChina价格:¥%.2f
BTCChina日交量:%.4f BTC

FXBTC价格:¥%.2f
FXBTC日交量:%.4f BTC

42BTC价格:¥%.2f
42BTC日交量:%.4f BTC
""" %\
            (0 if mt_usd is None else mt_usd.last_all,
             mt_usd.last_all * usd_cny_currency,
             0 if mt_usd is None else mt_usd.volume,
             0 if btce is None else btce.last_all,
             btce.last_all * usd_cny_currency,
             0 if btce is None else btce.volume,
             0 if btcc is None else btcc.last_all,
             0 if btcc is None else btcc.volume,
             0 if fxbtc is None else fxbtc.last_all,
             0 if fxbtc is None else fxbtc.volume,
             0 if cn42btc is None else cn42btc.last_all,
             0 if cn42btc is None else cn42btc.volume)

        return self.response_txt(content)