전략 상태 표시줄에서 인터랙티브 버튼 함수를 구성합니다

저자:리디아, 창작: 2023-07-13 14:14:38, 업데이트: 2024-01-02 21:29:26

img

전략 상태 표시줄에서 인터랙티브 버튼 함수를 구성합니다

API 문서에 설명

// You can also construct a button in the form, and use GetCommand to receive the contents of the cmd attribute.
var table = {
    type: 'table',
    title: 'position operation',
    cols: ['Column1', 'Column2', 'Action'],
    rows: [
        ['abc', 'def', {'type':'button', 'cmd': 'coverAll', 'name': 'close position'}],
    ]
};
LogStatus('`' + JSON.stringify(table) + '`')
// Or construct a separate button
LogStatus('`' + JSON.stringify({'type':'button', 'cmd': 'coverAll', 'name': 'close position'}) + '`')
// Button styles can be customized (bootstrap's button attributes)
LogStatus('`' + JSON.stringify({'type':'button', 'class': 'btn btn-xs btn-danger', 'cmd': 'coverAll', 'name': 'close position'}) + '`')

API 문서는 전략 상태 표시줄에 테이블, 문자열, 이미지, 차트 등을 표시하는 것은 API 함수를 호출하여 수행된다는 것을 보여줍니다.LogStatus- 그래요 우리는 JSON 데이터를 구성하여 대화형 버튼을 설정할 수도 있습니다.

DEMO 소스 코드:

function test1(p) {
    Log("Calls a custom function with parameters:", p);
    return p;
}
function main() {
    while (true) {
        var table = {
            type: 'table',
            title: 'position operation',
            cols: ['Column1', 'Column2', 'Action'],
            rows: [
                ['a', '1', {
                    'type': 'button',                       // To display a button, you must set the type to button.
                    'cmd': "CoverAll",                      // String, sent data, accepted by the GetCommand() function.
                    'name': 'close position'                           // The name displayed on the button.
                }],
                ['b', '1', {
                    'type': 'button',
                    'cmd': 10,                              // numerical value
                    'name': 'Send value'
                }],
                ['c', '1', {
                    'type': 'button',
                    'cmd': _D(),                            // The function is called for the duration of the strategy run
                    'name': 'call the function'
                }],
                ['d', '1', {
                    'type': 'button',
                    'cmd': 'JScode:test1("ceshi")',       // String, the JS code to execute.
                    'name': 'Send JS Code'
                }]
            ]
        };
        LogStatus('`' + JSON.stringify(table) + '`')

        var str_cmd = GetCommand();
        if (str_cmd) {
            Log("Received Interaction Data str_cmd:", "type:", typeof(str_cmd), "value:", str_cmd);
        }

        if (str_cmd && str_cmd.split(':', 2)[0] == "JScode") {          // Determine if there is a message
            var js = str_cmd.split(':', 2)[1];                          // Split the returned message string, limit it to two, and assign the element with index 1 to a variable named js. 
            Log("Execute debugging code:", js);                                     // Output executed code
            try {                                                       // Abnormal detection
                eval(js);                                               // Executes the eval function, which executes the parameters (code) passed in.
            } catch (e) {                                               // throw an exception
                Log("Exception", e);                                    // Output error messages
            }
        }

        Sleep(500);
    }
}

실행해보죠. 전략은 아래와 같습니다.

img

우리는 상태 표시줄에 있는 테이블의 버튼을 클릭하여 상호 작용을 유발할 수 있습니다. 우리는 Close PositionSend Value 버튼을 차례로 클릭합니다. Close Position 버튼을 누르면 메시지가 정상적으로 전송됩니다.

img

img

> But it doesn't work when you click on "Send value" because[ ```'cmd': 10,                              // value``` ]Here is 10. Numeric types cannot be sent.

https://www.fmz.com![img](/upload/asset/2d8e0f86599f1b82da792544b7b840bc824d4a96.png) 
# It has been optimized to be compatible with numeric values, and returns a string of values.

다음으로 Call Function 버튼을 클릭하면 호출되는 함수가 _D() 함수를 테스트하고, _D() 함수는 현재 시간 문자열을 계속 반환합니다.

수신된 데이터는 로그에 인쇄됩니다.

img

img

마지막으로, JS 코드를 보내기 버튼을 클릭하면 코드를 테스트하는 사용자 정의 함수를 실행할 수 있습니다.

function test1(p) {
    Log("Calls a custom function with parameters:", p);
    return p;
}

버튼을 클릭하세요:

img

img

당신은 로그 (Log) 를 볼 수 있습니다. "파라미터와 사용자 정의 함수를 호출: ", p); 함수 테스트1에서 문구가 실행되었습니다.

class: btn btn-xs btn-danger을 삽입하면 코드의 스타일이 버튼의 모양을 변경합니다.

img

당장 연습을 시작해!


더 많은