LoginSignup
0
0

More than 5 years have passed since last update.

C-CEX APIを使ってみた

Last updated at Posted at 2017-12-11

C-CEX

  • bitzenyを購入するために使われる取引所の一つ.
  • 正直,エラーが多すぎて送金とか怖い.

とりあえず使ってみた

  • coincheckみたいにC-CEXもAPIがあるので一応使ってみた.

恥ずかしいレベルのコーディング

  • めっちゃ適当.
  • まあ,自分のメモ書きということで,このレベルでも言いかなということで公開
  • Python 3.5.2を使った
    • Python2 使っている人文字コードを合わせる必要あり

コード


import os
import requests
import json

url = 'https://c-cex.com/t/prices.json'
url_ex = 'https://www.gaitameonline.com/rateaj/getrate'


def urll():

        response = requests.get(url)
        if response.status_code != 200:
                raise Exception('return status code is {}'.format(response.status_code))
        response_ex = requests.get(url_ex)
        if response_ex.status_code != 200:
                raise Exception('return status code is {}'.format(response_ex.status_code))

        price = json.loads(response.text)
        price_ex = json.loads(response_ex.text)

        return price,price_ex

if __name__ == '__main__':

        price,price_ex=urll()


        exchange = float(price_ex["quotes"][20]["ask"])
        price_zny_usd = price['zny-usd']['buy']

        print("1znyの値段",'%03.8f' % price_zny_usd,"$")
        zny_price = price_zny_usd * exchange
        print("1znyの値段",'%.2f' % zny_price,"円")

一応説明

  • C-CEXでは日本円では表示されないので,為替情報を取得するAPIを使った.
  • APIで使った情報は買値のみ
    • ほかのも表示しようかと思ったけど,今回はとりあえずAPIを使ってみようという感じだったからやめた.(printの型とか超適当)
  • まあAPIを使ったことない人には,参考になるかも!
    • API使ったことない人はとりあえずJSONの勉強しよう
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0