Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
# -*- coding: utf-8 -*-
from __future__ import unicode_literals, print_function, division
import os
# os.environ['HTTP_PROXY'] = ''
# os.environ['HTTPS_PROXY'] = ''
import datetime
import hashlib
import requests
from pprint import pprint
from dateutil.parser import parse
import pytz
from lbcapi import api
hmac_key = ''
hmac_secret = ''
conn = api.hmac(hmac_key, hmac_secret)
style = '| font="Source Code Pro" size=12'
green = 'color=#3ba027'
red = 'color=#b5272c'
ticker ='GET', '/bitcoinaverage/ticker-all-currencies/').json()['CNY']
asks ='GET', '/buy-bitcoins-online/CNY/.json').json()['data']['ad_list']
for i, ask in reversed(list(enumerate(asks[:5], start=1))):
price = float(ask['data']['temp_price'])
url = ask['actions']['public_view']
min_amount = ask['data']['min_amount']
max_amount = ask['data']['max_amount']
print('ask {}: price {:.2f}, amount [{}, {}]'.format(i, price, min_amount, max_amount), style, red, 'href='+url)
bids ='GET', '/sell-bitcoins-online/CNY/.json').json()['data']['ad_list']
for i, bid in enumerate(bids[:5], start=1):
price = float(bid['data']['temp_price'])
url = bid['actions']['public_view']
min_amount = bid['data']['min_amount']
max_amount = bid['data']['max_amount']
print('bid {}: price {:.2f}, amount [{}, {}]'.format(i, price, min_amount, max_amount), style, green, 'href='+url)
wallet ='GET', '/api/wallet-balance/').json()
balance = float(wallet['data']['total']['balance'])
sendable = float(wallet['data']['total']['sendable'])
print('balance : BTC {:.8f}'.format(balance), style)
txs ='GET', '/api/dashboard/released/').json()['data']['contact_list']
total_buy = sum(float(tx['data']['amount']) for tx in txs if tx['data']['advertisement']['trade_type'] == 'ONLINE_SELL')
total_sell = sum(float(tx['data']['amount']) for tx in txs if tx['data']['advertisement']['trade_type'] == 'ONLINE_BUY')
print('total buy : CNY {:.2f}'.format(total_buy), style)
print('total sell: CNY {:.2f}'.format(total_sell), style)
print('buy - sell: CNY {:.2f}'.format(total_buy - total_sell), style)
print('avg price : CNY {:.2f}'.format((total_buy-total_sell) / balance), style)
sell_all = float(bids[0]['data']['temp_price']) * sendable
diff = sell_all - (total_buy - total_sell)
ratio = diff / (total_buy - total_sell) * 100
print('sendable: BTC {:.8f}'.format(sendable), style)
print('sell all: CNY {:.2f}'.format(sell_all), style)
print('diff : CNY{:+.2f} ({:+.1f}%)'.format(diff, ratio), style, red if ratio < 0 else green)
print('recent txs')
for tx in txs:
created_at = parse(tx['data']['created_at']).astimezone(pytz.timezone('Asia/Shanghai'))
created_at = created_at.strftime('%Y-%m-%d')
cny = float(tx['data']['amount'])
btc = float(tx['data']['amount_btc'])
op = 'buy ' if tx['data']['advertisement']['trade_type'] == 'ONLINE_SELL' else 'sell'
print('[{}]{} CNY {:7.2f} / BTC {:.8f} = {:.2f}'.format(created_at, op, cny, btc, cny / btc), style)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment