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".
Add "LINE Notify" to your friends from LINE on your smartphone. 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.
Issue a token. The token name should be an appropriate name. 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.
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.
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.
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
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.
Now that the environment has been created, I would like to make something like a portal site.
Continue.
Recommended Posts