Skip to content

Commit

Permalink
feat(data-model): ITick add fields about interest rate (#427)
Browse files Browse the repository at this point in the history
  • Loading branch information
zccz14 authored Feb 10, 2024
1 parent e5627bd commit c262b2b
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 24 deletions.
10 changes: 10 additions & 0 deletions common/changes/@yuants/data-model/2024-02-10-21-18.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@yuants/data-model",
"comment": "add fields of ITick about interest rate",
"type": "minor"
}
],
"packageName": "@yuants/data-model"
}
10 changes: 10 additions & 0 deletions common/changes/@yuants/kernel/2024-02-10-21-18.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@yuants/kernel",
"comment": "refactor for data-model",
"type": "patch"
}
],
"packageName": "@yuants/kernel"
}
11 changes: 6 additions & 5 deletions libraries/data-model/etc/data-model.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,14 +178,15 @@ export interface ITick {
ask?: number;
bid?: number;
datasource_id: string;
interest_rate_for_long?: number;
interest_rate_for_short?: number;
open_interest?: number;
price: number;
price?: number;
product_id: string;
settlement_scheduled_at?: number;
spread?: number;
// @deprecated
timestamp_in_us: number;
updated_at?: number;
volume: number;
updated_at: number;
volume?: number;
}

// @public
Expand Down
36 changes: 25 additions & 11 deletions libraries/data-model/src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -849,8 +849,8 @@ export interface IDataRecord<T = unknown> {
origin: T;
}
/**
* Tick: Market transaction data at a certain moment
* Tick: 某个时刻的市场成交行情数据
* Tick: Market data at a certain moment
* Tick: 某个时刻的市场数据
* @public
*/

Expand All @@ -865,27 +865,21 @@ export interface ITick {
* 品种 ID
*/
product_id: string;
/**
* Timestamp (in microseconds)
* 时间戳
* @deprecated use updated_at instead
*/
timestamp_in_us: number;
/**
* Timestamp (in ms)
* 时间戳
*/
updated_at?: number;
updated_at: number;
/**
* Price
* 成交价
*/
price: number;
price?: number;
/**
* Volume
* 成交量
*/
volume: number;
volume?: number;
/**
* Open interest
* 持仓量
Expand All @@ -903,4 +897,24 @@ export interface ITick {
ask?: number;
/** 买一价 */
bid?: number;
/**
* Next timestamp for settlement
*/
settlement_scheduled_at?: number;
/**
* Current Interest Rate if you hold long position
*
* You will get the interest (rate * volume) when the next settlement.
*
* The rate is based on the volume (not the position value) of the position.
*/
interest_rate_for_long?: number;
/**
* Current Interest Rate if you hold short position
*
* You will get the interest (rate * volume) when the next settlement.
*
* The rate is based on the volume (not the position value) of the position.
*/
interest_rate_for_short?: number;
}
2 changes: 1 addition & 1 deletion libraries/kernel/etc/kernel.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -784,7 +784,7 @@ export class TickDataUnit extends BasicUnit {

// Warnings were encountered during analysis:
//
// src/units/OrderMatchingUnit.ts:269:11 - (ae-forgotten-export) The symbol "IMatchingRange" needs to be exported by the entry point index.d.ts
// src/units/OrderMatchingUnit.ts:270:11 - (ae-forgotten-export) The symbol "IMatchingRange" needs to be exported by the entry point index.d.ts

// (No @packageDocumentation comment for this package)

Expand Down
5 changes: 3 additions & 2 deletions libraries/kernel/src/units/OrderMatchingUnit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,9 @@ export class OrderMatchingUnit extends BasicUnit {
}

private updateRangeByTick(tick: ITick): void {
const ask = tick.ask || tick.price;
const bid = tick.bid || tick.price;
const ask = tick.ask;
const bid = tick.bid;
if (!ask || !bid) return;
this.mapProductIdToRange.set(encodePath(tick.datasource_id, tick.product_id), {
ask: {
first: ask,
Expand Down
6 changes: 3 additions & 3 deletions libraries/kernel/src/units/RealtimeTickLoadingUnit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ export class RealtimeTickLoadingUnit extends BasicUnit {

onEvent(): void | Promise<void> {
const tick = this.mapEventIdToTick.get(this.kernel.currentEventId);
if (tick) {
if (tick && tick.ask && tick.bid) {
this.quoteDataUnit.mapProductIdToQuote[tick.product_id] = {
ask: tick.ask || tick.price,
bid: tick.bid || tick.price,
ask: tick.ask,
bid: tick.bid,
};

this.tickDataUnit.setTick(tick);
Expand Down
4 changes: 2 additions & 2 deletions ui/web/src/modules/Fund/RealtimeAsset.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ const fromConfig = (config: IFundConfig): Observable<IFundInfo> => {
mergeMap((item) =>
useTick(item.datasource_id, item.product_id).pipe(
map((tick) => ({
[`${item.base_currency}${item.quoted_currency}`]: tick.price,
[`${item.quoted_currency}${item.base_currency}`]: 1 / tick.price,
[`${item.base_currency}${item.quoted_currency}`]: tick.price!,
[`${item.quoted_currency}${item.base_currency}`]: 1 / tick.price!,
})),
),
),
Expand Down

0 comments on commit c262b2b

Please sign in to comment.