Step 1: FOREX
Forex (Forex) is an international currency market, the commodity on which the currency serves. Here they buy dollars for euros, euros for dollars, and so on. Thus, each currency pair is a separate instrument. Forex works around the clock during the working week.
Let’s create a scoreboard to display in real time some Forex quotes, as well as stock quotes and futures contracts.
Step 2: Components
In the project we use the following components:
1) RGB matrix HUB75
2) Raspberry pi zero W microcomputer
3) RGB matrix driver for Raspberry pi
4) Power supply 5V 2-5A
Step 3: RGB Matrix HUB75
2048 RGB LEDs are assembled into a panel with a diagonal of 11 inches. The panel’s LEDs shine with a brightness of up to 1200 cd/m2, which allows you to see the image on the matrix in detail even in bright lighting. On the reverse side, the control circuit is soldered and screw fasteners are provided.
There is no microcontroller and memory chips on the matrix itself. The LEDs are connected via shift registers and drivers. The LED matrix is powered from 5 V and consumes up to 4 A.
A 16-wire loop is used to connect the matrix
Step 4: Raspberry Pi Zero W Microcomputer
Raspberry Pi Zero W is the second model of a miniature single-board computer from the Raspberry Pi line. Compared to Raspberry Pi Zero Version 1.3, Zero W has not undergone any other changes, except for the addition of the Cypress CYW43438 wireless communication chip, which supports Wi-Fi networks of the 802.11n standard and Bluetooth 4.1 (Bluetooth Classic and LE)
Installation of the operating system and connection to a local network can be carried out without using a monitor and keyboards, in headless mode. Download a fresh Raspbian image from the official website from the page https://www.raspberrypi.org/downloads/raspbian . We record the downloaded image on a microSD card. You can use, for example, the Win32DiskImager program. Before installing a microSD card into the slot of the Raspberry Pi Zero W microcomputer and powering it, we will set up a network connection. After recording the image, you need to open the microSD card and create two files in the root folder: ssh (without extension) and wpa_supplicant.conf. We leave the ssh file empty (it is needed in order to activate SSH access, which is disabled by default in Raspbian). We add the following contents to the wpa_supplicant.conf file by changing the values of the ssid and psk parameters to our own.
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=RU
network={
ssid=”my_DLink”
psk=”********”
key_mgmt=WPA-PSK
}
We install the microSD card into the slot of the Raspberry Pi Zero W microcomputer and supply power to it. If the name of the Wi-Fi access point and its password are specified correctly, then the Raspberry Pi Zero W should automatically connect to the local network when booting and get a local IP address that can be viewed on the router.
Knowing the IP address, we can connect to the microcomputer via ssh (from Windows with the putty program). Login pi, password raspberry
Step 5: RGB Matrix Driver for Raspberry Pi
RGB Matrix driver for Raspberry pi – bought here – https://www.chipdip.ru/product/rgb-led-matrix-driver-cap
Used to connect the matrix to the Raspberry pi
It is installed on top of the Raspberry Pi by the sandwich method.
We connect the signal lines between the driver and the LED matrix through a loop. One pin of the loop leads to the output connector on the controller, and the other to the input data connector on the DATA IN matrix. We connect the power from the driver to the LED matrix with a power wire. One end of the wire is inserted into the PWR OUT terminal block on the controller, and the other into the POWER connector on the matrix. Connect the power to the module via an external connector “DC Barrel jack”. We use a 5V power supply. Current consumption is up to 5A, but this is when all LEDs are turned on to the maximum (white). When connecting several LED panels, the current margin increases accordingly by N-times, text information will be displayed on a black background in the project, so you can limit yourself to a 2A power supply.
Step 6: Installing Software on Raspberry Pi.
We connect to Raspberry pi zero W via ssh.
Download and run the script to configure the software to work with Raspberry LED panels.
wget https://raw.githubusercontent.com/amperka/scriptsRPI/master/amperka-rpi-rgb-matrix.sh
sudo bash amperka-rpi-rgb-matrix.sh
The program will offer a choice of image output:
1 – High Quality – the image is displayed on the matrix without flickering and glare. But then you need to disable the audio driver on Raspberry pi zero W.
2 – Convenience – flickering may occur when displaying images. But the sound will remain on.
(For mode 1, you need to install a jumper on the driver).
Select mode 2 (do not install the jumper).
The installation and compilation process will begin, then after the reboot, the rpi-rgb-led-matrix folder should appear in the root folder.
Examples of working with a matrix in python are in the folder ./home/pi/rpi-rgb-led-matrix/bindings/python/samples.
Step 7: API Forex
To get quotes, we will use the API of the website of one of the FOREX brokers –
Information on getting quotes can be viewed on the page
https://partners.instaforex.com/ru/quotes_description.php/
When contacting the address
https://quotes.instaforex.com/api/quotes
Tick we get information about current quotes
symbol – symbol of the currency pair
bid – the bid
ask value – the ask
change value – the value showing the change relative to the previous price of the currency pair
digits – the value showing the rounded price of the currency pair to the number of decimal places
lasttime – the value of the time of the last change in the price of the currency pair
change24h – the change relative to the close of the previous day
To get only the necessary currency pairs, you need to pass the q= parameter with a comma-separated list of currency pairs.
Request example:
https://quotes.instaforex.com/api/quotesTick?q=eurusd,gold,%23bitcoin
The list of pairs can be viewed on the page https://www.instaforex.com/ru/trading_symbols, where there are currency pairs, precious metals, stocks, cryptocurrencies, oil futures and so on.
Select the necessary pairs and start writing the program.
Step 8: Programming.
Create a forex file in the folder /home page/pi/rpi-rgb-led-matrix/bindings/python/samples.py
Connecting the necessary libraries
import json
import requests
import time
from rgbmatrix import RGBMatrix, RGBMatrixOptions
from rgbmatrix import graphics
For the matrix, you need to set the settings
# Configuration for the matrix
options = RGBMatrixOptions()
options.rows = 32
options.cols = 64
options.chain_length = 1
options.parallel = 1
options.row_address_type = 0
options.multiplexing = 0
options.pwm_bits = 11
options.brightness = 100
options.pwm_lsb_nanoseconds = 130
options.led_rgb_sequence = “RGB”
options.pixel_mapper_config = “”
To store the received data, we will create a dictionary. Dictionaries in python are unordered collections of arbitrary objects with key access.
arr={‘symbolurl’:{0:’Forex’,1:’EURUSD’,2:’%23AAPL’,3:’GOLD’,4:’%23FB’},
‘symbol’:{0:’Forex’,1:’ EUR/USD’,2:’Apple inc’,3:’ GOLD’,4:’Facebook’},
‘ask’:{0:’ ‘,1:’0′,2:’0′,3:’0′,4:’0’},
‘bid’:{0:’ ‘,1:’0′,2:’0′,3:’0′,4:’0’},
‘change’:{0:0, 1:0, 2:0 ,3:0 ,4:0},
‘lasttime’:{0:’ ‘,1:’0′,2:’0′,3:’0′,4:’0’}
}
Every 10 seconds we form an address for receiving data from one of the pairs and save the received data in the dictionary. The data from the dictionary is displayed on the screen and in the terminal.
Step 9: File Сontents Forex.py
#!/usr/bin/env python import json import requests import time from rgbmatrix import RGBMatrix, RGBMatrixOptions from rgbmatrix import graphics # Configuration for the matrix options = RGBMatrixOptions() #adafruit-hat #options.hardware_mapping = 'regular' options.rows = 32 options.cols = 64 options.chain_length = 1 options.parallel = 1 options.row_address_type = 0 options.multiplexing = 0 options.pwm_bits = 11 options.brightness = 100 options.pwm_lsb_nanoseconds = 130 options.led_rgb_sequence = "RGB" options.pixel_mapper_config = "" matrix = RGBMatrix(options = options) # link="https://quotes.instaforex.com/api/quotesTick?q="; arr={'symbolurl':{0:'Forex',1:'EURUSD',2:'%23AAPL',3:'GOLD',4:'%23FB'}, 'symbol':{0:'Forex',1:' EUR/USD',2:'Apple inc',3:' GOLD',4:'Facebook'}, 'ask':{0:' ',1:'0',2:'0',3:'0',4:'0'}, 'bid':{0:' ',1:'0',2:'0',3:'0',4:'0'}, 'change':{0:0, 1:0, 2:0 ,3:0 ,4:0}, 'lasttime':{0:' ',1:'0',2:'0',3:'0',4:'0'} } pos=0 offset=0; matrix.Clear() canvas=matrix font1 = graphics.Font() font1.LoadFont("../../../fonts/7x13.bdf") font2 = graphics.Font() font2.LoadFont("../../../fonts/5x7.bdf") font3 = graphics.Font() font3.LoadFont("../../../fonts/4x6.bdf") textColor1 = graphics.Color(0, 255, 0) textColor2 = graphics.Color(0, 0, 255) textColor3 = graphics.Color(0, 0, 255) textColor4 = graphics.Color(0, 255, 0) textColor5 = graphics.Color(255, 0, 0) s = graphics.DrawText(canvas, font2, 0, 15, textColor1, "instaforex.com") time.sleep(2) # ipos=arr.keys() ipos=sorted(ipos) for i in range(len(ipos)): print(ipos[i],"=",arr[ipos[i]][0]) print(ipos[i],"=",arr[ipos[i]][1]) print(ipos[i],"=",arr[ipos[i]][2]) print(ipos[i],"=",arr[ipos[i]][3]) print(ipos[i],"=",arr[ipos[i]][4]) while True: # matrix.Clear() graphics.DrawText(canvas, font1, 0, 10, textColor2, arr['symbol'][pos]) graphics.DrawText(canvas, font2, 5, 20, textColor2, str(arr['ask'][pos])) if arr['change'][pos]>0: graphics.DrawText(canvas, font2, 10, 30, textColor4, "+"+str(arr['change'][pos])) elif arr['change'][pos]<0: graphics.DrawText(canvas, font2, 10, 30, textColor5, str(arr['change'][pos])) else : graphics.DrawText(canvas, font2, 10, 30, textColor3, "") # pos=max(1,(pos+1)%5) print("pos=",pos) responce=requests.get("https://quotes.instaforex.com/api/quotesTick?q="+arr['symbolurl'][pos]) data1=json.loads(responce.text) print("data1=",data1) i=0 for rec in data1: print(pos) arr['ask'][pos]=rec['ask'] arr['bid'][pos]=rec['bid'] arr['change'][pos]=rec['change'] #print("pos=",pos," ask=",arr['ask'][pos]," bid=",rec['bid'], " change=",rec['change']) i=i+1 for rec in data1: #print(rec) ipos=rec.keys() ipos=sorted(ipos) for i in range(len(ipos)): print(ipos[i],"=",rec[ipos[i]]) print("----------------") # time.sleep(10)
Step 10: Run
Starting the file
sudo python3 /home/pi/rpi-rgb-led-matrix/bindings/python/samples/forex.py
Source: Tableau of Forex Quotes in Real Time on Raspberry Pi and RGB Matrix 32×64