reduce only flag for perp place order (#286)

Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>

Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
This commit is contained in:
microwavedcola1 2022-11-09 09:59:34 +01:00 committed by GitHub
parent e8ba511c45
commit e47e17d79f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 37 additions and 2 deletions

View File

@ -84,7 +84,8 @@ pub fn perp_place_order(ctx: Context<PerpPlaceOrder>, order: Order, limit: u8) -
let now_ts = Clock::get()?.unix_timestamp as u64; let now_ts = Clock::get()?.unix_timestamp as u64;
// TODO reduce_only based on event queue // TODO apply reduce_only flag to compute final base_lots, also process event queue
require!(order.reduce_only == false, MangoError::SomeError);
book.new_order( book.new_order(
order, order,

View File

@ -505,6 +505,7 @@ pub mod mango_v4 {
max_quote_lots: i64, max_quote_lots: i64,
client_order_id: u64, client_order_id: u64,
order_type: PlaceOrderType, order_type: PlaceOrderType,
reduce_only: bool,
// Timestamp of when order expires // Timestamp of when order expires
// //
@ -534,6 +535,7 @@ pub mod mango_v4 {
max_base_lots, max_base_lots,
max_quote_lots, max_quote_lots,
client_order_id, client_order_id,
reduce_only,
time_in_force, time_in_force,
params: match order_type { params: match order_type {
PlaceOrderType::Market => OrderParams::Market, PlaceOrderType::Market => OrderParams::Market,
@ -566,6 +568,7 @@ pub mod mango_v4 {
max_quote_lots: i64, max_quote_lots: i64,
client_order_id: u64, client_order_id: u64,
order_type: PlaceOrderType, order_type: PlaceOrderType,
reduce_only: bool,
// Timestamp of when order expires // Timestamp of when order expires
// //
@ -595,6 +598,7 @@ pub mod mango_v4 {
max_base_lots, max_base_lots,
max_quote_lots, max_quote_lots,
client_order_id, client_order_id,
reduce_only,
time_in_force, time_in_force,
params: OrderParams::OraclePegged { params: OrderParams::OraclePegged {
price_offset_lots, price_offset_lots,

View File

@ -16,6 +16,9 @@ pub struct Order {
/// Arbitrary user-controlled order id. /// Arbitrary user-controlled order id.
pub client_order_id: u64, pub client_order_id: u64,
/// Reduce only
pub reduce_only: bool,
/// Number of seconds the order shall live, 0 meaning forever /// Number of seconds the order shall live, 0 meaning forever
pub time_in_force: u8, pub time_in_force: u8,

View File

@ -2402,7 +2402,8 @@ impl ClientInstruction for PerpPlaceOrderInstruction {
max_base_lots: self.max_base_lots, max_base_lots: self.max_base_lots,
max_quote_lots: self.max_quote_lots, max_quote_lots: self.max_quote_lots,
client_order_id: self.client_order_id, client_order_id: self.client_order_id,
order_type: PlaceOrderType::Limit, order_type: OrderType::Limit,
reduce_only: false,
expiry_timestamp: 0, expiry_timestamp: 0,
limit: 10, limit: 10,
}; };

View File

@ -1617,6 +1617,7 @@ export class MangoClient {
maxQuoteQuantity: number | undefined, maxQuoteQuantity: number | undefined,
clientOrderId: number | undefined, clientOrderId: number | undefined,
orderType: PerpOrderType | undefined, orderType: PerpOrderType | undefined,
reduceOnly: boolean | undefined,
expiryTimestamp: number | undefined, expiryTimestamp: number | undefined,
limit: number | undefined, limit: number | undefined,
): Promise<TransactionSignature> { ): Promise<TransactionSignature> {
@ -1633,6 +1634,7 @@ export class MangoClient {
maxQuoteQuantity, maxQuoteQuantity,
clientOrderId, clientOrderId,
orderType, orderType,
reduceOnly,
expiryTimestamp, expiryTimestamp,
limit, limit,
), ),
@ -1654,6 +1656,7 @@ export class MangoClient {
maxQuoteQuantity?: number, maxQuoteQuantity?: number,
clientOrderId?: number, clientOrderId?: number,
orderType?: PerpOrderType, orderType?: PerpOrderType,
reduceOnly?: boolean,
expiryTimestamp?: number, expiryTimestamp?: number,
limit?: number, limit?: number,
): Promise<TransactionInstruction> { ): Promise<TransactionInstruction> {
@ -1677,6 +1680,7 @@ export class MangoClient {
: I64_MAX_BN, : I64_MAX_BN,
new BN(clientOrderId ? clientOrderId : Date.now()), new BN(clientOrderId ? clientOrderId : Date.now()),
orderType ? orderType : PerpOrderType.limit, orderType ? orderType : PerpOrderType.limit,
reduceOnly ? reduceOnly : false,
new BN(expiryTimestamp ? expiryTimestamp : 0), new BN(expiryTimestamp ? expiryTimestamp : 0),
limit ? limit : 10, limit ? limit : 10,
) )

View File

@ -2754,6 +2754,10 @@ export type MangoV4 = {
"defined": "PlaceOrderType" "defined": "PlaceOrderType"
} }
}, },
{
"name": "reduceOnly",
"type": "bool"
},
{ {
"name": "expiryTimestamp", "name": "expiryTimestamp",
"type": "u64" "type": "u64"
@ -9583,6 +9587,10 @@ export const IDL: MangoV4 = {
"defined": "PlaceOrderType" "defined": "PlaceOrderType"
} }
}, },
{
"name": "reduceOnly",
"type": "bool"
},
{ {
"name": "expiryTimestamp", "name": "expiryTimestamp",
"type": "u64" "type": "u64"

View File

@ -471,6 +471,7 @@ async function main() {
quoteQty, quoteQty,
clientId, clientId,
PerpOrderType.limit, PerpOrderType.limit,
false,
0, //Date.now() + 200, 0, //Date.now() + 200,
1, 1,
); );
@ -513,6 +514,7 @@ async function main() {
quoteQty, quoteQty,
clientId, clientId,
PerpOrderType.limit, PerpOrderType.limit,
false,
0, //Date.now() + 200, 0, //Date.now() + 200,
1, 1,
); );
@ -553,6 +555,7 @@ async function main() {
quoteQty, quoteQty,
clientId, clientId,
PerpOrderType.limit, PerpOrderType.limit,
false,
0, //Date.now() + 200, 0, //Date.now() + 200,
1, 1,
); );
@ -584,6 +587,7 @@ async function main() {
quoteQty, quoteQty,
clientId, clientId,
PerpOrderType.limit, PerpOrderType.limit,
false,
0, //Date.now() + 200, 0, //Date.now() + 200,
1, 1,
); );
@ -618,6 +622,7 @@ async function main() {
price * 0.01, price * 0.01,
clientId, clientId,
PerpOrderType.limit, PerpOrderType.limit,
false,
0, //Date.now() + 200, 0, //Date.now() + 200,
1, 1,
); );
@ -639,6 +644,7 @@ async function main() {
price * 0.011, price * 0.011,
clientId, clientId,
PerpOrderType.limit, PerpOrderType.limit,
false,
0, //Date.now() + 200, 0, //Date.now() + 200,
1, 1,
); );

View File

@ -238,6 +238,7 @@ async function main() {
0.044, // ui quote quantity 0.044, // ui quote quantity
4200, 4200,
PerpOrderType.limit, PerpOrderType.limit,
false,
0, 0,
5, 5,
); );
@ -281,6 +282,7 @@ async function main() {
0.044, // ui quote quantity 0.044, // ui quote quantity
4200, 4200,
PerpOrderType.limit, PerpOrderType.limit,
false,
0, 0,
5, 5,
); );
@ -295,6 +297,7 @@ async function main() {
0.044, // ui quote quantity 0.044, // ui quote quantity
4200, 4200,
PerpOrderType.market, PerpOrderType.market,
false,
0, 0,
5, 5,
); );
@ -358,6 +361,7 @@ async function main() {
0.022, // ui quote quantity 0.022, // ui quote quantity
4200, 4200,
PerpOrderType.limit, PerpOrderType.limit,
false,
0, 0,
5, 5,
); );
@ -371,6 +375,7 @@ async function main() {
0.022, // ui quote quantity 0.022, // ui quote quantity
4200, 4200,
PerpOrderType.market, PerpOrderType.market,
false,
0, 0,
5, 5,
); );
@ -391,6 +396,7 @@ async function main() {
0.044, // ui quote quantity 0.044, // ui quote quantity
4201, 4201,
PerpOrderType.limit, PerpOrderType.limit,
false,
0, 0,
5, 5,
); );
@ -404,6 +410,7 @@ async function main() {
0.044, // ui quote quantity 0.044, // ui quote quantity
4201, 4201,
PerpOrderType.market, PerpOrderType.market,
false,
0, 0,
5, 5,
); );

View File

@ -56,6 +56,7 @@ async function takeOrder(
undefined, undefined,
Date.now(), Date.now(),
PerpOrderType.market, PerpOrderType.market,
false,
0, 0,
10, 10,
); );