디지털 화폐 스팟에 대한 새로운 주식 전략 (교습)

저자:리디아, 창작: 2022-11-08 17:02:28, 업데이트: 2023-09-20 10:31:51

img

지난 며칠 동안, 나는 텔레그램 그룹 사용자로부터 몇 가지 개인 메시지를 받았습니다, 그들은 참조를 위해 새로운 주식 전략을 구독하는 디자인 예를 가지고 있기를 바랍니다. 때때로, 그들은 거래소가 새로운 통화를 착륙 할 때 새로운 주식을 구독하고 싶어, 그래서이 기사에서, 우리는 새로운 주식을 구독하기위한 간단한 도구 전략을 설계 할 것입니다.

전략적 필요성

예를 들어, 현재, 거래소 및 거래 쌍: XXX_USDT는 아직 거래소에 상장되지 않았습니다. 그러나 곧 상장 될 것입니다. 우리는 이 거래소의 XXX_USDT 시장을 프로그램으로 따라야합니다. 거래 쌍이 상장되면 거래 될 수 있습니다. 우리는 10 개의 제한 가격 구매 주문을 발행하고 금액을 지정하고 새로운 통화를 구독하는 주문을 나열합니다. 그것들을 성공적으로 구입할 수 있다면 작업을 완료 할 수 있습니다. 그렇지 않으면 모든 주문이 종료 될 때까지 목록을 나열 할 수 있으며 통화를 구입할 수 있습니다.

필요성은 매우 간단하지만 디지털 통화 시장에 대한 프로그래밍 기초가 없는 사람들은 시작할 수 없을 수도 있습니다.

전략 코드

전략 파라미터 정의:

여기서 우리는 주문을 하는 것과 같은 작업을 제어하기 위해 이 7개의 매개 변수를 정의합니다.

img

코드 실행:

function pendingOrders(ordersNum, price, amount, deltaPrice, deltaAmount) {
    var routineOrders = []
    var ordersIDs = []
    for (var i = 0 ; i < ordersNum ; i++) {
        var routine = exchange.Go("Buy", price + i * deltaPrice, amount + i * deltaAmount)
        routineOrders.push(routine)
        Sleep(ApiReqInterval)        
    }
    for (var i = 0 ; i < routineOrders.length ; i++) {
        var orderId = routineOrders[i].wait()
        if (orderId) {
            ordersIDs.push(orderId)
            Log("placed an order successfully", orderId)
        }        
    }
    return ordersIDs
}

function main() {
    if (symbol == "null" || pendingPrice == -1 || pendingAmount == -1 || pendingPrice == -1 || deltaPrice == -1 || deltaAmount == -1) {
        throw "Parameter setting error"
    }
    exchange.SetCurrency(symbol)
    // Block error messages
    SetErrorFilter("GetDepth")
    while (true) {
        var msg = ""
        var depth = exchange.GetDepth()
        if (!depth || (depth.Bids.length == 0 && depth.Asks.length == 0)) {
            // No depth
            msg = "No depth data, wait!"
            Sleep(500)
        } else {
            // Obtain depth
            Log("Place orders concurrently!")
            var ordersIDs = pendingOrders(ordersNum, pendingPrice, pendingAmount, deltaPrice, deltaAmount)
            while (true) {
                var orders = _C(exchange.GetOrders)
                if (orders.length == 0) {
                    Log("The current number of pending orders is 0, and the operation is stopped")
                    return 
                }
                var tbl = {
                    type: "table",
                    title: "The current pending orders",
                    cols: ["id", "price", "amount"], 
                    rows: []
                }
                _.each(orders, function(order) {
                    tbl.rows.push([order.Id, order.Price, order.Amount])
                })
                LogStatus(_D(), "\n`" + JSON.stringify(tbl) + "`")
                Sleep(500)
            }
        }
        LogStatus(_D(), msg)
    }
}

전략은 교환 API와 주문록 인터페이스를 검사합니다. 주문록 데이터를 얻을 수있을 때, 전략은 동시에 주문을 배치하기 위해 exchange.Go 기능을 사용합니다. 주문이 배치 된 후, 현재 미뤄진 주문의 상태는 순환적으로 확인됩니다. 전략은 실제로 테스트되지 않았습니다. 여기 코드 디자인 참조 만입니다. 관심이 있다면 기능을 수정하거나 추가 할 수 있습니다.

전체 전략은:https://www.fmz.com/strategy/358383


관련

더 많은