Upgrade to Pro — share decks privately, control downloads, hide ads and more …

pycon2016_zaif

英 谷口
August 28, 2016

 pycon2016_zaif

英 谷口

August 28, 2016
Tweet

More Decks by 英 谷口

Other Decks in Technology

Transcript

  1. 4.実行 >>from zaifapi.impl import ZaifPublicApi, ZaifPrivateApi >>#ビットコインと日本円の終値を取得 >>zaif = ZaifPublicApi()

    >>print(zaif.last_price('btc_jpy')) {'last_price': 58370.0} >>#残高などのアカウント情報を取得 >>zaif = ZaifPrivateApi(key, secret) >>print(zaif.get_info()) {'funds': {'jpy': 1.321, 'btc': 0.1635, 'mona': 0.0, 'xem': 0.0}, 'server_time': 1472393161, 'open_orders': 0, 'rights': {'trade': 1, 'withdraw': 1, 'info': 1}, 'deposit': {'jpy': 1.321, 'btc': 0.1635, 'mona': 0.0, 'xem': 0.0}, 'trade_count': 0}
  2. requestsって便利 import requests #getの場合 response = requests.get(self.__API_URL.format(func_name, currency_pair)) if response.status_code

    != 200: raise Exception('return status code is {}'.format(response.status_code)) res = json.loads(response.text) return res #postの場合 response = requests.post(self.__API_URL, data=params, headers=header) if response.status_code != 200: raise Exception('return status code is {}'.format(response.status_code)) res = json.loads(response.text) return res
  3. cerberusって便利 import cerberus param = { 'from_num': 10, 'currency_pair': 'btc_jpy'

    } SCHEMA = { 'from_num': { 'type': 'integer' }, 'currency_pair': { 'type': 'string', 'allowed': ['btc_jpy', 'xem_jpy', 'mona_jpy', 'mona_btc'] } } v = cerberus.Validator(SCHEMA) if v.validate(param) is False raise Exception()