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

avatar
· Views 2,404

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