Longbridge Developers
立即開始

修改訂單

該接口用於修改訂單的價格,數量。

>_ CLI
# 將下方訂單 ID 替換為實際的訂單 ID
longbridge order replace 693664675163312128 --qty 200 --price 255.00

Request

HTTP MethodPUT
HTTP URL/v1/trade/order

Parameters

Content-Type: application/json; charset=utf-8

NameTypeRequiredDescription
order_idstringYES訂單 ID
quantitystringYES改單數量,例如:200
pricestringNO改單價格,例如:388.5

LO / ELO / ALO / ODD / LIT 訂單必填
trigger_pricestringNO觸發價格,例如:388.5

LIT / MIT 訂單必填
limit_offsetstringNO指定價差

TSLPAMT / TSLPPCT 訂單在 limit_depth_level 為 0 時必填
trailing_amountstringNO跟蹤金額

TSLPAMT 訂單必填
trailing_percentstringNO跟蹤漲跌幅

TSLPPCT 訂單必填
remarkstringNO備註 (最大 64 字符)
limit_depth_levelint32NO指定買賣檔位,TSLPAMT / TSLPPCT 訂單必填
monitor_pricestringNO監控價格,TSLPAMT / TSLPPCT 訂單必填
trigger_countint32NO觸發次數,LIT / MIT / TSLPAMT / TSLPPCT 訂單必填
attached_paramsobjectNO附加單參數(止盈止損)
attached_params.attached_order_typestringNO附加單訂單類型

可選值:
PROFIT_TAKER - 止盈
STOP_LOSS - 止損
BRACKET - 括號單
attached_params.profit_taker_pricestringNO止盈觸發價格
attached_params.stop_loss_pricestringNO止損觸發價格
attached_params.time_in_forcestringNO附加單有效期類型

可選值:
Day - 當日有效
GTC - 撤單前有效
GTD - 到期前有效(此時繼承主單 expire_date)
attached_params.expire_timeint64NO到期時間(Unix 時間戳,單位秒)
attached_params.profit_taker_idint64NO止盈單 ID,修改現有止盈單時填寫
attached_params.stop_loss_idint64NO止損單 ID,修改現有止損單時填寫
attached_params.cancel_all_attachedboolNO是否取消所有附加單
attached_params.main_idint64NO主單 ID
attached_params.quantitystringNO附加單數量
attached_params.market_pricestringNO市價
attached_params.activate_order_typestringNO觸發後提交的訂單類型,例如 LIT(限價單)或 MIT(市價單)
attached_params.profit_taker_submit_pricestringNO止盈限價委託價格,activate_order_typeLIT 時必填
attached_params.stop_loss_submit_pricestringNO止損限價委託價格,activate_order_typeLIT 時必填
attached_params.activate_rthstringNO觸發後提交的訂單是否允許盤前盤後

可選值:
RTH_ONLY - 不允許盤前盤後
ANY_TIME - 允許盤前盤後

Request Example

from decimal import Decimal
from longbridge.openapi import TradeContext, Config, OAuthBuilder

oauth = OAuthBuilder("your-client-id").build(lambda url: print("Visit:", url))
config = Config.from_oauth(oauth)
ctx = TradeContext(config)

ctx.replace_order(
    order_id = "709043056541253632",
    quantity = Decimal(100),
    price = Decimal(50),
)
import asyncio
from decimal import Decimal
from longbridge.openapi import AsyncTradeContext, Config, OAuthBuilder

async def main() -> None:
    oauth = await OAuthBuilder("your-client-id").build_async(lambda url: print("Visit:", url))
    config = Config.from_oauth(oauth)
    ctx = AsyncTradeContext.create(config)

    ctx.replace_order(
        order_id = "709043056541253632",
        quantity = Decimal(100),
        price = Decimal(50),
    )

if __name__ == "__main__":
    asyncio.run(main())
const { Config, TradeContext, OAuth, Decimal } = require('longbridge')

