Quote context

Constructors

Methods

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

    Parameters

    • callback: ((err, event) => void)
        • (err, event): void
        • Parameters

          Returns void

    Returns void

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

    Parameters

    • callback: ((err, event) => void)
        • (err, event): void
        • Parameters

          Returns void

    Returns void

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

    Parameters

    • callback: ((err, event) => void)

    Returns void

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

    Parameters

    • callback: ((err, event) => void)

    Returns void

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

    Parameters

    • callback: ((err, event) => void)

    Returns void

  • Subscribe

    Example

    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

    Example

    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<void>

  • Unsubscribe security candlesticks

    Parameters

    Returns Promise<void>

  • Get subscription information

    Example

    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

    Example

    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

    Example

    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

    Example

    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

    Example

    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

    Example

    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

    Example

    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

    Example

    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

    Example

    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

    Example

    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

    Example

    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

    Example

    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

    Example

    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

    Example

    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

    Example

    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

    Example

    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

    Example

    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

    Example

    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

    Example

    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

    Example

    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

    Example

    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

    Example

    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

    Example

    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

    Example

    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

    Example

    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

    Example

    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

    Example

    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

    Example

    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

    Example

    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[]>