To win in Forex Part 4 ~ LINE Notification

This is a continuation of the previous "To win with foreign exchange 3 ~ LAMP construction".

Get notified from the LINE Messageing API when price movements increase. I thought about other methods, but

--SMS is a basic charge --twitter is not suitable for use (misunderstood as bot) --facebook Hmm, it looks difficult ――I don't use #slack very much

That's why I chose LINE. The reference for this time is "Send a message to LINE with Python".

Make LINE Notify a Friend

Add "LINE Notify" to your friends from LINE on your smartphone. Screenshot_addfriend.png It seems that you already have nearly 2 million friends, but it would be difficult if you had that much. I can't remember it anymore.

Issuance of LINE Access Token

Issue a token. The token name should be an appropriate name. Screenshot_publishtoken.png I made one mistake here If you want to create a group and notify it, it seems that you had to select "Talk room to send notification" on this screen. I had to recreate it later.

Python code

Now that we have the token, we'll embed it in our Python program. See the full code at GitHub.

from decimal import Decimal
import requests

Import the required libraries.

# LINE Notify settings
line_url = "https://notify-api.line.me/api/notify"
line_access_token = "## Your LINE Access Token ##"
line_headers = {'Authorization': 'Bearer ' + line_access_token}

This is a setting for notifying LINE Notify.

line_message = ""

# Difference high and low
diff = Decimal(raw[price]["h"]) - Decimal(raw[price]["l"])
print("{} {}: {}".format(
    raw["time"].replace("000Z", "").replace("T", " "),
    response["instrument"],
    diff
))

if response["instrument"].find("_JPY") > -1:
    if diff >= 0.1:
        line_message += "'" + response["instrument"] + "' "
else:
    if diff >= 0.0015:
        line_message += "'" + response["instrument"] + "' "

# LINE Notify
if len(line_message) > 0:
    line_payload = {"message": "There were signficant price fluctuations in " + line_message + "."}
    r = requests.post(line_url, headers=line_headers, params=line_payload)

If the exchange rate against the yen is 0.1 yen or more, and if there is a price movement of 0.0015 US dollars (others) or more, the LINE notification message will be stored. Finally, request.post a message that LINE should notify you.

result

Basically, you only need to know which currency pair has the big price movement, so it looks like this. It is also a good idea to check the chart and trade if there is a sign. Screenshot_linenotify.png

Run when Raspberry Pi starts

It is convenient to register as a startup.

shell:/home/pi/.config/autostart/market.desktop


[Desktop Entry]
Type=Application
Name=Market Monitor
Exec=/usr/bin/python3 -B /home/pi/python/MarketMonitor/oanda_candle.py
Terminal=false

Operation check

It's okay if you reboot your system and see if it's working or not if you can see it in the database with phpmyadmin. I don't think LINE notifications usually come in very often. Screenshot_phpmyadmin.png

Now that the environment has been created, I would like to make something like a portal site.

Continue.

Recommended Posts

To win in Forex Part 4 ~ LINE Notification
I tried Line notification in Python
How to receive command line arguments in Python
How to do zero-padding in one line with OpenCV
The easiest line bot in the world to lose weight
Go language to see and remember Part 7 C language in GO language
Introduction to PyQt4 Part 1
Command line tool to put .gitkeep in an empty directory
How to specify command line arguments when debugging in PyCharm
Procedure memo to put AWS command line interface in CentOS6
Introduction to Socket API Learned in C Part 2 Client Edition