Tự động hóa giao dịch của bạn
Ngôn ngữ của bạn
Quy tắc của bạn

Biến ý tưởng giao dịch của bạn thành hành động với GMI Edge API - viết mã và tự động hóa Bots giao dịch của bạn bằng bất kỳ ngôn ngữ nào bạn chọn, bao gồm Python, C, C++ đến C#, v.v.

Lợi ích của giao dịch bằng Bots so với giao dịch thủ công

Hoạt động thị trường 24/7

Bots không bao giờ ngủ — chúng nắm bắt cơ hội cả ngày lẫn đêm, ngay cả khi bạn đang nghỉ ngơi.

Giao dịch không cảm xúc

Loại bỏ nỗi sợ hãi và phân vân; bot sẽ thực hiện kế hoạch của bạn mà không do dự.

Phản ứng tức thì với các sự kiện thị trường

Tự động phản hồi khi giá tăng đột biến, tin tức hoặc biến động — nhanh hơn bất kỳ người nào.

Khả năng mở rộng

Quản lý các chiến lược phức tạp hoặc giao dịch tần suất cao ở quy mô không thể thực hiện thủ công.

Nó hoạt động như thế nào

Đăng ký hoặc Đăng nhập vào GMI Members Area

Nhận thông tin xác thực tài khoản giao dịch GMI EDGE của bạn

Đọc tài liệu và bắt đầu viết chiến lược giao dịch của bạn

Khởi chạy bot giao dịch và xem nó giao dịch cho bạn

Đặc trưng

Tự do đa ngôn ngữ

Xây dựng bot của bạn bằng bất kỳ ngôn ngữ lập trình nào—Python, C++, C#, Java, JavaScript, Go, v.v. Không có giới hạn.

Tiềm năng tự động hóa không giới hạn

Không giới hạn số lượng hoặc độ phức tạp của bot—mở rộng từ bot đơn giản đến các chiến lược đa tài sản, đa tài khoản nâng cao.

Khả năng tương thích đa nền tảng

Sử dụng API từ Windows, Mac, Linux hoặc thậm chí là máy chủ đám mây—chạy bots ở bất cứ đâu bạn muốn.

Kiến trúc hiện đại, trong suốt

Không có lớp ẩn hay ngôn ngữ kịch bản độc quyền. Mã của bạn giao tiếp trực tiếp với API của chúng tôi, đảm bảo tính minh bạch và linh hoạt tuyệt đối.

Câu hỏi thường gặp

GMI Edge API là gì?
API GMI Edge là một công cụ mạnh mẽ cho phép bạn tự động hóa giao dịch bằng cách xây dựng bot bằng bất kỳ ngôn ngữ lập trình nào. Kết nối trực tiếp với tài khoản GMI của bạn, nhận dữ liệu thị trường theo thời gian thực và đặt lệnh giao dịch theo chương trình.
Tôi có thể sử dụng ngôn ngữ lập trình nào với GMI Edge API?
Bạn có thể sử dụng bất kỳ ngôn ngữ lập trình nào. Cho dù bạn lập trình bằng Python, C++, C#, Java, JavaScript hay ngôn ngữ nào khác, GMI Edge API đều linh hoạt để phù hợp với quy trình làm việc của bạn.
Kết nối API an toàn đến mức nào?
Mọi giao tiếp API đều được mã hóa để đảm bảo an toàn cho bạn. Chúng tôi sẽ sớm giới thiệu xác thực khóa API để tăng cường bảo mật và kiểm soát.
Người dùng API có thể sử dụng những hỗ trợ nào?
Bạn sẽ được tiếp cận với hỗ trợ kỹ thuật chuyên dụng, tài liệu chi tiết, mã mẫu và cộng đồng nhà phát triển năng động. Hỗ trợ ưu tiên dành cho người dùng nâng cao.
Có giới hạn sử dụng hoặc phí nào cho API không?
API GMI Edge hoàn toàn miễn phí cho tất cả khách hàng của GMI Edge, không có phí ẩn hoặc phụ phí nào.
Tôi có thể thử nghiệm bot giao dịch của mình mà không phải mạo hiểm tiền thật không?
Có, GMI Edge cung cấp tài khoản demo, cho phép bạn thử nghiệm và tinh chỉnh chiến lược một cách an toàn mà không cần phải mạo hiểm tiền thật.

Ví dụ về mã cho Trading Bot

import yaml

import httpx

import sys

import ssl

from datetime import datetime, timedelta

import time



def read_config(filename):

with open(filename, "r") as file:

return yaml.safe_load(file)



def check_response(response):

if response.status_code == httpx.codes.OK:

return

error_body = response.json()

error_code = error_body["Code"]

error_message = error_body["Error"]

print(f"[{error_code}] {error_message}")

sys.exit(-1)



def report_position(position):

order_id = position["OrderId"]

amount = position["Amount"]

symbol = position["Symbol"]

order_side = position["OrderSide"]

order_status = position["OrderStatus"]

print(f"#{order_id} {symbol} {amount} {order_side} {order_status}")



def time_to_seconds(time_text):

t = datetime.strptime(time_text, "%M:%S")

delta = timedelta(minutes=t.minute, seconds=t.second)

return delta.total_seconds()



def find_position_profit(orders_state, order_id):

pos_state = next(

order for order in orders_state if order["OrderId"] == order_id

)

