Quote context

Constructors

Methods

  • Returns the member ID

    Returns number

  • Returns the quote level

    Returns string

  • Set quote callback, after receiving the quote data push, it will call back to this function.

    Parameters

    Returns void

  • Set depth callback, after receiving the depth data push, it will call back to this function.

    Parameters

    Returns void

  • Set brokers callback, after receiving the brokers data push, it will call back to this function.

    Parameters

    Returns void

  • Set trades callback, after receiving the trades data push, it will call back to this function.

    Parameters

    Returns void

  • Set candlestick callback, after receiving the trades data push, it will call back to this function.

    Parameters

    Returns void

  • Subscribe

    const { Config, QuoteContext, SubType } = require("longport")

    let config = Config.fromEnv()
    QuoteContext.new(config)
    .then((ctx) => {
    ctx.setOnQuote((_, event) => console.log(event.toString()));
    ctx.subscribe(["700.HK", "AAPL.US"], [SubType.Quote], true);
    });

    Parameters

    • symbols: string[]
    • subTypes: SubType[]
    • isFirstPush: boolean

    Returns Promise<void>

  • Unsubscribe

    const { Config, QuoteContext, SubType } = require("longport")

    let config = Config.fromEnv()
    QuoteContext.new(config)
    .then((ctx) => {
    ctx.subscribe(["700.HK", "AAPL.US"], [SubType.Quote], true)
    .then(() => ctx.unsubscribe(["AAPL.US"], [SubType.Quote], true)))
    })

    Parameters

    • symbols: string[]
    • subTypes: SubType[]

    Returns Promise<void>

  • Subscribe security candlesticks

    Parameters

    Returns Promise<Candlestick[]>

  • Unsubscribe security candlesticks

    Parameters

    Returns Promise<void>

  • Get subscription information

    const { Config, QuoteContext, SubType } = require("longport")

    let config = Config.fromEnv();
    QuoteContext.new(config)
    .then((ctx) => {
    return ctx
    .subscribe(["700.HK", "AAPL.US"], [SubType.Quote], true)
    .then(() => ctx.subscriptions());
    })
    .then((resp) => console.log(resp.toString()));

    Returns Promise<Subscription[]>

  • Get basic information of securities

    const { Config, QuoteContext } = require("longport")

    let config = Config.fromEnv()
    QuoteContext.new(config)
    .then((ctx) => ctx.staticInfo(["700.HK", "AAPL.US", "TSLA.US", "NFLX.US"]))
    .then((resp) => {
    for (let obj of resp) {
    console.log(obj.toString())
    }
    })

    Parameters

    • symbols: string[]

    Returns Promise<SecurityStaticInfo[]>

  • Get quote of securities

    const { Config, QuoteContext } = require("longport")

    let config = Config.fromEnv()
    QuoteContext.new(config)
    .then((ctx) => ctx.quote(["700.HK", "AAPL.US", "TSLA.US", "NFLX.US"]))
    .then((resp) => {
    for (let obj of resp) {
    console.log(obj.toString())
    }
    })

    Parameters

    • symbols: string[]

    Returns Promise<SecurityQuote[]>

  • Get quote of option securities

    import { Config, QuoteContext } from 'longport'

    let config = Config.fromEnv()
    QuoteContext.new(config)
    .then((ctx) => ctx.optionQuote(["AAPL230317P160000.US"]))
    .then((resp) => {
    for (let obj of resp) {
    console.log(obj.toString())
    }
    })

    Parameters

    • symbols: string[]

    Returns Promise<OptionQuote[]>

  • Get quote of warrant securities

    const { Config, QuoteContext } = require("longport")

    let config = Config.fromEnv()
    QuoteContext.new(config)
    .then((ctx) => ctx.warrantQuote(["21125.HK"]))
    .then((resp) => {
    for (let obj of resp) {
    console.log(obj.toString())
    }
    })

    Parameters

    • symbols: string[]

    Returns Promise<WarrantQuote[]>

  • Get security depth

    const { Config, QuoteContext } = require("longport")

    let config = Config.fromEnv()
    QuoteContext.new(config)
    .then((ctx) => ctx.depth("700.HK"))
    .then((resp) => console.log(resp.toString()))

    Parameters

    • symbol: string

    Returns Promise<SecurityDepth>

  • Get security brokers

    const { Config, QuoteContext } = require("longport")

    let config = Config.fromEnv()
    QuoteContext.new(config)
    .then((ctx) => ctx.brokers("700.HK"))
    .then((resp) => console.log(resp.toString()))

    Parameters

    • symbol: string

    Returns Promise<SecurityBrokers>

  • Get participants

    const { Config, QuoteContext } = require("longport")

    let config = Config.fromEnv()
    QuoteContext.new(config)
    .then((ctx) => ctx.participants())
    .then((resp) => {
    for (let obj of resp) {
    console.log(obj.toString());
    }
    })

    Returns Promise<ParticipantInfo[]>

  • Get security trades

    const { Config, QuoteContext } = require("longport")

    let config = Config.fromEnv()
    QuoteContext.new(config)
    .then((ctx) => ctx.trades("700.HK", 10))
    .then((resp) => {
    for (let obj of resp) {
    console.log(obj.toString());
    }
    })

    Parameters

    • symbol: string
    • count: number

    Returns Promise<Trade[]>

  • Get security intraday

    const { Config, QuoteContext } = require("longport")

    let config = Config.fromEnv()
    QuoteContext.new(config)
    .then((ctx) => ctx.intraday("700.HK"))
    .then((resp) => {
    for (let obj of resp) {
    console.log(obj.toString());
    }
    })

    Parameters

    • symbol: string

    Returns Promise<IntradayLine[]>

  • Get security candlesticks

    const { Config, QuoteContext, Period, AdjustType } = require("longport")

    let config = Config.fromEnv()
    QuoteContext.new(config)
    .then((ctx) => ctx.candlesticks("700.HK", Period.Day, 10, AdjustType.NoAdjust))
    .then((resp) => {
    for (let obj of resp) {
    console.log(obj.toString());
    }
    })

    Parameters

    Returns Promise<Candlestick[]>

  • Get security history candlesticks by offset

    Parameters

    Returns Promise<Candlestick[]>

  • Get option chain expiry date list

    const { Config, QuoteContext } = require("longport")

    let config = Config.fromEnv()
    QuoteContext.new(config)
    .then((ctx) => ctx.optionChainExpiryDateList("AAPL.US"))
    .then((resp) => {
    for (let obj of resp) {
    console.log(obj.toString())
    }
    })

    Parameters

    • symbol: string

    Returns Promise<NaiveDate[]>

  • Get option chain info by date

    const { Config, QuoteContext, NaiveDate } = require("longport")

    let config = Config.fromEnv()
    QuoteContext.new(config)
    .then((ctx) => ctx.optionChainInfoByDate("AAPL.US", new NaiveDate(2023, 1, 20)))
    .then((resp) => {
    for (let obj of resp) {
    console.log(obj.toString())
    }
    })

    Parameters

    Returns Promise<StrikePriceInfo[]>

  • Get warrant issuers

    const { Config, QuoteContext, NaiveDate } = require("longport")

    let config = Config.fromEnv()
    QuoteContext.new(config)
    .then((ctx) => ctx.warrantIssuers())
    .then((resp) => {
    for (let obj of resp) {
    console.log(obj.toString())
    }
    })

    Returns Promise<IssuerInfo[]>

  • Query warrant list

    const { Config, QuoteContext, WarrantSortBy, SortOrderType } = require("longport")
    let config = Config.fromEnv()
    QuoteContext.new(config)
    .then((ctx) => ctx.warrantList("700.HK", WarrantSortBy.LastDone, SortOrderType.Asc))
    .then((resp) => {
    for (let obj of resp) {
    console.log(obj.toString())
    }
    })

    Parameters

    Returns Promise<WarrantInfo[]>

  • Get trading session of the day

    const { Config, QuoteContext, NaiveDate } = require("longport")

    let config = Config.fromEnv()
    QuoteContext.new(config)
    .then((ctx) => ctx.tradingSession())
    .then((resp) => {
    for (let obj of resp) {
    console.log(obj.toString())
    }
    })

    Returns Promise<MarketTradingSession[]>

  • Get trading session of the day

    const { Config, QuoteContext, Market, NaiveDate } = require("longport")

    let config = Config.fromEnv()
    QuoteContext.new(config)
    .then((ctx) => ctx.tradingDays(Market.HK, new NaiveDate(2022, 1, 20), new NaiveDate(2022, 2, 20)))
    .then((resp) => console.log(resp.toString()))

    Parameters

    Returns Promise<MarketTradingDays>

  • Get capital flow intraday

    const { Config, QuoteContext } = require("longport")

    let config = Config.fromEnv()
    QuoteContext.new(config)
    .then((ctx) => ctx.capitalFlow("700.HK"))
    .then((resp) => {
    for (let obj of resp) {
    console.log(obj.toString())
    }
    })

    Parameters

    • symbol: string

    Returns Promise<CapitalFlowLine[]>

  • Get capital distribution

    const { Config, QuoteContext } = require("longport")

    let config = Config.fromEnv()
    QuoteContext.new(config)
    .then((ctx) => ctx.capitalDistribution("700.HK"))
    .then((resp) => console.log(resp.toString()))

    Parameters

    • symbol: string

    Returns Promise<CapitalDistributionResponse>

  • Get watchlist

    const { Config, QuoteContext } = require("longport")

    let config = Config.fromEnv()
    QuoteContext.new(config)
    .then((ctx) => ctx.watchList())
    .then((resp) => console.log(resp.toString()))

    Returns Promise<WatchlistGroup[]>

  • Create watchlist group

    const { Config, QuoteContext } = require("longport")

    let config = Config.fromEnv();
    QuoteContext.new(config)
    .then((ctx) => {
    ctx.createWatchlistGroup({
    name: "Watchlist1",
    securities: ["700.HK", "BABA.US"],
    })
    .then((group_id) => console.log(group_id));

    Parameters

    Returns Promise<number>

  • Delete watchlist group

    const { Config, QuoteContext } = require("longport")
    let config = Config.fromEnv();
    QuoteContext.new(config)
    .then(ctx => ctx.deleteWatchlistGroup({ id: 10086 });

    Parameters

    Returns Promise<void>

  • Update watchlist group

    const { Config, QuoteContext } = require("longport")
    let config = Config.fromEnv();
    QuoteContext.new(config)
    .then(ctx => ctx.updateWatchlistGroup({
    id: 10086,
    name: "Watchlist2",
    securities: ["700.HK", "BABA.US"],
    });

    Parameters

    Returns Promise<void>

  • Get security list

    const { Config, QuoteContext, Market, SecurityListCategory } = require("longport")

    let config = Config.fromEnv();
    QuoteContext.new(config)
    .then((ctx) => ctx.securityList(Market.US, SecurityListCategory.Overnight))
    .then((resp) => console.log(resp.toString()));

    Parameters

    Returns Promise<Security[]>

  • Get real-time quote

    const { Config, QuoteContext, SubType } = require("longport")

    let config = Config.fromEnv();
    QuoteContext.new(config).then((ctx) => {
    ctx.subscribe(["700.HK", "AAPL.US"], [SubType.Quote], true).then(() => {
    setTimeout(() => {
    ctx.realtimeQuote(["700.HK", "AAPL.US"]).then((resp) => {
    for (let obj of resp) {
    console.log(obj.toString());
    }
    });
    }, 5000);
    });
    });

    Parameters

    • symbols: string[]

    Returns Promise<RealtimeQuote[]>

  • Get real-time depth

    const { Config, QuoteContext, SubType } = require("longport")

    let config = Config.fromEnv();
    QuoteContext.new(config).then((ctx) => {
    ctx.subscribe(["700.HK", "AAPL.US"], [SubType.Depth], true);
    setTimeout(
    () =>
    ctx.realtimeDepth("700.HK").then((resp) => console.log(resp.toString())),
    5000
    );
    });

    Parameters

    • symbol: string

    Returns Promise<SecurityDepth>

  • Get real-time brokers

    const { Config, QuoteContext, NaiveDate, SubType } = require("longport")

    let config = Config.fromEnv();
    QuoteContext.new(config).then((ctx) => {
    ctx.subscribe(["700.HK", "AAPL.US"], [SubType.Brokers], true).then(() => {
    setTimeout(
    () =>
    ctx
    .realtimeBrokers("700.HK")
    .then((resp) => console.log(resp.toString())),
    5000
    );
    });
    });

    Parameters

    • symbol: string

    Returns Promise<SecurityBrokers>

  • Get real-time trades

    const { Config, QuoteContext, SubType } = require("longport")

    let config = Config.fromEnv();
    QuoteContext.new(config).then((ctx) => {
    ctx.subscribe(["700.HK", "AAPL.US"], [SubType.Trade], false).then(() => {
    setTimeout(() => {
    ctx.realtimeTrades("700.HK", 10).then((resp) => {
    for (let obj of resp) {
    console.log(obj.toString());
    }
    });
    }, 5000);
    });
    });

    Parameters

    • symbol: string
    • count: number

    Returns Promise<Trade[]>

  • Get real-time candlesticks

    const { Config, QuoteContext, Period } = require("longport")

    let config = Config.fromEnv();
    QuoteContext.new(config).then((ctx) => {
    ctx.subscribeCandlesticks("700.HK", Period.Min_1).then(() => {
    setTimeout(() => {
    ctx.realtimeCandlesticks("700.HK", Period.Min_1, 10).then((resp) => {
    for (let obj of resp) {
    console.log(obj.toString());
    }
    });
    }, 5000);
    });
    });

    Parameters

    • symbol: string
    • period: Period
    • count: number

    Returns Promise<Candlestick[]>