Beginners will make a Bitcoin automatic trading bot aiming for a lot of money! Part 1 [Information acquisition]

It's been two years since I started working ... ** "Money that doesn't increase more than I expected !!" ** ** "Anxiety about recruiting old age !!!" ** I found it! !! ** zaif **, a site where you can trade Bitcoin.

When I read it, what ...

-** Transaction fees are negative ** -** API release ** (zaif API)

Is written! !! !!

this is,,, I'm not sure about Bitcoin, The fee is minus, ** If you make a bot and make a profitable trade, you can make a profit without doing anything ...! ?? ** **

Based on the shallow idea of ..., I would like to start making bots ☆ ― (ノ ゚ Д ゚) Hachi (゚ Д ゚) Neue

Preparation

Build the environment and install the API. The OS uses Windows 7 Home premium.

1. 1. Environment

First, decide which language to use. If you look at zaif site,

Seems to be usable as a language.

This time I will make it with python that I have touched.

■ What to put:

-python2.7 I want to put it on AWS Lambda, so select 2 instead of 3. -pycharm I heard that this is a good development environment for python.

that's all. Few···

2. API installation

Looking at the python corner of zaif site, A library that makes it easy to use the zaif API (unofficial) There was a god who provided it !! ∑d (゚ ∀ ゚) d) !! Thank you for using it.

Follow the README to install. I want to install it in the working folder, so follow the steps below.

  1. Create a working folder (I created it with the name zaif)
  2. Open a command prompt
  3. Use the cd command to move to the folder created in 1.
  4. Run the command pip install zaifapi -t .

Verification

Check the movement using the zaif API.

  1. Open pycharm

  2. Open the working folder created earlier from "open"

  3. Right-click the working folder from the folder list displayed on the left and create a python file (I created it with the name main) Picture1.png

  4. Write the code in the created file (main.py).

Information acquisition (public information API)

First, let's move it simply. The first step is important for everything. Let's get the current Bitcoin price (Japanese Yen equivalent). (Just copy and execute the following (shift + F10) and it's ok)

main.py


# -*- coding: utf-8 -*-

from zaifapi import ZaifPublicApi  #Class that executes API that does not require authentication information published by Zaif
from pprint import pprint  #For display(It displays json nicely)

if __name__ == '__main__':
    zaif = ZaifPublicApi()
    pprint(zaif.last_price('btc_jpy'))

Uh, it worked ...! ヾ (゚ ω ゚ *) ノ I did it

■ Execution result

{u'last_price': 118365.0}

Process finished with exit code 0

The current price seems to be 1bitcoin = ¥ 118,365.

By the way, it seems that the ZaifPublicApi used this time also has the following methods. [Details]

--last_price: closing price --ticker: Ticker (acquisition of aggregated information) --trades: All transaction history --depth: Board information --currency_pairs: Currency pair information available in trade_history etc. --currencies: Currency information available in deposit_history etc.

For the time being, I will try to move everything.

main.py


# -*- coding: utf-8 -*-

from zaifapi import ZaifPublicApi  #Class that executes API that does not require authentication information published by Zaif
from pprint import pprint  #For display(It displays json nicely)

if __name__ == '__main__':
    zaif = ZaifPublicApi()

    print('---last_price :closing price--')
    pprint(zaif.last_price('btc_jpy'))

    print('---ticker :Ticker (acquisition of aggregated information)--')
    pprint(zaif.ticker('btc_jpy'))

    print('---trades :All transaction history--')
    print('Number of acquisitions:' + str(len(zaif.trades('btc_jpy'))))
    pprint(zaif.trades('btc_jpy'))

    print('---depth :Board information--')
    print('Number of acquisitions[buy]:' + str(len(zaif.depth('btc_jpy')['asks'])))
    print('Number of acquisitions[Sell]:' + str(len(zaif.depth('btc_jpy')['bids'])))
    pprint(zaif.depth('btc_jpy'))

    print('---currency_pairs : trade_Currency pair information available in history etc.--')
    pprint(zaif.currency_pairs('btc_jpy'))

    print('---currencies : deposit_Currency information available in history etc.--')
    pprint(zaif.currencies('all'))

■ Execution result

python


---last_price :closing price--
{u'last_price': 118400.0}

python


---ticker :Ticker (acquisition of aggregated information)--
{u'ask': 118455.0,
 u'bid': 118435.0,
 u'high': 118995.0,
 u'last': 118455.0,
 u'low': 114895.0,
 u'volume': 11032.3017,
 u'vwap': 116852.519}

python


---trades :All transaction history--
Number of acquisitions: 150
[{u'amount': 0.001,
  u'currency_pair': u'btc_jpy',
  u'date': 1490952581,
  u'price': 118455.0,
  u'tid': 41153900,
  u'trade_type': u'ask'},...<Abbreviation>

python


---depth :Board information--
Number of acquisitions[buy]:150
Number of acquisitions[Sell]:150
{u'asks': [[118455.0, 0.0209],...<Abbreviation>
 u'bids': [[118450.0, 1.7704],...<Abbreviation>

python


---currency_pairs : trade_Currency pair information available in history etc.--
[{u'aux_unit_min': 5.0,
  u'aux_unit_step': 5.0,
  u'currency_pair': u'btc_jpy',
  u'description': u'\u30d3\u30c3\u30c8\u30b3\u30a4\u30f3\u30fb\u65e5\u672c\u5186\u306e\u53d6\u5f15\u3092\u884c\u3046\u3053\u3068\u304c\u3067\u304d\u307e\u3059',
  u'event_number': 0,
  u'is_token': False,
  u'item_unit_min': 0.0001,
  u'item_unit_step': 0.0001,
  u'name': u'BTC/JPY',
  u'title': u'BTC/JPY'}]

python


---currencies : deposit_Currency information available in history etc.--
Number of acquisitions: 126
[{u'is_token': True, u'name': u'MAGATAMARDFR'},...<Abbreviation>

in conclusion

I see, you can get various things. I thought it would be easy to make, but it's surprisingly difficult to make a bot ... So far this time, next time I will try to run the API ** that requires authentication information. I felt like I glanced at it, and since I wrote "order", I'm excited that I can move like a bot. +   +   ∧_∧  + (0 ° ・ ∀ ・) (0 ° ∪ ∪ + And __) __) +

Thank you for your hard work! !! !!

update information

・ 2017/4/4: * Additional notes when installing python ・ 2017/4/27: MarkDown notation error correction (alt Thank you for pointing out.)

Recommended Posts

Beginners will make a Bitcoin automatic trading bot aiming for a lot of money! Part 1 [Information acquisition]
Beginners will make a Bitcoin automatic trading bot aiming for a lot of money! Part 3 [Local Bot]
Beginners will make a Bitcoin automatic trading bot aiming for a lot of money! Part 4 [Serverless]
Beginners will make a Bitcoin automatic trading bot aiming for a lot of money! Part 2 [Transaction with API]