Automating Your Strategy: How to Access Raw Market Data via API

avatar
· Views 2,417

The Foundation of Algo-Trading

Before you can automate a strategy on FollowMe or any other platform, you need a reliable data feed. Visual charts are great for humans, but your algorithms need raw numbers—JSON data delivered via HTTP.

The "Query" Challenge

Advanced APIs often require you to send specific parameters to filter data (e.g., requesting only the last 2 candles of Gold). This is often done by embedding a JSON object into the URL. If you look at the code below, the test_url1 contains a long string starting with %7B. This is simply the machine-readable version of the configuration comments above it.

Python Implementation

Here is a functional script to pull the latest price action for USDJPY.

Python

import time

import requests # pip3 install requestsimport json

# Extra headers

test_headers = {

    'Content-Type' : 'application/json'

}

'''

github: https://github.com/alltick/rea...

Register for token: https://alltick.co/register

Website: https://alltick.co

 

code: Please check the code list to select the code you want to query

kline_type: kline type, 1 for 1-min K, 2 for 5-min K, 3 for 15-min K, 4 for 30-min K, 5 for 1-hour K, 6 for 2-hour K, 7 for 4-hour K, 8 for daily K, 9 for weekly K, 10 for monthly K

query_kline_num: number of klines to query, max 1000

 

URL encode the following JSON and paste it into the query field of the http query string

{"trace" : "python_http_test1","data" : {"code" : "USDJPY","kline_type" : 1,"kline_timestamp_end" : 0,"query_kline_num" : 2,"adjust_type": 0}}

{"trace" : "python_http_test2","data" : {"symbol_list": [{"code": "GOLD"}]}}

{"trace" : "python_http_test3","data" : {"symbol_list": [{"code": "GOLD"}]}}

'''

test_url1 = 'https://quote.aatest.online/qu...

 

resp1 = requests.get(url=test_url1, headers=test_headers)

# Decoded text returned by the request

text1 = resp1.text

print(text1)

From Code to Signal

Once you receive text1, you parse it to get the latest Close price. If Close > Open, your bot triggers a buy; otherwise, it sells. This simple script is the cornerstone of automated execution.


Automating Your Strategy: How to Access Raw Market Data via API


免責事項:本記事で述べられている見解は著者の見解のみであり、Followmeの公式見解を反映するものではありません。Followmeは、提供された情報の正確性、完全性、信頼性について一切責任を負いません。また、書面で明示的に記載されている場合を除き、本記事の内容に基づいて行われたいかなる行動についても責任を負いません。

この記事が気に入ったら、著者にチップを送って感謝の気持ちを表しましょう。
応答 0

古いコメントはありません。ソファをつかむ最初のものになりましょう。

  • tradingContest