Product -> FinancialInstrument

This commit is contained in:
斟酌 鵬兄 2022-10-22 04:10:27 +08:00
parent 36faffe882
commit 49043117e2
6 changed files with 28 additions and 24 deletions

View File

@ -7,14 +7,14 @@ import (
/* /*
EXPECT: BUY EXPECT: BUY
THEN EXPECT: [AmountStatement] OF [ProductStatement] THEN EXPECT: [AmountStatement] OF [FinancialInstrumentStatement]
THEN EXPECT: FOR [AmountStatement] THEN EXPECT: FOR [AmountStatement]
THEN EXPECT: FROM [ExchangeType] THEN EXPECT: FROM [ExchangeType]
THEN OPT EXPECT: [ExchangeType] THEN OPT EXPECT: [ExchangeType]
THEN OPT EXPECT: [AND|OR] THEN OPT EXPECT: [AND|OR]
THEN EXPECT: [ActionExpression] THEN EXPECT: [ActionExpression]
THEN OPT EXPECT: FOR EVERY THEN OPT EXPECT: FOR EVERY
THEN EXPECT: [AmountType] OF [ProductType] THEN EXPECT: [AmountType] OF [FinancialInstrumentType]
THEN EXPECT: [SOLD|BOUGHT] FROM [ExchangeType] THEN EXPECT: [SOLD|BOUGHT] FROM [ExchangeType]
*/ */
@ -43,19 +43,19 @@ func BuyStatement( lexer *engine.Lexer ) ( istmt stmtd.IStatement, err error ) {
return return
} }
// ProductStatement // FinancialInstrumentStatement
readProduct := engine.LexerExpect{ readFI := engine.LexerExpect{
Statements: true, Statements: true,
Keywords: false, Keywords: false,
Brackets: false, Brackets: false,
Quotes: false, Quotes: false,
Key: "PRODUCT", Key: "FINANCIAL_INSTRUMENT",
} }
productStmt, err := lexer.ReadStatement( &readProduct ) productStmt, err := lexer.ReadStatement( &readFI )
if err != nil { if err != nil {
return return
} }
orderStmt.Product( productStmt ) orderStmt.FinancialInstrument( productStmt )
istmt = orderStmt istmt = orderStmt
return return

View File

@ -12,7 +12,7 @@ func TestBuyStatement( t *testing.T ) {
supportedStmts := map[string] func( *engine.Lexer ) ( stmtd.IStatement, error ) { supportedStmts := map[string] func( *engine.Lexer ) ( stmtd.IStatement, error ) {
"BUY": BuyStatement, "BUY": BuyStatement,
"AMOUNT": AmountStatement, "AMOUNT": AmountStatement,
"PRODUCT": ProductStatement, "FINANCIAL_INSTRUMENT": FinancialInstrumentStatement,
} }
lexer.SupportedStmts = &supportedStmts lexer.SupportedStmts = &supportedStmts

View File

@ -12,8 +12,8 @@ OR
EXPECT: [FUNCTION]( ...params ) EXPECT: [FUNCTION]( ...params )
*/ */
func ProductStatement( lexer *engine.Lexer ) ( istmt stmtd.IStatement, err error ) { func FinancialInstrumentStatement( lexer *engine.Lexer ) ( istmt stmtd.IStatement, err error ) {
stmt := stmtd.ProductStatement{} stmt := stmtd.FinancialInstrumentStatement{}
name, err := lexer.ReadAlpha() name, err := lexer.ReadAlpha()
if err != nil { if err != nil {

View File

@ -25,7 +25,7 @@ type AmountStatement struct {
Unit string Unit string
} }
type ProductStatement struct { type FinancialInstrumentStatement struct {
IStatement IStatement
Name string Name string
} }
@ -44,5 +44,5 @@ type OrderStatement struct {
func ( this *OrderStatement ) For( stmt IStatement ) { func ( this *OrderStatement ) For( stmt IStatement ) {
} }
func ( this *OrderStatement ) Product( stmt IStatement ) { func ( this *OrderStatement ) FinancialInstrument( stmt IStatement ) {
} }

View File

@ -51,17 +51,17 @@ TODO
## SELL Statement ## SELL Statement
``` ```
[SELL] [Units] OF [Product] [SELL] [Amounts] OF [FinancialInstrument]
FOR [Amount] FOR [Amount]
FROM [Exchange] FROM [Exchange]
WITH LIMIT OF [Units] WITH LIMIT OF [Amounts]
AND AND
[Other Action Statements] [Other Action Statements]
FOR EVERY FOR EVERY
[Units] OF [Product] [SOLD] [Amounts] OF [FinancialInstrument] [SOLD]
FROM [Exchange]/ANYWHERE FROM [Exchange]/ANYWHERE
AND/OR AND/OR
[Units] OF [Product] [BOUGHT] [Amounts] OF [FinancialInstrument] [BOUGHT]
FROM [Exchange]/ANYWHERE FROM [Exchange]/ANYWHERE
AS 'ACTION_NAME' AS 'ACTION_NAME'
``` ```
@ -69,8 +69,12 @@ AS 'ACTION_NAME'
### Examples ### Examples
#### Simple Sell #### Simple Sell
The following statements are identical
``` ```
SELL 1 SHARES OF QQQ FROM "MyBrokerAccount" SELL 1 SHARES OF QQQ FROM "MyBrokerAccount"
SELL 1 UNIT OF QQQ FROM "MyBrokerAccount"
SELL 1 QQQ FROM "MyBrokerAccount"
``` ```
#### Sell Trigger #### Sell Trigger
@ -87,17 +91,17 @@ AS 'My Hedge Trigger'
## BUY Statement ## BUY Statement
``` ```
[BUY] [Units] OF [Product] [BUY] [Amounts] OF [FinancialInstrument]
FOR [Amount] FOR [Amount]
FROM [Exchange] FROM [Exchange]
WITH LIMIT OF [Units] WITH LIMIT OF [Amounts]
AND AND
[Other Action Statements] [Other Action Statements]
FOR EVERY FOR EVERY
[Units] OF [Product] [SOLD] [Amounts] OF [FinancialInstrument] [SOLD]
FROM [Exchange]/ANYWHERE FROM [Exchange]/ANYWHERE
AND/OR AND/OR
[Units] OF [Product] [BOUGHT] [Amounts] OF [FinancialInstrument] [BOUGHT]
FROM [Exchange]/ANYWHERE FROM [Exchange]/ANYWHERE
``` ```
@ -116,13 +120,13 @@ BUY 1 SHARES OF BTC_ETF
## PURCHASING_POWER ## PURCHASING_POWER
`PURCHASING_POWER( Exchange, Product )` `PURCHASING_POWER( Exchange, FinancialInstrument )`
Returns the maximum [Units] of [Product] can purchase from [Exchange] Returns the maximum [Amounts] of [FinancialInstrument] can purchase from [Exchange]
## CURRENT_PRICE ## CURRENT_PRICE
`CURRENT_PRICE( Exchange, Product )` `CURRENT_PRICE( Exchange, FinancialInstrument )`
Returns the current price of a product from exchange Returns the current price of a product from exchange

View File

@ -13,7 +13,7 @@ BUY 1 SHARES OF BTC_ETF
``` ```
{ {
Statement: BUY Statement: BUY
Product: { FinancialInstrument: {
Name: BTC_ETF Name: BTC_ETF
Amount: { Amount: {
Value: 1 Value: 1