質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.50%
Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

API

APIはApplication Programming Interfaceの略です。APIはプログラムにリクエストされるサービスがどのように動作するかを、デベロッパーが定めたものです。

Q&A

解決済

1回答

1321閲覧

ccxtからpythonを使ってAPIでzaifとQuoinexのアービトラージを実行しようとしましたがエラーが出ます

piptail

総合スコア9

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

API

APIはApplication Programming Interfaceの略です。APIはプログラムにリクエストされるサービスがどのように動作するかを、デベロッパーが定めたものです。

0グッド

1クリップ

投稿2018/05/24 10:34

githubからccxtをインストールし、pythonで下記のコードを実行しました(API keyとsecretは伏せています)。

lang

1import ccxt 2 3exchanges = { 4 "bitflyer": { 5 "apiKey": "", 6 "secret": "" 7 }, 8 "quoinex": { 9 "apiKey": "", 10 "secret": "" 11 }, 12 "zaif": { 13 "apiKey": "", 14 "secret": "" 15 } 16} 17 18amount = 0.001 19ask_exchange = '' 20ask_price = 99999999 21bid_exchange = '' 22bid_price = 0 23 24# 各取引所のaskとbidを取得 25for exchange_id in exchanges: 26 exchange = eval('ccxt.' + exchange_id + '()') 27 28 orderbook = exchange.fetch_order_book('BTC/JPY') 29 bid = orderbook['bids'][0][0] if len(orderbook['bids']) > 0 else None 30 ask = orderbook['asks'][0][0] if len(orderbook['asks']) > 0 else None 31 if ask < ask_price: 32 ask_exchange = exchange_id 33 ask_price = ask 34 if bid > bid_price: 35 bid_exchange = exchange_id 36 bid_price = bid 37 38# 裁定取引を行う 39#買い 40ask_price = int(ask_price/5)*5 41exchange = eval('ccxt.' + ask_exchange + '()') 42exchange.apiKey = exchanges[ask_exchange]["apiKey"] 43exchange.secret = exchanges[ask_exchange]["secret"] 44exchange.create_limit_buy_order ('BTC/JPY', amount, ask_price) 45 46#売り 47bid_price = int(bid_price*5)/5 48exchange = eval('ccxt.' + bid_exchange + '()') 49exchange.apiKey = exchanges[bid_exchange]["apiKey"] 50exchange.secret = exchanges[bid_exchange]["secret"] 51exchange.create_limit_sell_order ('BTC/JPY', amount, bid_price) 52 53print(ask_exchange, 'で', ask_price, '円で', amount, '買って') 54print(bid_exchange, 'で', bid_price, '円で', amount, '売ったので') 55print((bid_price - ask_price)*amount, '円の利益!')

ところが下記のエラーが返って来て実行されませんでした。解決方法を教えて下さい。

Last login: Thu May 24 16:17:24 on ttys000
disconoMacBook-ea:~ disco$ cd python
disconoMacBook-ea:python disco$ python arbitrage.py
Traceback (most recent call last):
File "/anaconda3/lib/python3.6/site-packages/ccxt/base/exchange.py", line 364, in fetch
response.raise_for_status()
File "/anaconda3/lib/python3.6/site-packages/requests/models.py", line 935, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 401 Client Error: Unauthorized for url: https://api.quoine.com/orders

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "arbitrage.py", line 44, in <module>
exchange.create_limit_buy_order ('BTC/JPY', amount, ask_price)
File "/anaconda3/lib/python3.6/site-packages/ccxt/base/exchange.py", line 1267, in create_limit_buy_order
return self.create_order(symbol, 'limit', 'buy', *args)
File "/anaconda3/lib/python3.6/site-packages/ccxt/qryptos.py", line 300, in create_order
response = self.privatePostOrders(self.extend(order, params))
File "/anaconda3/lib/python3.6/site-packages/ccxt/base/exchange.py", line 306, in request
return self.fetch2(path, api, method, params, headers, body)
File "/anaconda3/lib/python3.6/site-packages/ccxt/base/exchange.py", line 303, in fetch2
return self.fetch(request['url'], request['method'], request['headers'], request['body'])
File "/anaconda3/lib/python3.6/site-packages/ccxt/base/exchange.py", line 377, in fetch
self.handle_rest_errors(e, response.status_code, self.last_http_response, url, method)
File "/anaconda3/lib/python3.6/site-packages/ccxt/base/exchange.py", line 406, in handle_rest_errors
self.raise_error(error, url, method, exception if exception else http_status_code, response)
File "/anaconda3/lib/python3.6/site-packages/ccxt/base/exchange.py", line 288, in raise_error
raise exception_type(output)
ccxt.base.errors.AuthenticationError: quoinex https://api.quoine.com/orders POST 401 Client Error: Unauthorized for url: https://api.quoine.com/orders
disconoMacBook-ea:python disco$

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

とりあえず、APIの認証に失敗しているようです。

この辺が参考になると思います。適当にググって出てきたページですが・・・

(質問)QuoineのAPI設定について · Issue #12 · bitrinjani/r2

どのようにAPIアクセスキーを取得できますか。 – QUOINEX Japan

各ビットコイン取引所APIの認証で陥りやすいポイント - Qiita

済ませていない設定等があればやる必要があります。

投稿2018/05/24 12:27

hayataka2049

総合スコア30933

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

piptail

2018/05/28 09:57

ご回答有難う御座います。 とりあえず、QuoinexのAPIの問題は解決しませんでしたので、一旦Quoinexを除く取引所のみで試して見た所、うまくいきました!
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.50%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問