15 KiB
15 KiB
In [28]:
import pandas as pd
import matplotlib.pyplot as plt
import keyring as kr
import MetaTrader5 as mt
import requests
import re
from time import sleep
from time import strftime
import datetime as dt
import sqlite3 as db
In [2]:
# login to your Trading Account - sign up in the description
mt.initialize()
login = 10800246
server = 'VantageInternational-Demo'
password = kr.get_password(server, str(login))
mt.login(login, password, server)Out [2]:
True
In [3]:
symbols = ['BTCUSD', 'ETHUSD',
'XRPUSD', 'XAUUSD', 'EURUSD', 'EURNZD']In [6]:
mt.symbol_info('BTCUSD')Out [6]:
SymbolInfo(custom=False, chart_mode=0, select=True, visible=True, session_deals=0, session_buy_orders=0, session_sell_orders=0, volume=0, volumehigh=0, volumelow=0, time=1747583136, digits=2, spread=1603, spread_float=True, ticks_bookdepth=0, trade_calc_mode=5, trade_mode=4, start_time=0, expiration_time=0, trade_stops_level=0, trade_freeze_level=0, trade_exemode=2, swap_mode=5, swap_rollover3days=5, margin_hedged_use_leg=False, expiration_mode=15, filling_mode=2, order_mode=63, order_gtc_mode=0, option_mode=0, option_right=0, bid=103854.84, bidhigh=104085.24, bidlow=102892.04, ask=103870.87, askhigh=104101.27, asklow=102908.07, last=0.0, lasthigh=0.0, lastlow=0.0, volume_real=0.0, volumehigh_real=0.0, volumelow_real=0.0, option_strike=0.0, point=0.01, trade_tick_value=0.01, trade_tick_value_profit=0.01, trade_tick_value_loss=0.01, trade_tick_size=0.01, trade_contract_size=1.0, trade_accrued_interest=0.0, trade_face_value=0.0, trade_liquidity_rate=0.0, volume_min=0.01, volume_max=100.0, volume_step=0.01, volume_limit=0.0, swap_long=-19.0, swap_short=10.0, margin_initial=0.0, margin_maintenance=0.0, session_volume=0.0, session_turnover=0.0, session_interest=0.0, session_buy_orders_volume=0.0, session_sell_orders_volume=0.0, session_open=103363.54, session_close=103363.54, session_aw=0.0, session_price_settlement=0.0, session_price_limit_min=0.0, session_price_limit_max=0.0, margin_hedged=0.0, price_change=0.4753, price_volatility=0.0, price_theoretical=0.0, price_greeks_delta=0.0, price_greeks_theta=0.0, price_greeks_gamma=0.0, price_greeks_vega=0.0, price_greeks_rho=0.0, price_greeks_omega=0.0, price_sensitivity=0.0, basis='', category='', currency_base='BTC', currency_profit='USD', currency_margin='BTC', bank='', description='Bitcoin', exchange='', formula='', isin='', name='BTCUSD', page='', path='Crypto Currency\\Crypto Major\\BTCUSD')
In [ ]:
current_date_and_time = dt.datetime.now()
format = '%Y-%m-%d %H:%M:%S'
current_date_and_time.strftime(format)
datetime.datetime(2025, 5, 18, 21, 59, 2, 465512)
In [ ]:
In [150]:
pricemovement = {}
for s in symbols:
items = mt.symbol_info(s)
pricemovement[s] = round(items.price_change,2)
#print(s, round(items.price_change,2))
sorted_pricemovement = sorted(pricemovement.items(), key=lambda x:x[1], reverse=True)
converted_dict = dict(sorted_pricemovement)
print(converted_dict)
pricemovementOut [150]:
{'XAUUSD': 0.97, 'EURUSD': 0.87, 'EURNZD': 0.47, 'ETHUSD': -0.0, 'BTCUSD': -1.65, 'XRPUSD': -3.22}
{'BTCUSD': -1.65,
'ETHUSD': -0.0,
'XRPUSD': -3.22,
'XAUUSD': 0.97,
'EURUSD': 0.87,
'EURNZD': 0.47}In [ ]:
In [68]:
con = db.connect("trading.db")
print(con.total_changes)
0
In [69]:
cursor = con.cursor()In [70]:
cursor.execute("Create Table If Not Exists pricemovment (date TEXT,symbol TEXT, movement INTEGER)")Out [70]:
<sqlite3.Cursor at 0x268bf0321c0>
In [151]:
for key, value in pricemovement.items():
print(key, value)
current_date_and_time = dt.datetime.now()
format = '%Y-%m-%d %H:%M:%S'
current_date_and_time.strftime(format)
cursor.execute("Insert into pricemovment values(?, ?, ?)", (current_date_and_time, key, value))
con.commit()BTCUSD -1.65 ETHUSD -0.0 XRPUSD -3.22 XAUUSD 0.97 EURUSD 0.87 EURNZD 0.47
In [152]:
for s in symbols:
print(s)
cursor.execute(f"Select * from pricemovment where date like '2025-05-18%' and symbol = '{s}'")
inhalt = cursor.fetchall()
print(inhalt)BTCUSD
[('2025-05-18 22:02:41.439814', 'BTCUSD', 0.13), ('2025-05-18 22:06:10.375867', 'BTCUSD', 0.2), ('2025-05-18 22:42:44.244148', 'BTCUSD', 0.65), ('2025-05-18 22:57:00.481991', 'BTCUSD', 0.65)]
ETHUSD
[('2025-05-18 22:02:41.441815', 'ETHUSD', -5.19), ('2025-05-18 22:06:10.379865', 'ETHUSD', -4.86), ('2025-05-18 22:42:44.249142', 'ETHUSD', -3.92), ('2025-05-18 22:57:00.485990', 'ETHUSD', -4.05)]
XRPUSD
[('2025-05-18 22:02:41.441815', 'XRPUSD', -0.63), ('2025-05-18 22:06:10.382865', 'XRPUSD', -0.37), ('2025-05-18 22:42:44.252143', 'XRPUSD', 0.45), ('2025-05-18 22:57:00.487996', 'XRPUSD', 0.45)]
XAUUSD
[('2025-05-18 22:02:41.441815', 'XAUUSD', -1.21), ('2025-05-18 22:06:10.384868', 'XAUUSD', -1.21), ('2025-05-18 22:42:44.255142', 'XAUUSD', -1.21), ('2025-05-18 22:57:00.491343', 'XAUUSD', -1.21)]
EURUSD
[('2025-05-18 22:02:41.441815', 'EURUSD', -0.2), ('2025-05-18 22:06:10.387868', 'EURUSD', -0.2), ('2025-05-18 22:42:44.258146', 'EURUSD', -0.2), ('2025-05-18 22:57:00.493342', 'EURUSD', -0.2)]
EURNZD
[('2025-05-18 22:02:41.441815', 'EURNZD', -0.29), ('2025-05-18 22:06:10.426110', 'EURNZD', -0.29), ('2025-05-18 22:42:44.262143', 'EURNZD', -0.29), ('2025-05-18 22:57:00.496339', 'EURNZD', -0.29)]
In [155]:
cursor.execute("Select * from pricemovment where date like '2025-05-19%'")
inhalt = cursor.fetchall()
inhalt = pd.DataFrame(inhalt, columns=['date', 'symbol', 'percentage'])
for s in symbols:
x = inhalt.loc[inhalt['symbol'] == s].percentage.diff()
pd.concat([inhalt, x])
inhalt
Out [155]:
| date | symbol | percentage | |
|---|---|---|---|
| 0 | 2025-05-19 14:42:14.686479 | BTCUSD | -1.72 |
| 1 | 2025-05-19 14:42:14.735008 | ETHUSD | -0.04 |
| 2 | 2025-05-19 14:42:14.738010 | XRPUSD | -3.05 |
| 3 | 2025-05-19 14:42:14.741009 | XAUUSD | 1.30 |
| 4 | 2025-05-19 14:42:14.743007 | EURUSD | 0.92 |
| 5 | 2025-05-19 14:42:14.746007 | EURNZD | 0.43 |
| 6 | 2025-05-19 14:57:55.112334 | BTCUSD | -1.65 |
| 7 | 2025-05-19 14:57:55.116333 | ETHUSD | 0.00 |
| 8 | 2025-05-19 14:57:55.124334 | XRPUSD | -3.22 |
| 9 | 2025-05-19 14:57:55.128902 | XAUUSD | 0.97 |
| 10 | 2025-05-19 14:57:55.186314 | EURUSD | 0.87 |
| 11 | 2025-05-19 14:57:55.202850 | EURNZD | 0.47 |
In [187]:
list = inhalt.loc[inhalt['symbol'] == 'XAUUSD'].percentage.to_list()
list
Out [187]:
[1.3, 0.97]
In [ ]:
cursor.execute("Insert into pricemovement values(?, ?, ?)", ())In [ ]:
In [59]:
cursor.execute('Drop Table pricemovment')Out [59]:
<sqlite3.Cursor at 0x268bee8ab40>
In [74]:
con.commit()In [ ]:
cursor.execute('INSERT INTO pricemovement VALUES(1, datetime('now'))'In [ ]:
con.close()In [ ]: