Some drafts
This commit is contained in:
		
							
								
								
									
										121
									
								
								specifications/0001_LanguageSyntax.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										121
									
								
								specifications/0001_LanguageSyntax.md
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,121 @@
 | 
			
		||||
# Action Statements
 | 
			
		||||
 | 
			
		||||
## SELL Statement
 | 
			
		||||
```
 | 
			
		||||
[SELL] [Units] OF [Product]
 | 
			
		||||
    FROM [Exchange]
 | 
			
		||||
AND
 | 
			
		||||
[Other Action Statements]
 | 
			
		||||
    FOR EVERY
 | 
			
		||||
        [Units] OF [Product] [SOLD]
 | 
			
		||||
            FROM [Exchange]/ANYWHERE
 | 
			
		||||
        AND/OR
 | 
			
		||||
        [Units] OF [Product] [BOUGHT]
 | 
			
		||||
            FROM [Exchange]/ANYWHERE
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
### Examples
 | 
			
		||||
```
 | 
			
		||||
SELL 1 SHARES OF QQQ
 | 
			
		||||
  FROM "MyBrokerAccount"
 | 
			
		||||
  FOR EVERY
 | 
			
		||||
    2 SHARES OF QQQ_TOKEN SOLD
 | 
			
		||||
        FROM "CoinBase"
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
## BUY Statement
 | 
			
		||||
```
 | 
			
		||||
[BUY] [Units] OF [Product]
 | 
			
		||||
    FROM [Exchange]
 | 
			
		||||
AND
 | 
			
		||||
[Other Action Statements]
 | 
			
		||||
    FOR EVERY
 | 
			
		||||
        [Units] OF [Product] [SOLD]
 | 
			
		||||
            FROM [Exchange]/ANYWHERE
 | 
			
		||||
        AND/OR
 | 
			
		||||
        [Units] OF [Product] [BOUGHT]
 | 
			
		||||
            FROM [Exchange]/ANYWHERE
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
### Examples
 | 
			
		||||
```
 | 
			
		||||
BUY 1 SHARES OF BTC_ETF
 | 
			
		||||
  FROM "MyBrokerAccount"
 | 
			
		||||
  FOR EVERY
 | 
			
		||||
    1 BTC OF USD_BTC SOLD
 | 
			
		||||
        FROM "CoinBase"
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
### Other things
 | 
			
		||||
 | 
			
		||||
```
 | 
			
		||||
(set max position=$1000,
 | 
			
		||||
spread=$10,  QQQ etf price(Qetf)=$100. ), 
 | 
			
		||||
then the quote u give is: 
 | 
			
		||||
               Bid                   Ask
 | 
			
		||||
10shares@$95           10shares@$105
 | 
			
		||||
($1000 of Qetf).         ($1000 of Qetf)
 | 
			
		||||
 | 
			
		||||
if a trader hit ur ASK by bidding 2 shares of QQQ token ,then the output quote:
 | 
			
		||||
           Bid.                      Ask
 | 
			
		||||
10shares@$95           8shares@$105
 | 
			
		||||
($1000 of Qetf).        ($800 of Qetf)
 | 
			
		||||
 | 
			
		||||
if another trader hit ur ASK with a 20 shares of bid  , then only 8 shares of his order can be filled. 
 | 
			
		||||
u dont need to handle his remaining 12 shares , its not ur responsibility, its his "broker/app/program" to deal with unfilled order.
 | 
			
		||||
so ur quote becomes
 | 
			
		||||
Bid.                                 Ask
 | 
			
		||||
10shares@$95           
 | 
			
		||||
($1000 of Qetf).
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
```
 | 
			
		||||
[In reply to Penguin]
 | 
			
		||||
#Code example:
 | 
			
		||||
"""
 | 
			
		||||
set the maximum amount($USD) of QQQ tokens i can sell to traders as [my max position]
 | 
			
		||||
"""
 | 
			
		||||
set [my max position$]=[$1000]
 | 
			
		||||
 | 
			
		||||
"""set the amount($USD) of sold QQQ token as $0 becoz i havent sold any QQQ tokens before i start my bot
 | 
			
		||||
"""
 | 
			
		||||
set [total$].[sold QQQ token] =0
 | 
			
		||||
 | 
			
		||||
"""
 | 
			
		||||
The quantity of the sell order quote i can send to the market is the remaining amount of [my max position], which is [max]-[total].[sold]
 | 
			
		||||
initially, 
 | 
			
		||||
[my max position$]=$1000,
 | 
			
		||||
[total$].[sold QQQ token]=0,
 | 
			
		||||
remaining token=
 | 
			
		||||
[my max position$] - [total$].[sold QQQ token]=$1000-0=$1000
 | 
			
		||||
so,
 | 
			
		||||
[remain$]
 | 
			
		||||
=[my max position$] - [total$].[sold QQQ token]
 | 
			
		||||
"""
 | 
			
		||||
 | 
			
		||||
#get price quote from the nasdaq
 | 
			
		||||
[get][QQQ etf price$] from [ib]
 | 
			
		||||
 | 
			
		||||
while [total$].[sold QQQ token]
 | 
			
		||||
<[my max position$] 
 | 
			
		||||
   """find my remaining amount($USD)
 | 
			
		||||
   of qqq tokens i can sell
 | 
			
		||||
   """
 | 
			
		||||
   [remain$]=
 | 
			
		||||
   [my max position$]  -  [total$].[sold
 | 
			
		||||
   QQQ token]
 | 
			
		||||
 | 
			
		||||
   """convert the remaining
 | 
			
		||||
   amount($USD) to number of shares
 | 
			
		||||
   of qqq tokens i can sell
 | 
			
		||||
   """
 | 
			
		||||
   [share].[remain$]=
 | 
			
		||||
   [remain$] / [QQQ etf $price] 
 | 
			
		||||
   
 | 
			
		||||
#set my Bid Ask spread
 | 
			
		||||
   [price].[Bid]=
 | 
			
		||||
   [QQQ etf $price]  -  [spread]/2
 | 
			
		||||
   [price].[Ask]=
 | 
			
		||||
   [QQQ etf $price]  +  [spread]/2
 | 
			
		||||
```
 | 
			
		||||
		Reference in New Issue
	
	Block a user