2022-10-18 09:13:41 +00:00
|
|
|
# Table of Contents
|
|
|
|
* [Action Statements](#action-statements)
|
2022-10-19 13:45:11 +00:00
|
|
|
* [CREATE EXCHANGE](#create-exchange-statement)
|
2022-10-19 14:04:49 +00:00
|
|
|
* [CREATE SPREAD](#create-spread-statement)
|
2022-10-18 09:13:41 +00:00
|
|
|
* [SELL](#sell-statement)
|
|
|
|
* [BUY](#buy-statement)
|
|
|
|
* [Functions](#functions)
|
|
|
|
* [PURCHASING_POWER](#purchasing_power)
|
2022-10-19 11:51:35 +00:00
|
|
|
* [CURRENT_PRICE](#current_price)
|
2022-10-19 13:45:11 +00:00
|
|
|
* [Types of Exchange](#types-of-exchange)
|
|
|
|
* [IB_API](#ib_api)
|
|
|
|
* [HIVE](#hive)
|
2022-10-18 09:13:41 +00:00
|
|
|
|
|
|
|
|
2022-10-18 08:48:56 +00:00
|
|
|
# Action Statements
|
|
|
|
|
2022-10-19 13:45:11 +00:00
|
|
|
## CREATE EXCHANGE Statement
|
|
|
|
```
|
|
|
|
CREATE EXCHANGE [Name] TYPE [ExchangeType]
|
|
|
|
URI [API CALLBACK URI]
|
|
|
|
[...Exchange type-specific PARAMS]
|
|
|
|
```
|
|
|
|
|
|
|
|
### Examples
|
|
|
|
```
|
|
|
|
CREATE EXCHANGE 'IB' TYPE IB_API
|
|
|
|
URI 'https://127.0.0.1:11590/'
|
|
|
|
```
|
|
|
|
|
2022-10-19 14:04:11 +00:00
|
|
|
## CREATE SPREAD Statement
|
|
|
|
This is a shortcut function to create a buy/sell order pairs with hedge triggers
|
2022-10-19 13:45:11 +00:00
|
|
|
```
|
2022-10-19 14:04:11 +00:00
|
|
|
TODO
|
2022-10-19 13:45:11 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
### Examples
|
|
|
|
```
|
2022-10-19 14:04:11 +00:00
|
|
|
CREATE SPREAD OF 10 BTC FOR QQQToken FROM "CryptoExchange"
|
|
|
|
HEDGE BTC FOR USD FROM "CryptoExchange"
|
|
|
|
HEDGE QQQToken FOR QQQ FROM "StockExchange"
|
2022-10-19 13:45:11 +00:00
|
|
|
```
|
|
|
|
|
2022-10-19 14:04:11 +00:00
|
|
|
|
2022-10-18 08:48:56 +00:00
|
|
|
## SELL Statement
|
|
|
|
```
|
|
|
|
[SELL] [Units] OF [Product]
|
2022-10-19 11:51:35 +00:00
|
|
|
FOR [Amount]
|
2022-10-18 08:48:56 +00:00
|
|
|
FROM [Exchange]
|
2022-10-18 09:13:41 +00:00
|
|
|
WITH LIMIT OF [Units]
|
2022-10-18 08:48:56 +00:00
|
|
|
AND
|
|
|
|
[Other Action Statements]
|
|
|
|
FOR EVERY
|
|
|
|
[Units] OF [Product] [SOLD]
|
|
|
|
FROM [Exchange]/ANYWHERE
|
|
|
|
AND/OR
|
|
|
|
[Units] OF [Product] [BOUGHT]
|
|
|
|
FROM [Exchange]/ANYWHERE
|
2022-10-18 09:13:41 +00:00
|
|
|
AS 'ACTION_NAME'
|
2022-10-18 08:48:56 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
### Examples
|
2022-10-18 09:13:41 +00:00
|
|
|
|
|
|
|
#### Simple Sell
|
|
|
|
```
|
|
|
|
SELL 1 SHARES OF QQQ FROM "MyBrokerAccount"
|
|
|
|
```
|
|
|
|
|
|
|
|
#### Sell Trigger
|
2022-10-18 08:48:56 +00:00
|
|
|
```
|
|
|
|
SELL 1 SHARES OF QQQ
|
2022-10-19 11:51:35 +00:00
|
|
|
FOR 10 USD
|
2022-10-18 08:48:56 +00:00
|
|
|
FROM "MyBrokerAccount"
|
2022-10-18 09:13:41 +00:00
|
|
|
WITH LIMIT OF 100 SHARES
|
2022-10-18 08:48:56 +00:00
|
|
|
FOR EVERY
|
|
|
|
2 SHARES OF QQQ_TOKEN SOLD
|
|
|
|
FROM "CoinBase"
|
2022-10-18 09:13:41 +00:00
|
|
|
AS 'My Hedge Trigger'
|
2022-10-18 08:48:56 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
## BUY Statement
|
|
|
|
```
|
|
|
|
[BUY] [Units] OF [Product]
|
2022-10-19 11:51:35 +00:00
|
|
|
FOR [Amount]
|
2022-10-18 08:48:56 +00:00
|
|
|
FROM [Exchange]
|
2022-10-18 09:13:41 +00:00
|
|
|
WITH LIMIT OF [Units]
|
2022-10-18 08:48:56 +00:00
|
|
|
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
|
2022-10-19 11:51:35 +00:00
|
|
|
FOR 10 USD
|
2022-10-18 08:48:56 +00:00
|
|
|
FROM "MyBrokerAccount"
|
2022-10-18 09:13:41 +00:00
|
|
|
WITH LIMIT OF PURCHASING_POWER( "MyBrokerAccount", "QQQ" )
|
2022-10-18 08:48:56 +00:00
|
|
|
FOR EVERY
|
|
|
|
1 BTC OF USD_BTC SOLD
|
|
|
|
FROM "CoinBase"
|
|
|
|
```
|
|
|
|
|
2022-10-18 09:13:41 +00:00
|
|
|
# functions
|
|
|
|
|
|
|
|
## PURCHASING_POWER
|
|
|
|
|
|
|
|
`PURCHASING_POWER( Exchange, Product )`
|
|
|
|
|
|
|
|
Returns the maximum [Units] of [Product] can purchase from [Exchange]
|
2022-10-18 08:48:56 +00:00
|
|
|
|
2022-10-19 11:51:35 +00:00
|
|
|
## CURRENT_PRICE
|
2022-10-18 08:48:56 +00:00
|
|
|
|
2022-10-19 11:51:35 +00:00
|
|
|
`CURRENT_PRICE( Exchange, Product )`
|
|
|
|
|
|
|
|
Returns the current price of a product from exchange
|
|
|
|
|
|
|
|
# Examples
|
|
|
|
|
|
|
|
## Creating a spread
|
|
|
|
|
|
|
|
* Max position: $1000
|
|
|
|
* Spread: $10
|
|
|
|
* QQQ etf price(Qetf): $100
|
|
|
|
|
|
|
|
| Bid | Ask |
|
2022-10-19 11:53:36 +00:00
|
|
|
|-----------------|----------------|
|
2022-10-19 11:51:35 +00:00
|
|
|
| 10shares@$95 | 10shares@$105 |
|
|
|
|
| ($1000 of Qetf) | ($800 of Qetf) |
|
|
|
|
|
|
|
|
If a trader hit ur ASK by bidding 2 shares of QQQ token
|
|
|
|
|
|
|
|
| Bid | Ask |
|
2022-10-19 11:53:36 +00:00
|
|
|
|-----------------|----------------|
|
2022-10-19 11:51:35 +00:00
|
|
|
| 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.
|
|
|
|
* No need to handle his remaining 12 shares , its not ur responsibility, its his "broker/app/program" to deal with unfilled order.
|
|
|
|
|
|
|
|
| Bid | Ask |
|
2022-10-19 11:53:36 +00:00
|
|
|
|-----------------|----------------|
|
2022-10-19 11:51:35 +00:00
|
|
|
| 10shares@$95 | |
|
|
|
|
| ($1000 of Qetf) | |
|
|
|
|
|
|
|
|
|
|
|
|
### SELL Order
|
2022-10-18 08:48:56 +00:00
|
|
|
```
|
2022-10-19 11:51:35 +00:00
|
|
|
SELL 10 SHARES OF "QQQ_TOKEN"
|
2022-10-19 13:16:03 +00:00
|
|
|
FOR CURRENT_PRICE( "CryptoExchange", "QQQ_TOKEN" ) + 5 BTC
|
|
|
|
WITH LIMIT OF 1000 BTC
|
2022-10-19 11:51:35 +00:00
|
|
|
FROM "CryptoExchange"
|
|
|
|
```
|
|
|
|
|
2022-10-18 08:48:56 +00:00
|
|
|
|
2022-10-19 11:51:35 +00:00
|
|
|
### BUY Order
|
|
|
|
```
|
|
|
|
BUY 10 SHARES OF "QQQ_TOKEN"
|
2022-10-19 13:16:03 +00:00
|
|
|
FOR CURRENT_PRICE( "CryptoExchange", "QQQ_TOKEN" ) - 5 BTC
|
|
|
|
WITH LIMIT OF 1000 BTC
|
2022-10-19 11:51:35 +00:00
|
|
|
FROM "CryptoExchange"
|
|
|
|
```
|
2022-10-18 08:48:56 +00:00
|
|
|
|
2022-10-19 12:04:00 +00:00
|
|
|
## Hedging
|
|
|
|
|
2022-10-19 13:28:14 +00:00
|
|
|
### BUY Trigger for every QQQToken handed out
|
2022-10-18 08:48:56 +00:00
|
|
|
```
|
2022-10-19 11:51:35 +00:00
|
|
|
BUY 1 SHARES OF "QQQ"
|
|
|
|
FOR CURRENT_PRICE( "StockExchange", "QQQ" )
|
|
|
|
FROM "StockExchange"
|
|
|
|
FOR EVERY 1 SHARES OF "QQQ_TOKEN" SOLD FROM "CryptoExchange"
|
|
|
|
```
|
|
|
|
|
2022-10-19 13:28:14 +00:00
|
|
|
### SELL Trigger for every QQQToken received
|
2022-10-18 08:48:56 +00:00
|
|
|
```
|
2022-10-19 13:16:03 +00:00
|
|
|
SELL 1 SHARES OF "QQQ"
|
|
|
|
FOR CURRENT_PRICE( "StockExchange", "QQQ" )
|
|
|
|
FROM "StockeExchange"
|
|
|
|
FOR EVERY 1 SHARES OF "QQQ_TOKEN" BOUGHT FROM "CryptoExchange"
|
|
|
|
```
|
|
|
|
|
|
|
|
### BUY Trigger for every BTC handed out
|
|
|
|
```
|
|
|
|
BUY 1 BTC OF BTC
|
|
|
|
FOR CURRENT_PRICE( "CryptoExchange", "USD.BTC" )
|
|
|
|
FROM "CryptoExchange"
|
|
|
|
FOR EVERY 1 BTC OF BTC SOLD FROM "CryptoExchange"
|
|
|
|
```
|
|
|
|
|
|
|
|
### SELL Trigger for every BTC received
|
|
|
|
```
|
|
|
|
SELL 1 BTC OF BTC
|
|
|
|
FOR CURRENT_PRICE( "CryptoExchange", "USD.BTC" )
|
|
|
|
FROM "CryptoExchange"
|
|
|
|
FOR EVERY 1 BTC OF BTC BOUGHT FROM "CryptoExchange"
|
2022-10-18 08:48:56 +00:00
|
|
|
```
|