Skip to content

Commit

Permalink
Merge pull request #7 from wiseaidev/patch-4
Browse files Browse the repository at this point in the history
fix orders operations, improve cli
  • Loading branch information
wiseaidev authored Mar 14, 2024
2 parents 701f412 + f23b2b2 commit 12c0578
Show file tree
Hide file tree
Showing 10 changed files with 376 additions and 199 deletions.
16 changes: 14 additions & 2 deletions .bumpversion.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
[bumpversion]
current_version = 0.0.4
current_version = 0.0.5

[bumpversion:file:Cargo.toml]
search = 'version = "{current_version}"'
replace = 'version = "{new_version}"'
replace = 'version = "{new_version}"'

[bumpversion:file:Cargo.lock]
search = 'version = "{current_version}"'
replace = 'version = "{new_version}"'

[bumpversion:file:README.md]
search = 'openbook = "{current_version}"'
replace = 'openbook = "{new_version}"'

[bumpversion:file:src/lib.rs]
search = '//! openbook = "{current_version}"'
replace = '//! openbook = "{new_version}"'
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "openbook"
version = "0.0.4"
version = "0.0.5"
edition = "2021"
description = "📖 A CLI and library for interacting with the OpenBook market on the Solana blockchain."
license = "MIT"
Expand Down
106 changes: 66 additions & 40 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,112 +49,134 @@ export KEY_PATH=<path_to_your_key_file>
## ⌨ Usage as CLI

### Get Market Info:
### Fetch Market Info:

```sh
openbook info
```

### Place a limit bid:
### Place a limit bid order:

```sh
openbook place --bid 100
openbook place -t 10.0 -s bid -b 0.5 -e -p 15.0
```

### Cancel an order:
### Place a limit ask order:

```sh
openbook cancel --bid 42
openbook place -t 10.0 -s ask -b 0.5 -e -p 15.0
```

### Make match orders transaction:
### Cancel all limit orders:

```sh
openbook match --order 5
openbook cancel -e
```

### Make consume events instruction:
### Settle balances:

```sh
openbook consume --limit 10
openbook settle -e
```

### Make consume events permissioned instruction:
### Fetch all orders for current owner (bids + asks):

```sh
openbook load
```

### Make match orders transaction:

```sh
openbook match --limit 3
```

### Make consume events instruction:

```sh
openbook consume-permissioned --limit 15
openbook consume --limit 2
```

### Load orders for owner:
### Make consume events permissioned instruction:

```sh
openbook load --num 20
openbook consume-permissioned --limit 2
```

## 💻 Usage as Dependency

```toml
[dependencies]
openbook = "0.0.4"
openbook = "0.0.5"
```

```rust
use openbook::{pubkey::Pubkey, signature::Keypair, rpc_client::RpcClient};
use openbook::market::Market;
use openbook::utils::read_keypair;
use openbook::matching::Side;
use openbook::commitment_config::CommitmentConfig;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let rpc_url = std::env::var("RPC_URL").expect("RPC_URL is not set in .env file");
let key_path = std::env::var("KEY_PATH").expect("KEY_PATH is not set in .env file");

let rpc_client = RpcClient::new(rpc_url);


let commitment_config = CommitmentConfig::confirmed();
let rpc_client = RpcClient::new_with_commitment(rpc_url, commitment_config);

let keypair = read_keypair(&key_path);

let mut market = Market::new(rpc_client, 3, "usdc", keypair).await;

println!("Initialized Market: {:?}", market);

let max_bid = 1;
let r = market.place_limit_bid(max_bid).await?;
println!("Place Order Results: {:?}", r);
let r = market
.place_limit_order(
10.0,
Side::Bid, // or Side::Ask
0.5,
true,
15.0,
)
.await?;
println!("Place Limit Order Result: {:?}", r);

let order_id_to_cancel = 2;
let c = market.cancel_order(order_id_to_cancel).await?;
println!("Cancel Order Results: {:?}", c);
let c = market.cancel_orders(true).await?;
println!("Cancel Orders Result: {:?}", c);

let s = market.settle_balance().await?;
println!("Settle Balance Results: {:?}", s);
let s = market.settle_balance(true).await?;
println!("Settle Balance Result: {:?}", s);

let m = market.make_match_orders_transaction(1).await?;
println!("Match Order Results: {:?}", m);
println!("Match Order Result: {:?}", m);

let open_orders_accounts = vec![Pubkey::new_from_array([0; 32])];
let limit = 10;

let e = market.make_consume_events_instruction(open_orders_accounts.clone(), limit).await?;
println!("Consume Events Results: {:?}", e);
println!("Consume Events Result: {:?}", e);

let p = market.make_consume_events_permissioned_instruction(open_orders_accounts.clone(), limit).await?;
println!("Consume Events Permissioned Results: {:?}", p);
println!("Consume Events Permissioned Result: {:?}", p);

Ok(())
}
```

## 🎨 Options