return pos_state["Profit"]



if __name__ == "__main__":

print("Reading bot configuration...")

config = read_config("bot-config.yaml")

api_url = config["api-url"]

account = config["account"]

password = config["password"]

symbols = config["symbols"]

pause1 = config["pause1"]

pause1_sec = time_to_seconds(pause1)

pause2 = config["pause2"]

pause2_sec = time_to_seconds(pause2)

print("Done.")


print(f"Connecting to account {account} via {api_url}...")

ssl_context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)

ssl_context.load_default_certs()

http = httpx.Client(verify=ssl_context)

login_response = http.post(

api_url + "/login", json={"BotId": account, "Password": password}

)

check_response(login_response)


print("Connected.")

access_token = login_response.json()["AccessToken"]

auth_headers = {"Authorization": "Bearer " + access_token}


try:

while True:

print("Checking my open positions...")

open_pos_response = http.get(

api_url + "/positionlist", headers=auth_headers

)

check_response(open_pos_response)

all_positions = open_pos_response.json()["Orders"]

my_positions = [

p for p in all_positions if p["OrderSource"] == "TRADING_API"

]


if len(my_positions) == 0:

print("No open positions.")

else:

for position in my_positions:

report_position(position)


print("Closing my open positions...")

for position in my_positions:

order_id = position["OrderId"]

close_pos_response = http.post(

api_url + "/closeposition",

json={"OrderId": order_id},

headers=auth_headers,

)

check_response(close_pos_response)


print("Closed.")


for symbol in symbols:

print(f"Checking symbol {symbol}...")

syminfo_response = http.post(

api_url + "/symbolinfo",

json={"Symbol": symbol},

headers=auth_headers,

)

check_response(syminfo_response)

min_lots = syminfo_response.json()["MinTradeAmount"]

lot_size = syminfo_response.json()["ContractSize"]

min_amount = min_lots * lot_size


print(f"Minimum tradable amount for {symbol}: {min_amount}")


print("Opening positions")

pos_ids = []

for symbol in symbols:

buy_pos_response = http.post(

api_url + "/sendorder",

json={

"Symbol": symbol,

"OrderSide": "BUY",

"OrderType": "MARKET",

"Amount": min_amount,

},

headers=auth_headers,

)

check_response(buy_pos_response)

report_position(buy_pos_response.json())

buy_pos_id = buy_pos_response.json()["OrderId"]


sell_pos_response = http.post(

api_url + "/sendorder",

json={

"Symbol": symbol,

"OrderSide": "SELL",

"OrderType": "MARKET",

"Amount": min_amount,

},

headers=auth_headers,

)

check_response(sell_pos_response)

report_position(sell_pos_response.json())

sell_pos_id = sell_pos_response.json()["OrderId"]

pos_ids.append((buy_pos_id, sell_pos_id))


print(f"Wait {pause1}...")

time.sleep(pause1_sec)

print("Checking profit and loss...")

account_state_response = http.get(

api_url + "/accountstate", headers=auth_headers

)

check_response(account_state_response)

balance = account_state_response.json()["AccountState"]["Balance"]

print(f"Account balance: {balance}")

orders_state = account_state_response.json()["OrderStates"]


to_close = []

for buy_pos_id, sell_pos_id in pos_ids:

buy_pos_profit = find_position_profit(orders_state, buy_pos_id)

sell_pos_profit = find_position_profit(

orders_state, sell_pos_id

)

print(f"#{buy_pos_id} PROFIT {buy_pos_profit}")

print(f"#{sell_pos_id} PROFIT {sell_pos_profit}")


if buy_pos_profit <= sell_pos_profit:

to_close.append(buy_pos_id)

else:

to_close.append(sell_pos_id)


print("Close less profitable position in each pair...")


for order_id in to_close:

print(f"Closing #{order_id}...")

close_response = http.post(

api_url + "/closeposition",

json={"OrderId": order_id},

headers=auth_headers,

)

check_response(close_response)

print("Done.")

Giải thích

Mã được mô tả xác định trình tự các hành động cho Trading Bot:


  • 1. Kết nối với Trading API cho một tài khoản cụ thể
  • 2. Chọn công cụ mục tiêu
  • 3. Xác định tất cả các vị thế được bot mở cho các công cụ này
  • 4. Đóng tất cả các vị thế hiện có do bot khởi tạo trên các công cụ đã chọn
  • 5. Mở 2 vị thế đối lập cho một công cụ:
    • Vị thế MUA
    • Vị thế BÁN
  • 6. Sau 1 phút: Đóng vị thế thua lỗ (dựa trên PnL hiện tại)
  • 7. Sau 1 phút: Lặp lại toàn bộ vòng lặp bắt đầu từ bước 1

Nền tảng Giao dịch GMI Edge Mới của chúng tôi!

Được thiết kế để tăng cường trải nghiệm giao dịch của bạn, Nền tảng Giao dịch Edge mang đến một kỷ nguyên mới của khả năng cho thế giới giao dịch ngoại hối.

Tự động hóa giao dịch của bạn. Ngôn ngữ của bạn. Quy tắc của bạn.

Biến ý tưởng giao dịch của bạn thành hành động với GMI Edge API - viết mã và tự động hóa Bots giao dịch của bạn bằng bất kỳ ngôn ngữ nào bạn chọn, bao gồm Python, C, C++ đến C#, v.v.