async function main() {
  const oauth = await OAuth.build("your-client-id", (_, url) => { console.log("Open this URL to authorize: " + url) })
  const config = Config.fromOAuth(oauth)
  const ctx = TradeContext.new(config)
  await ctx.replaceOrder({ orderId: "701276261045858304", quantity: new Decimal(400), price: new Decimal(60) })
  console.log("replaced")
}
main().catch(console.error)
import com.longbridge.*;
import com.longbridge.trade.*;
import java.math.BigDecimal;
class Main {
    public static void main(String[] args) throws Exception {
        try (OAuth oauth = new OAuthBuilder("your-client-id").build(url -> System.out.println("Open to authorize: " + url)).get();
             Config config = Config.fromOAuth(oauth);
             TradeContext ctx = TradeContext.create(config)) {
            ctx.replaceOrder(new ReplaceOrderOptions("701276261045858304", new BigDecimal("400")).setPrice(new BigDecimal("60"))).get();
            System.out.println("replaced");
        }
    }
}
use std::sync::Arc;
use longbridge::{oauth::OAuthBuilder, trade::{TradeContext, ReplaceOrderOptions}, Config};
use rust_decimal::Decimal;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let oauth = OAuthBuilder::new("your-client-id").build(|url| println!("Open this URL to authorize: {url}")).await?;
    let config = Arc::new(Config::from_oauth(oauth));
    let (ctx, _) = TradeContext::new(config);
    ctx.replace_order(
        ReplaceOrderOptions::new("701276261045858304", Decimal::from(400))
            .price(Decimal::from(60))
    ).await?;
    println!("replaced");
    Ok(())
}
#include &lt;iostream&gt;
#include <longbridge.hpp>

#ifdef WIN32
#include <windows.h>
#endif

using namespace longbridge;
using namespace longbridge::trade;

static void
run(const OAuth& oauth)
{
    Config config = Config::from_oauth(oauth);
    TradeContext ctx = TradeContext::create(config);

    ReplaceOrderOptions opts{"701276261045858304", 400, Decimal(60.0)};
    ctx.replace_order(opts, [](auto res) {
        if (!res) { std::cout << "failed" << std::endl; return; }
        std::cout << "replaced" << std::endl;
    });
}

int main(int argc, char const* argv[]) {
#ifdef WIN32
    SetConsoleOutputCP(CP_UTF8);
#endif

    const std::string client_id = "your-client-id";
    OAuthBuilder(client_id).build(
    [](const std::string& url) {
        std::cout << "Open this URL to authorize: " << url << std::endl;
    },
    [](auto res) {
        if (!res) {
            std::cout << "authorization failed: " << *res.status().message() << std::endl;
            return;
        }
        run(*res);
    });

    std::cin.get();
    return 0;
}
package main

import (
	"context"
	"fmt"
	"log"

	"github.com/longbridge/openapi-go/config"
	"github.com/longbridge/openapi-go/oauth"
	"github.com/longbridge/openapi-go/trade"
	"github.com/shopspring/decimal"
)

func main() {
	o := oauth.New("your-client-id").
		OnOpenURL(func(url string) { fmt.Println("Open this URL to authorize:", url) })
	if err := o.Build(context.Background()); err != nil {
		log.Fatal(err)
	}
	conf, err := config.New(config.WithOAuthClient(o))
	if err != nil {
		log.Fatal(err)
	}
	tctx, err := trade.NewFromCfg(conf)
	if err != nil {
		log.Fatal(err)
	}
	defer tctx.Close()
	err = tctx.ReplaceOrder(context.Background(), &trade.ReplaceOrder{
		OrderId:  "701276261045858304",
		Quantity: 400,
		Price:    decimal.NewFromFloat(60),
	})
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println("replaced")
}

Response

Response Headers

  • Content-Type: application/json

Response Example

{
  "code": 0,
  "message": "success",
  "data": {}
}

Response Status

StatusDescriptionSchema
200提交成功,訂單已委托。None
400下單被拒絕,請求參數錯誤。None