#!/usr/bin/env python
# ------------------------------------------------------------------------------
#
# Disclaimer:
#
# DTN grants you an nonexclusive copyright license to use this code and you can
# use it to prepare similar functions tailored to your own needs.
#
# The code is provided for illustrative purposes only and has not been tested under
# all conditions. For that reason, DTN provides this code to you "AS IS" without
# any warranties of any kind.
#
# ------------------------------------------------------------------------------
#
# Retrieve a daily history report and present result as a SVG chart.
#
# Imports
import PXWeb
# ------------------------------------------------------------------------------
# PXWeb access credentials
USER = 'YOUR_USER'
PSWD = 'YOUR_PASSWORD'
# Search pattern to send to PXWeb
PATTERN = '@C`## 20'
# Max number of history entries to return for each symbol
LIMIT = 500
# GetDailyHistory request string and CSV fields for response
FIELDS = ( 'Date', 'Open', 'Close', 'High', 'Low', 'OI', 'Volume' )
# Name of output file
OUT_FILE = 'result.svg'
# ------------------------------------------------------------------------------
# Chart size
WIDTH = 900
HEIGHT = 400
# Coordinates at origin
X0 = 30
Y0 = 60
# Grid count and title on X axis
GRID_COUNT = 10
X_TITLE = 'DAYS BEFORE {}'
# SVG objects
SVG_LINE = '\n'
SVG_POLYLINE = '{0}\n'
SVG_RECT = '\n'
SVG_TEXT = '{}\n'
SVG_TEXT_MAP = '{3}\n'
# Start of SVG file
SVG_HEAD = '''
' )
ofile.close()
# Notify
print(f'Result ready in file "{OUT_FILE}".')