Product -> FinancialInstrument
This commit is contained in:
parent
36faffe882
commit
49043117e2
@ -7,14 +7,14 @@ import (
|
||||
|
||||
/*
|
||||
EXPECT: BUY
|
||||
THEN EXPECT: [AmountStatement] OF [ProductStatement]
|
||||
THEN EXPECT: [AmountStatement] OF [FinancialInstrumentStatement]
|
||||
THEN EXPECT: FOR [AmountStatement]
|
||||
THEN EXPECT: FROM [ExchangeType]
|
||||
THEN OPT EXPECT: [ExchangeType]
|
||||
THEN OPT EXPECT: [AND|OR]
|
||||
THEN EXPECT: [ActionExpression]
|
||||
THEN OPT EXPECT: FOR EVERY
|
||||
THEN EXPECT: [AmountType] OF [ProductType]
|
||||
THEN EXPECT: [AmountType] OF [FinancialInstrumentType]
|
||||
THEN EXPECT: [SOLD|BOUGHT] FROM [ExchangeType]
|
||||
*/
|
||||
|
||||
@ -43,19 +43,19 @@ func BuyStatement( lexer *engine.Lexer ) ( istmt stmtd.IStatement, err error ) {
|
||||
return
|
||||
}
|
||||
|
||||
// ProductStatement
|
||||
readProduct := engine.LexerExpect{
|
||||
// FinancialInstrumentStatement
|
||||
readFI := engine.LexerExpect{
|
||||
Statements: true,
|
||||
Keywords: false,
|
||||
Brackets: false,
|
||||
Quotes: false,
|
||||
Key: "PRODUCT",
|
||||
Key: "FINANCIAL_INSTRUMENT",
|
||||
}
|
||||
productStmt, err := lexer.ReadStatement( &readProduct )
|
||||
productStmt, err := lexer.ReadStatement( &readFI )
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
orderStmt.Product( productStmt )
|
||||
orderStmt.FinancialInstrument( productStmt )
|
||||
|
||||
istmt = orderStmt
|
||||
return
|
||||
|
@ -12,7 +12,7 @@ func TestBuyStatement( t *testing.T ) {
|
||||
supportedStmts := map[string] func( *engine.Lexer ) ( stmtd.IStatement, error ) {
|
||||
"BUY": BuyStatement,
|
||||
"AMOUNT": AmountStatement,
|
||||
"PRODUCT": ProductStatement,
|
||||
"FINANCIAL_INSTRUMENT": FinancialInstrumentStatement,
|
||||
}
|
||||
lexer.SupportedStmts = &supportedStmts
|
||||
|
||||
|
@ -12,8 +12,8 @@ OR
|
||||
EXPECT: [FUNCTION]( ...params )
|
||||
*/
|
||||
|
||||
func ProductStatement( lexer *engine.Lexer ) ( istmt stmtd.IStatement, err error ) {
|
||||
stmt := stmtd.ProductStatement{}
|
||||
func FinancialInstrumentStatement( lexer *engine.Lexer ) ( istmt stmtd.IStatement, err error ) {
|
||||
stmt := stmtd.FinancialInstrumentStatement{}
|
||||
|
||||
name, err := lexer.ReadAlpha()
|
||||
if err != nil {
|
||||
|
@ -25,7 +25,7 @@ type AmountStatement struct {
|
||||
Unit string
|
||||
}
|
||||
|
||||
type ProductStatement struct {
|
||||
type FinancialInstrumentStatement struct {
|
||||
IStatement
|
||||
Name string
|
||||
}
|
||||
@ -44,5 +44,5 @@ type OrderStatement struct {
|
||||
func ( this *OrderStatement ) For( stmt IStatement ) {
|
||||
}
|
||||
|
||||
func ( this *OrderStatement ) Product( stmt IStatement ) {
|
||||
func ( this *OrderStatement ) FinancialInstrument( stmt IStatement ) {
|
||||
}
|
||||
|
@ -51,17 +51,17 @@ TODO
|
||||
|
||||
## SELL Statement
|
||||
```
|
||||
[SELL] [Units] OF [Product]
|
||||
[SELL] [Amounts] OF [FinancialInstrument]
|
||||
FOR [Amount]
|
||||
FROM [Exchange]
|
||||
WITH LIMIT OF [Units]
|
||||
WITH LIMIT OF [Amounts]
|
||||
AND
|
||||
[Other Action Statements]
|
||||
FOR EVERY
|
||||
[Units] OF [Product] [SOLD]
|
||||
[Amounts] OF [FinancialInstrument] [SOLD]
|
||||
FROM [Exchange]/ANYWHERE
|
||||
AND/OR
|
||||
[Units] OF [Product] [BOUGHT]
|
||||
[Amounts] OF [FinancialInstrument] [BOUGHT]
|
||||
FROM [Exchange]/ANYWHERE
|
||||
AS 'ACTION_NAME'
|
||||
```
|
||||
@ -69,8 +69,12 @@ AS 'ACTION_NAME'
|
||||
### Examples
|
||||
|
||||
#### Simple Sell
|
||||
|
||||
The following statements are identical
|
||||
```
|
||||
SELL 1 SHARES OF QQQ FROM "MyBrokerAccount"
|
||||
SELL 1 UNIT OF QQQ FROM "MyBrokerAccount"
|
||||
SELL 1 QQQ FROM "MyBrokerAccount"
|
||||
```
|
||||
|
||||
#### Sell Trigger
|
||||
@ -87,17 +91,17 @@ AS 'My Hedge Trigger'
|
||||
|
||||
## BUY Statement
|
||||
```
|
||||
[BUY] [Units] OF [Product]
|
||||
[BUY] [Amounts] OF [FinancialInstrument]
|
||||
FOR [Amount]
|
||||
FROM [Exchange]
|
||||
WITH LIMIT OF [Units]
|
||||
WITH LIMIT OF [Amounts]
|
||||
AND
|
||||
[Other Action Statements]
|
||||
FOR EVERY
|
||||
[Units] OF [Product] [SOLD]
|
||||
[Amounts] OF [FinancialInstrument] [SOLD]
|
||||
FROM [Exchange]/ANYWHERE
|
||||
AND/OR
|
||||
[Units] OF [Product] [BOUGHT]
|
||||
[Amounts] OF [FinancialInstrument] [BOUGHT]
|
||||
FROM [Exchange]/ANYWHERE
|
||||
```
|
||||
|
||||
@ -116,13 +120,13 @@ BUY 1 SHARES OF BTC_ETF
|
||||
|
||||
## 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( Exchange, Product )`
|
||||
`CURRENT_PRICE( Exchange, FinancialInstrument )`
|
||||
|
||||
Returns the current price of a product from exchange
|
||||
|
||||
|
@ -13,7 +13,7 @@ BUY 1 SHARES OF BTC_ETF
|
||||
```
|
||||
{
|
||||
Statement: BUY
|
||||
Product: {
|
||||
FinancialInstrument: {
|
||||
Name: BTC_ETF
|
||||
Amount: {
|
||||
Value: 1
|
||||
|
Loading…
Reference in New Issue
Block a user