[Financial Engineering] How to get market prices with Python — Part I

A Ydobon
2 min readJun 7, 2021

--

There are two prerequisites before we start.

시작하기 전에 두가지 준비사항이 있습니다.

開始する前に、二つの準備があります。

  • Gmail account
  • Chrome browser

Step 1. google colab

Search for colab in google search and create a new notebook.

google search에서 colab을 검색하고, 새 노트북을 만듭니다.

google searchでcolabを検索して、新しいノートパソコンを作成します。

Step 2. polygon.io

Go to the site called polygon.io in your browser. If you are logging in for the first time, of course, you must sign up and create a new account. If you log in using the account you created, you can find a place called API Keys. This is the most important information to get market data. You can make a copy.

browser에서 polygon.io라는 사이트로 들어갑니다. 처음 접속하는 경우에는 당연히 sign up을 해서 새로운 계정을 만들어야 합니다. 만든 계정을 이용하여 들어가보면 API Keys라는 곳을 찾을 수가 있습니다. 이것이 market data를 가져오기 위한 제일 중요한 정보입니다. Copy를 할 수가 있습니다.

browserでpolygon.ioというサイトに入ります。初めて接続する場合には、当然のことながらsign upをして、新しいアカウントを作成します。作成したアカウントを使用して、入ってみるとAPI Keysというところを見つけることができます。これmarket dataを取得するための最も重要な情報です。Copyをすることができます。

Step 3. Intro to Python

Copy and paste the following sentences into colab. Then, replace the ******* part with your own API Key.

다음의 문장을 colab에 복사하여 넣습니다. 그리고는 *******로 된 부분을 자신의 API Key로 바꾸어 넣습니다.

次の文章をcolabにコピーして挿入します。そして、*******になった部分を自分のAPI Keyに入れ替えました。

import requestsurl = "https://api.polygon.io/v1/open-close/AAPL/2020-10-14?unadjusted=true&apiKey=**************************"response = requests.get(url)print(response.text)

Success if you see something like this: It will look long on one line.

다음과 같은 것이 보이면 성공입니다. 한 줄에 길게 보일 것입니다.

次のようなものが表示されたら成功です。行に長く見えます。

{
"status": "OK",
"from": "2020-10-14",
"symbol": "AAPL",
"open": 121,
"high": 123.03,
"low": 119.62,
"close": 121.19,
"volume": 151057198,
"afterHours": 120.81,
"preMarket": 121.55
}

Let’s learn three things.

There is a part enclosed in " " in the entered Python code. This quoted data type is called a string.

If you look closely at the output, it is in the format { key_1: value_1, key_2: value_2, key_3: value_3, …}. This data type is called a dictionary.

url = “https://..." does not mean that the left and right sides are the same. This means that we evaluate the value on the right side and store the result in the variable on the left side.

딱 세가지만 배우겠습니다.

입력한 Python code에서 " "로 묶인 부분이 있습니다. 이렇게 따옴표로 묶인 데이터 형식을 string이라고 부릅니다.

출력을 가만히 살펴보면 { key_1: value_1, key_2: value_2, key_3: value_3, ...}으로 형식으로 되어 있습니다. 이러한 데이터 형식을 dictionary라고 부릅니다.

url = "https://..." 은 좌변과 우변이 같다는 뜻이 아닙니다. 우변을 값을 evaluate하고 그 결과를 좌변에 있는 변수에 저장한다는 뜻입니다.

ぴったり三つだけ学びます。

入力されたPython codeで””で囲まれた部分があります。このように二重引用符で囲まれたデータ型をstringと呼びます。

出力をじっと見てみると、{key_1:value_1、key_2:value_2、key_3:value_3、…}で型になっています。これらのデータ型をdictionaryと呼びます。

url=”https://…”は、左辺と右辺が等しいことを意味はありません。右辺に値をevaluateし、その結果を左辺の変数に格納することを意味します。

--

--