API đặt lệnh cho VNDirect - ProTrade Trial (Phái sinh ảo)
Công cụ hỗ trợ đặt lệnh cho nền tảng VNDirect phái sinh ảo.
Sao chép hoặc tải đoạn mã sau về máy và dùng AmiBroker để thử nghiệm.
/// chobot.vn - Zhang Khoa - 0908204305
// Huong dan su dung API dat lenh cho VNDirect ProTrade (free)
// Dien thong tin vao cac bien sau
user = "xxx"; // Ten dang nhap TK ProTrial
side = "S"; // Nhap "S" khi SHORT, "B" khi LONG
price = "1054"; // Nhap gia can dat, Lenh LO: gia chinh xac, co the dung MTL, MOK, MAK, ATC, ATO
quantity = 1; // Nhap khoi luong can dat lenh
symbol = "VN30F1M"; // Ma hop dong phai sinh: VN30F1M, VN30F2M, VN30F1Q
// Ham mo vi the
function vndOpenPosition(user, symbol, side, price, quantity) {
local url, hFile, time;
time = Now();
url = StrFormat("https://tradingview.chobot.vn/protrial?act=open&user=%s&symbol=%s&side=%s&price=%s&quantity=%g&time=%s",
user, symbol, side, price, quantity, time);
_TRACE(url); printf(url); printf("\r\n");
hFile = InternetOpenURL(url);
if (hFile) {
ret = InternetReadString(hFile);
_TRACE(ret); printf(ret);
InternetClose(hFile);
}
}
// Ham dong vi the
function vndClosePosition(user, symbol) {
local url, hFile;
url = StrFormat("https://tradingview.chobot.vn/protrial?act=close&user=%s&symbol=%s&time=%s", user, symbol, now());
_TRACE(url); printf(url); printf("\r\n");
hFile = InternetOpenURL(url);
if (hFile) {
ret = InternetReadString(hFile);
_TRACE(ret); printf(ret);
InternetClose(hFile);
}
}
// Ham huy tat ca lenh
function vndCancelAllOrders(user, symbol) {
local url, hFile;
url = StrFormat("https://tradingview.chobot.vn/protrial?act=close&user=%s&symbol=%s&time=%s", user, symbol, now());
_TRACE(url); printf(url); printf("\r\n");
hFile = InternetOpenURL(url);
if (hFile) {
ret = InternetReadString(hFile);
_TRACE(ret); printf(ret);
InternetClose(hFile);
}
}
_SECTION_BEGIN("VNDirect API");
bTrigger = ParamTrigger("Mo vi the", "Click de mo vi the");
if (bTrigger) {
_TRACE("Mo vi the");
ret = vndCancelAllOrders(user, symbol);
ret = vndOpenPosition(user, symbol, side, price, quantity);
}
bTrigger2 = ParamTrigger("Dong vi the", "Click de dong vi the");
if (bTrigger2){
_TRACE("Dong vi the");
ret = vndClosePosition(user, symbol);
}
bTrigger3 = ParamTrigger("Huy tat ca lenh", "Click de huy tat ca len");
if (bTrigger3){
_TRACE("Huy tat ca lenh");
ret = vndCancelAllOrders(user, symbol);
}
_SECTION_END();
/*
ret = vndCancelAllOrders(user, symbol);
ret = vndOpenPosition(user, symbol, side, price, quantity);
ret = vndClosePosition(user, symbol);
ret = vndCancelAllOrders(user, symbol);
*/
Plot( C, "Price", colorDefault, styleCandle );
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));