This time, I would like to move the API ** that requires authentication information and actually trade ✧ + (0 ° ・ ∀ ・) + wktk✧ I will verify the movement immediately.
API that requires authentication information: Let's run ** ZaifPrivateApi **. This time, we verified information acquisition (get_info ()) and transaction (trade ()).
This API requires two keys, key and secret, so create it with ** zaif **.
Register a new user in zaif and log in
Select the account in the upper right
Select API KEY of API for developers
Select get Verification Code
A 6-digit code will be sent to the registered email address, so enter it.
Enter the name of the Key and select the authority to associate with the key (link info, trade)
Press create to generate the key
Make a copy of the Keys and secret of Keys and make a note of them.
** 0. Get transaction information using the Key and secret created in Preparation **.
main.py
# -*- coding: utf-8 -*-
from zaifapi import ZaifPrivateApi #Class that executes API that requires authentication information published by Zaif
from pprint import pprint #For display(It displays json nicely)
if __name__ == '__main__':
key = '[Key created in preparation]'
secret = '[Secret created in preparation]'
zaif = ZaifPrivateApi(key, secret)
pprint(zaif.get_info())
■ Execution result
python
{u'deposit': {u'btc': 0.0, u'jpy': 0.0, u'mona': 0.0, u'xem': 0.0},
u'funds': {u'btc': 0.0, u'jpy': 0.0, u'mona': 0.0, u'xem': 0.0},
u'open_orders': 0,
u'rights': {u'info': 1, u'personal_info': 0, u'trade': 0, u'withdraw': 0},
u'server_time': 1491068366,
u'trade_count': 0}
I got the deposit, funds, order quantity (open_orders), authority information (rights), and trade count (trade_count). It seems that a lightweight version of get_info2 () that does not get the number of trades is also available.
Now that the warm-up is over, it's today's main dish "** Trading **".
I will put about 1,000 yen for the transaction test. There was no credit card payment in the "Japanese Yen Deposit / Withdrawal" menu, so Buy Bitcoin directly from Buy Bitcoin with Credit Card.
Enter the required information and purchase. I bought it safely! ヾ (o´∀`o) ノ
**···Hmm? ** ** It seems that about 7.6% was taken as a commission ... (´ ・ ω ・ `)
Since it is the lowest purchase price, the commission is probably relatively high ... Regain your mind and go to the verification of trade (`・ ω ・ ´)
Document says that you should pass currency_pair, action, price, and amount.
Set each value in the correct order. Sell all your Bitcoin (0.0076btc). For the sale price, specify the current Bitcoin price of ¥ 121,800. ... I'm angry. If the argument is wrong.
python
TypeError: trade() takes exactly 1 argument (5 given)
When I check the error on the console, it is said that I am passing 5 even though only 1 is entered. (The document says that 4 parameters are required. I'm passing 4 parameters ...)
When I went around, the ancestor solved it. (Thank you. It was very helpful.) Apparently, the way to specify the parameters was wrong.
main.py
# -*- coding: utf-8 -*-
from zaifapi import ZaifPrivateApi #Class that executes API that requires authentication information published by Zaif
from pprint import pprint #For display(It displays json nicely)
if __name__ == '__main__':
key = '[Key created in preparation]'
secret = '[Secret created in preparation]'
zaif = ZaifPrivateApi(key, secret)
#Sell Bitcoin
pprint(zaif.trade(currency_pair="btc_jpy", action="ask", price=121800, amount=0.0076))
■ Execution result
python
{u'funds': {u'btc': 0.0, u'jpy': 925.946, u'mona': 0.0, u'xem': 0.0},
u'order_id': 0,
u'received': 925.946,
u'remains': 0.0}
It moved ~ ヾ (゚ ω ゚ *) ノ It is successful because btc becomes 0 and jpy increases.
Now that we have sold Bitcoin, we will try to buy Bitcoin in the same way. I will buy as much Bitcoin as I can with the Japanese Yen (¥ 925.946) I have. The purchase amount is calculated by the amount of money you have (¥ 925) ÷ the current price of 1bitcoin (¥ 122,210).
main.py
# -*- coding: utf-8 -*-
from zaifapi import ZaifPrivateApi #Class that executes API that requires authentication information published by Zaif
from pprint import pprint #For display(It displays json nicely)
if __name__ == '__main__':
key = '[Key created in preparation]'
secret = '[Secret created in preparation]'
zaif = ZaifPrivateApi(key, secret)
#Current price of 1 Bitcoin
price = 122210
#Since the API supports up to 4 digits after the decimal point, round()
#If the 5th decimal place is moved up, there will be a shortage of assets.(- 0.0001)
amount = round(925.0/price, 4) - 0.0001
#Buy Bitcoin
pprint(zaif.trade(currency_pair="btc_jpy", action="bid", price=price, amount=amount))
■ Execution result
python
{u'funds': {u'btc': 0.0075, u'jpy': 9.4085, u'mona': 0.0, u'xem': 0.0},
u'order_id': 0,
u'received': 0.0075,
u'remains': 0.0}
I bought 0.0075 Bitcoin ヾ (゚ ω ゚ *) ノ Japanese yen remains ¥ 9.4805, but it seems that there is no help for the specifications below the minimum unit of 0.0001 Bitcoin (¥ 12.221).
In addition to get_info (), get_info2 (), trade () verified this time, the following methods are prepared. [Details]
- get_personal_info :Get the nickname and image URL used for chat
- get_id_info :Get personal information such as user ID and email address
- trade_history :Get transaction history
- active_orders :Get a list of currently valid orders
- cancel_order :Cancel an order
- withdraw :Make a cryptocurrency withdrawal request
- deposit_history :Get deposit history
- withdraw_history :Get withdrawal history
This time, I was able to ** get transaction information ** and ** transaction *! ヽ ( ´∀ `) Eight (´∀ ` *) ノ I stumbled on the way, but I'm glad I moved safely. Now that we have obtained the information and verified the transaction, Next time, combine the contents verified this time and repeat "Get information ▶ Sell / Buy ▶ Return to the beginning" I would like to create something that will trade without permission. ** I think we can finally make something that can be called a bot ...! !! I expect **.
Thank you for your hard work! !!
Recommended Posts