| Option | Default Value | Description |
|--------------------------|---------------|----------------------------------------------------------|
| `place --bid <BID>` | - | Place a limit bid with the specified amount. |
| `cancel --bid <BID>` | - | Cancel an existing order with the given order ID. |
| `settle` | - | Settle balances in the OpenBook market. |
| `match --order <ORDER>` | - | match orders transaction with the specified number of orders to match. |
| `consume --limit <LIMIT>` | - | consume events instruction with the specified limit. |
| `consume-permissioned --limit <LIMIT>` | - | consume events permissioned instruction with the specified limit. |
| `load --num <NUM>` | - | Load orders for a specific owner with the specified number. |
| `find-open-accounts` | - | Find open orders accounts for a specific owner. |
| Option | Default Value | Description |
|----------------------------------------|---------------|----------------------------------------------------------|
| `place -t <TARGET_AMOUNT_QUOTE> -s <SIDE> -b <BEST_OFFSET_USDC> -e -p <PRICE_TARGET>` | - | Place a limit order with the specified parameters. |
| `cancel -e` | - | Cancel all existing order for the current owner. |
| `settle -e` | - | Settle balances in the OpenBook market. |
| `match --limit <LIMIT>` | - | Match orders transaction with the specified limit. |
| `consume --limit <LIMIT>` | - | Consume events instruction with the specified limit. |
| `consume-permissioned --limit <LIMIT>` | - | Consume events permissioned instruction with the specified limit. |
| `find --future_option <FUTURE_OPTION>` | - | Find open orders accounts for a specific owner. |
| `load` | - | Load orders for the current owner, bids + asks. |
| `info` | - | Fetch OpenBook market info. |

## 🤝 Contributing

Expand All @@ -163,3 +185,7 @@ Contributions and feedback are welcome! If you'd like to contribute, report an i
## 📄 License

This project is licensed under the [MIT License](LICENSE).


Unresolved Questions:
- After completing all the tasks, should I transfer the repo ownership to the `@GigaDAO-GigaDEX` orginization? or create a new one?
55 changes: 35 additions & 20 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,17 @@ USAGE:
openbook [OPTIONS] <COMMAND>
EXAMPLES:
Place a limit bid:
openbook place --bid 100
Place a bid limit order:
openbook place -t 10.0 -s bid -b 0.5 -e -p 15.0
Cancel an order:
openbook cancel --order 42
Place a ask limit order:
openbook place -t 10.0 -s ask -b 0.5 -e -p 15.0
Cancel all limit orders:
openbook cancel -e
Settle balances:
openbook settle
openbook settle -e
For more information, visit: github.com/wiseaidev/openbook
"#
Expand All @@ -79,7 +82,7 @@ pub struct Cli {
#[cfg(feature = "cli")]
#[derive(Subcommand, Debug, Clone)]
pub enum Commands {
/// Place a limit bid.
/// Place a limit order.
Place(Place),
/// Cancel an order.
Cancel(Cancel),
Expand All @@ -99,31 +102,47 @@ pub enum Commands {
Info(Info),
}

/// Represents options for placing a limit bid in the OpenBook market.
/// Represents options for placing a limit order in the OpenBook market.
#[cfg(feature = "cli")]
#[derive(Args, Debug, Clone)]
pub struct Place {
/// Maximum bid amount.
/// Target amount in quote currency.
#[arg(short, long)]
pub target_amount_quote: f64,

/// Side of the order (Bid or Ask).
#[arg(short, long)]
pub side: String,

/// Best offset in USDC.
#[arg(short, long)]
pub best_offset_usdc: f64,

/// Flag indicating whether to execute the order immediately.
#[arg(short, long)]
pub execute: bool,

/// Target price for the order.
#[arg(short, long)]
pub bid: u64,
pub price_target: f64,
}

/// Represents options for cancelling an order in the OpenBook market.
#[cfg(feature = "cli")]
#[derive(Args, Debug, Clone)]
pub struct Cancel {
/// Order ID to cancel.
/// Flag indicating whether to execute the order immediately.
#[arg(short, long)]
pub order: u64,
pub execute: bool,
}

/// Represents options for settling balances in the OpenBook market.
#[cfg(feature = "cli")]
#[derive(Args, Debug, Clone)]
pub struct Settle {
/// Comming Soon: future options related to settling balances.
/// Flag indicating whether to execute the order immediately.
#[arg(short, long)]
pub future_option: u64,
pub execute: bool,
}

/// Represents options for match orders transactions in the OpenBook market.
Expand All @@ -132,7 +151,7 @@ pub struct Settle {
pub struct Match {
/// The maximum number of orders to match.
#[arg(short, long)]
pub order: u16,
pub limit: u16,
}

/// Represents options for consume events instructions in the OpenBook market.
Expand All @@ -153,14 +172,10 @@ pub struct ConsumePermissioned {
pub limit: u16,
}

/// Represents options for loading orders for a specific owner in the OpenBook market.
/// Represents options for loading orders for the current owner in the OpenBook market.
#[cfg(feature = "cli")]
#[derive(Args, Debug, Clone)]
pub struct Load {
/// Number of orders to load.
#[arg(short, long)]
pub num: u64,
}
pub struct Load {}

/// Represents options for finding open orders accounts for a specific owner in the OpenBook market.
#[cfg(feature = "cli")]
Expand Down
Loading

0 comments on commit 12c0578

Please sign in to comment.