@yuants/agent
Advanced tools
Comparing version 0.0.5 to 0.1.0
@@ -149,2 +149,4 @@ import { AccountPerformanceUnit } from '@yuants/kernel'; | ||
as_counterparty?: boolean; | ||
/** Position Limit (Maximum Position) */ | ||
position_limit?: number; | ||
} | ||
@@ -151,0 +153,0 @@ |
@@ -1,2 +0,2 @@ | ||
import { AccountPerformanceMetricsUnit, AccountPerformanceUnit, AccountSimulatorUnit, BasicUnit, CounterpartyOrderMappingUnit, DataLoadingTaskUnit, HistoryOrderUnit, HistoryPeriodLoadingUnit, Kernel, KernelFramesMetricsUnit, OrderMatchingUnit, PeriodDataCheckingUnit, PeriodDataUnit, PeriodMetricsUnit, PortfolioSimulatorUnit, ProductDataUnit, ProductLoadingUnit, QuoteDataUnit, QuoteMetricsUnit, RealtimePeriodLoadingUnit, SeriesDataUnit, StopLossOrderMapperUnit, createEmptyAccountInfo, } from '@yuants/kernel'; | ||
import { AccountPerformanceMetricsUnit, AccountPerformanceUnit, AccountSimulatorUnit, BasicUnit, CounterpartyOrderMappingUnit, DataLoadingTaskUnit, HistoryOrderUnit, HistoryPeriodLoadingUnit, Kernel, KernelFramesMetricsUnit, OrderMatchingUnit, PeriodDataCheckingUnit, PeriodDataUnit, PeriodMetricsUnit, PortfolioSimulatorUnit, PositionLimitOrderMappingUnit, ProductDataUnit, ProductLoadingUnit, QuoteDataUnit, QuoteMetricsUnit, RealtimePeriodLoadingUnit, SeriesDataUnit, StopLossOrderMapperUnit, createEmptyAccountInfo, } from '@yuants/kernel'; | ||
import { Subject } from 'rxjs'; | ||
@@ -91,2 +91,6 @@ import { v4 } from 'uuid'; | ||
}, | ||
position_limit: { | ||
type: 'number', | ||
title: '仓位限制', | ||
}, | ||
}, | ||
@@ -165,2 +169,13 @@ }; | ||
}); | ||
let positionLimitAccountInfoUnit; | ||
let positionLimitAccountPerformanceUnit; | ||
let positionLimitOrderMatchingUnit; | ||
let positionLimitHistoryOrderUnit; | ||
if (agentConf.position_limit) { | ||
positionLimitHistoryOrderUnit = new HistoryOrderUnit(kernel, quoteDataUnit, productDataUnit); | ||
positionLimitOrderMatchingUnit = new OrderMatchingUnit(kernel, productDataUnit, periodDataUnit, positionLimitHistoryOrderUnit); | ||
positionLimitAccountInfoUnit = new AccountSimulatorUnit(kernel, productDataUnit, quoteDataUnit, positionLimitHistoryOrderUnit, createEmptyAccountInfo(`${resolved_account_id}-PL`, resolved_currency, agentConf.leverage, agentConf.initial_balance)); | ||
const positionLimitUnit = new PositionLimitOrderMappingUnit(kernel, agentConf.position_limit, originOrderMatchingUnit, positionLimitOrderMatchingUnit, positionLimitAccountInfoUnit); | ||
positionLimitAccountPerformanceUnit = new AccountPerformanceUnit(kernel, positionLimitAccountInfoUnit); | ||
} | ||
let counterpartyAccountInfoUnit; | ||
@@ -172,3 +187,3 @@ let counterpartyAccountPerformanceUnit; | ||
const counterpartyOrderMatchingUnit = new OrderMatchingUnit(kernel, productDataUnit, periodDataUnit, counterpartyHistoryOrderUnit); | ||
const counterpartyUnit = new CounterpartyOrderMappingUnit(kernel, originOrderMatchingUnit, counterpartyOrderMatchingUnit); | ||
const counterpartyUnit = new CounterpartyOrderMappingUnit(kernel, positionLimitOrderMatchingUnit || originOrderMatchingUnit, counterpartyOrderMatchingUnit); | ||
const counterpartyAccountInfo = createEmptyAccountInfo(`${resolved_account_id}-CP`, resolved_currency, agentConf.leverage, agentConf.initial_balance); | ||
@@ -255,5 +270,8 @@ counterpartyAccountInfoUnit = new AccountSimulatorUnit(kernel, productDataUnit, quoteDataUnit, counterpartyHistoryOrderUnit, counterpartyAccountInfo); | ||
await agentUnit.execute(); | ||
// these lines of code implies that there is a certain priority of units, | ||
// maybe we should make it more explicit. | ||
const accountInfoUnit = portfolioAccountInfoUnit || | ||
stopLossAccountInfoUnit || | ||
counterpartyAccountInfoUnit || | ||
positionLimitAccountInfoUnit || | ||
originAccountInfoUnit; | ||
@@ -263,2 +281,3 @@ const accountPerformanceUnit = portfolioAccountPerformanceUnit || | ||
counterpartyAccountPerformanceUnit || | ||
positionLimitAccountPerformanceUnit || | ||
originAccountPerformanceUnit; | ||
@@ -268,2 +287,3 @@ const historyOrderUnit = portfolioHistoryOrderUnit || | ||
counterpartyHistoryOrderUnit || | ||
positionLimitHistoryOrderUnit || | ||
originHistoryOrderUnit; | ||
@@ -270,0 +290,0 @@ return { |
@@ -45,3 +45,6 @@ import { AccountSimulatorUnit, BasicUnit, DataLoadingTaskUnit, OrderMatchingUnit, PeriodDataUnit, ProductDataUnit, ProductLoadingUnit, SeriesDataUnit, } from '@yuants/kernel'; | ||
function makeScriptRunner(script) { | ||
const globalContext = { | ||
const globalContext = Object.assign(Object.assign({ | ||
// Issue: block access to globalThis and its properties for security | ||
globalThis: {} }, Object.fromEntries(Object.keys(globalThis).map((key) => [key, undefined]))), { | ||
// Supply some global variables | ||
PositionVariant, | ||
@@ -67,4 +70,3 @@ OrderDirection, | ||
useSeries, | ||
useState, | ||
}; | ||
useState }); | ||
const x = Object.entries(globalContext); | ||
@@ -71,0 +73,0 @@ const module = new Function(...x.map((x) => x[0]), `return ${script}`)(...x.map((x) => x[1])); |
@@ -46,3 +46,3 @@ import { useAgent, useEffect, useMemo, useSeries } from '.'; | ||
if (period) { | ||
time[idx] = period.timestamp_in_us; | ||
time[idx] = period.timestamp_in_us / 1000; | ||
open[idx] = period.open; | ||
@@ -49,0 +49,0 @@ high[idx] = period.high; |
@@ -45,2 +45,4 @@ import { AccountPerformanceUnit, AccountSimulatorUnit, HistoryOrderUnit, Kernel, PeriodDataUnit, ProductDataUnit, QuoteDataUnit } from '@yuants/kernel'; | ||
as_counterparty?: boolean; | ||
/** Position Limit (Maximum Position) */ | ||
position_limit?: number; | ||
} | ||
@@ -47,0 +49,0 @@ /** |
@@ -94,2 +94,6 @@ "use strict"; | ||
}, | ||
position_limit: { | ||
type: 'number', | ||
title: '仓位限制', | ||
}, | ||
}, | ||
@@ -168,2 +172,13 @@ }; | ||
}); | ||
let positionLimitAccountInfoUnit; | ||
let positionLimitAccountPerformanceUnit; | ||
let positionLimitOrderMatchingUnit; | ||
let positionLimitHistoryOrderUnit; | ||
if (agentConf.position_limit) { | ||
positionLimitHistoryOrderUnit = new kernel_1.HistoryOrderUnit(kernel, quoteDataUnit, productDataUnit); | ||
positionLimitOrderMatchingUnit = new kernel_1.OrderMatchingUnit(kernel, productDataUnit, periodDataUnit, positionLimitHistoryOrderUnit); | ||
positionLimitAccountInfoUnit = new kernel_1.AccountSimulatorUnit(kernel, productDataUnit, quoteDataUnit, positionLimitHistoryOrderUnit, (0, kernel_1.createEmptyAccountInfo)(`${resolved_account_id}-PL`, resolved_currency, agentConf.leverage, agentConf.initial_balance)); | ||
const positionLimitUnit = new kernel_1.PositionLimitOrderMappingUnit(kernel, agentConf.position_limit, originOrderMatchingUnit, positionLimitOrderMatchingUnit, positionLimitAccountInfoUnit); | ||
positionLimitAccountPerformanceUnit = new kernel_1.AccountPerformanceUnit(kernel, positionLimitAccountInfoUnit); | ||
} | ||
let counterpartyAccountInfoUnit; | ||
@@ -175,3 +190,3 @@ let counterpartyAccountPerformanceUnit; | ||
const counterpartyOrderMatchingUnit = new kernel_1.OrderMatchingUnit(kernel, productDataUnit, periodDataUnit, counterpartyHistoryOrderUnit); | ||
const counterpartyUnit = new kernel_1.CounterpartyOrderMappingUnit(kernel, originOrderMatchingUnit, counterpartyOrderMatchingUnit); | ||
const counterpartyUnit = new kernel_1.CounterpartyOrderMappingUnit(kernel, positionLimitOrderMatchingUnit || originOrderMatchingUnit, counterpartyOrderMatchingUnit); | ||
const counterpartyAccountInfo = (0, kernel_1.createEmptyAccountInfo)(`${resolved_account_id}-CP`, resolved_currency, agentConf.leverage, agentConf.initial_balance); | ||
@@ -258,5 +273,8 @@ counterpartyAccountInfoUnit = new kernel_1.AccountSimulatorUnit(kernel, productDataUnit, quoteDataUnit, counterpartyHistoryOrderUnit, counterpartyAccountInfo); | ||
await agentUnit.execute(); | ||
// these lines of code implies that there is a certain priority of units, | ||
// maybe we should make it more explicit. | ||
const accountInfoUnit = portfolioAccountInfoUnit || | ||
stopLossAccountInfoUnit || | ||
counterpartyAccountInfoUnit || | ||
positionLimitAccountInfoUnit || | ||
originAccountInfoUnit; | ||
@@ -266,2 +284,3 @@ const accountPerformanceUnit = portfolioAccountPerformanceUnit || | ||
counterpartyAccountPerformanceUnit || | ||
positionLimitAccountPerformanceUnit || | ||
originAccountPerformanceUnit; | ||
@@ -271,2 +290,3 @@ const historyOrderUnit = portfolioHistoryOrderUnit || | ||
counterpartyHistoryOrderUnit || | ||
positionLimitHistoryOrderUnit || | ||
originHistoryOrderUnit; | ||
@@ -273,0 +293,0 @@ return { |
@@ -49,3 +49,6 @@ "use strict"; | ||
function makeScriptRunner(script) { | ||
const globalContext = { | ||
const globalContext = Object.assign(Object.assign({ | ||
// Issue: block access to globalThis and its properties for security | ||
globalThis: {} }, Object.fromEntries(Object.keys(globalThis).map((key) => [key, undefined]))), { | ||
// Supply some global variables | ||
PositionVariant: protocol_1.PositionVariant, | ||
@@ -71,4 +74,3 @@ OrderDirection: protocol_1.OrderDirection, | ||
useSeries: hooks_1.useSeries, | ||
useState: hooks_1.useState, | ||
}; | ||
useState: hooks_1.useState }); | ||
const x = Object.entries(globalContext); | ||
@@ -75,0 +77,0 @@ const module = new Function(...x.map((x) => x[0]), `return ${script}`)(...x.map((x) => x[1])); |
@@ -49,3 +49,3 @@ "use strict"; | ||
if (period) { | ||
time[idx] = period.timestamp_in_us; | ||
time[idx] = period.timestamp_in_us / 1000; | ||
open[idx] = period.open; | ||
@@ -52,0 +52,0 @@ high[idx] = period.high; |
{ | ||
"name": "@yuants/agent", | ||
"version": "0.0.5", | ||
"version": "0.1.0", | ||
"main": "lib/index.js", | ||
@@ -28,3 +28,3 @@ "module": "dist/index.js", | ||
"dependencies": { | ||
"@yuants/kernel": "0.0.5", | ||
"@yuants/kernel": "0.1.0", | ||
"@yuants/protocol": "0.1.3", | ||
@@ -31,0 +31,0 @@ "@yuants/utils": "0.0.2", |
@@ -124,2 +124,3 @@ ## API Report File for "@yuants/agent" | ||
period_self_check_interval_in_second?: number; | ||
position_limit?: number; | ||
publish_account?: boolean; | ||
@@ -126,0 +127,0 @@ resume_on_source_margin_below?: number; |
{ | ||
"libraries/agent/CHANGELOG.json": "4fa81d82d1a8c8d8fad0a7f9928d206b0a1425f9", | ||
"libraries/agent/CHANGELOG.md": "afbacc6c666e7ebc9bd486806817b62278fafa63", | ||
"libraries/agent/CHANGELOG.json": "2307591448776fd15cbb79192763990a2789462f", | ||
"libraries/agent/CHANGELOG.md": "670a9a9e6c10d877a574196bd27bcb3ad07e591c", | ||
"libraries/agent/api-extractor.json": "62f4fd324425b9a235f0c117975967aab09ced0c", | ||
@@ -8,6 +8,6 @@ "libraries/agent/config/jest.config.json": "4bb17bde3ee911163a3edb36a6eb71491d80b1bd", | ||
"libraries/agent/config/typescript.json": "854907e8a821f2050f6533368db160c649c25348", | ||
"libraries/agent/etc/agent.api.md": "34068167ed162f897ae58ceb60712575a3194185", | ||
"libraries/agent/package.json": "3008baaef42a16b25fc57fa8eb3f6e5db7e604f5", | ||
"libraries/agent/src/AgentScene.ts": "75908242143da35f53910c8f03a32fbb7304f368", | ||
"libraries/agent/src/AgentUnit.ts": "932607bb208e8969c8d82e0cb76de3ed5c9fe263", | ||
"libraries/agent/etc/agent.api.md": "164d4430a184b7c17268ac17a4e11972009fbc33", | ||
"libraries/agent/package.json": "c3f26c8dc1aa31fb947c9b8477e10abe05e16902", | ||
"libraries/agent/src/AgentScene.ts": "c1f9934c9f1593753ccd7440a926c9a538818364", | ||
"libraries/agent/src/AgentUnit.ts": "6a09e4ad90ab4aafe971340c3264882c28ceae0a", | ||
"libraries/agent/src/hooks/basic-set.ts": "0945eaf15151d3979da058e639126471420e84f5", | ||
@@ -19,3 +19,3 @@ "libraries/agent/src/hooks/index.ts": "f5e72a407ba4e6786afd89ba870454778bc5da05", | ||
"libraries/agent/src/hooks/useExchange.ts": "5365234c06a6e90ee2bd41fc5bb23fa3a2c49e10", | ||
"libraries/agent/src/hooks/useOHLC.ts": "17b66be1dc192c4d3a260a312dbe55886908178b", | ||
"libraries/agent/src/hooks/useOHLC.ts": "4c72eb71f1954f74b923b568bbcceca6d30dd7b5", | ||
"libraries/agent/src/hooks/useProduct.ts": "9e377bf3b1dfec4b67a87de80b0bb2dc79f8a424", | ||
@@ -27,3 +27,3 @@ "libraries/agent/src/hooks/useSinglePosition.ts": "d1b6554376900228531961b0b7de057342bac157", | ||
"libraries/agent/.rush/temp/shrinkwrap-deps.json": "a4ff9d1da2ea0b0129d874a92a1f7a87bb50d6a0", | ||
"libraries/kernel/temp/package-deps.json": "06dfabfc06a82ce89cd7263fe1bb9e2145dff40c", | ||
"libraries/kernel/temp/package-deps.json": "ef30e166c0a3987c8a7162366aafb824897eee7d", | ||
"libraries/protocol/temp/package-deps.json": "8c2d0730ddd9331f456c98591ab7437f85eca236", | ||
@@ -30,0 +30,0 @@ "libraries/utils/temp/package-deps.json": "d16348fe4fc484901d6fb1e9f01b13502c94ed46", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
327813
4775
+ Added@yuants/kernel@0.1.0(transitive)
+ Addedcall-bind-apply-helpers@1.0.2(transitive)
- Removed@yuants/kernel@0.0.5(transitive)
- Removedcall-bind-apply-helpers@1.0.1(transitive)
Updated@yuants/kernel@0.1.0