-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
199 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,8 @@ pub mod msg; | |
#[cfg(test)] | ||
mod testing; | ||
|
||
mod order_management; | ||
mod types; | ||
#[cfg(test)] | ||
pub mod utils; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
use crate::types; | ||
use cosmwasm_std::{to_json_binary, Coin, CosmosMsg, StdResult, SubMsg, Uint128, WasmMsg}; | ||
Check warning on line 2 in contracts/injective-cosmwasm-mock/src/order_management.rs
|
||
use injective_cosmwasm::{InjectiveMsgWrapper, OrderType, SpotMarket}; | ||
use injective_math::FPDecimal; | ||
|
||
|
||
pub fn create_stargate_msg(type_url: &str, value: Vec<u8>) -> StdResult<CosmosMsg<InjectiveMsgWrapper>> { | ||
Ok(CosmosMsg::Stargate { | ||
type_url: type_url.to_string(), | ||
value: value.into(), | ||
}) | ||
} | ||
|
||
pub fn create_spot_market_order( | ||
price: FPDecimal, | ||
quantity: FPDecimal, | ||
order_type: OrderType, | ||
sender: &str, | ||
subaccount_id: &str, | ||
market: &SpotMarket, | ||
) -> types::MsgCreateSpotMarketOrder { | ||
types::MsgCreateSpotMarketOrder { | ||
sender: sender.to_string(), | ||
order: Some(types::SpotOrder { | ||
market_id: market.market_id.as_str().into(), | ||
order_info: Some(types::OrderInfo { | ||
subaccount_id: subaccount_id.to_string(), | ||
fee_recipient: sender.to_string(), | ||
price: price.to_string(), | ||
quantity: quantity.to_string(), | ||
}), | ||
order_type: order_type as i32, | ||
trigger_price: "".to_string(), | ||
}), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
#[allow(clippy::derive_partial_eq_without_eq)] | ||
#[derive( | ||
Clone, | ||
PartialEq, | ||
Eq, | ||
::prost::Message, | ||
::serde::Serialize, | ||
::serde::Deserialize, | ||
::schemars::JsonSchema, | ||
// CosmwasmExt, | ||
)] | ||
// #[proto_message(type_url = "/injective.exchange.v1beta1.OrderInfo")] | ||
pub struct OrderInfo { | ||
/// bytes32 subaccount ID that created the order | ||
#[prost(string, tag = "1")] | ||
#[serde(alias = "subaccountID")] | ||
pub subaccount_id: ::prost::alloc::string::String, | ||
/// address fee_recipient address that will receive fees for the order | ||
#[prost(string, tag = "2")] | ||
pub fee_recipient: ::prost::alloc::string::String, | ||
/// price of the order | ||
#[prost(string, tag = "3")] | ||
pub price: ::prost::alloc::string::String, | ||
/// quantity of the order | ||
#[prost(string, tag = "4")] | ||
pub quantity: ::prost::alloc::string::String, | ||
} | ||
|
||
#[allow(clippy::derive_partial_eq_without_eq)] | ||
#[derive( | ||
Clone, | ||
PartialEq, | ||
Eq, | ||
::prost::Message, | ||
::serde::Serialize, | ||
::serde::Deserialize, | ||
::schemars::JsonSchema, | ||
// CosmwasmExt, | ||
)] | ||
// #[proto_message(type_url = "/injective.exchange.v1beta1.SpotOrder")] | ||
pub struct SpotOrder { | ||
/// market_id represents the unique ID of the market | ||
#[prost(string, tag = "1")] | ||
#[serde(alias = "marketID")] | ||
pub market_id: ::prost::alloc::string::String, | ||
/// order_info contains the information of the order | ||
#[prost(message, optional, tag = "2")] | ||
pub order_info: ::core::option::Option<OrderInfo>, | ||
/// order types | ||
#[prost(enumeration = "OrderType", tag = "3")] | ||
// #[serde( | ||
// serialize_with = "crate::serde::as_str::serialize", | ||
// deserialize_with = "crate::serde::as_str::deserialize" | ||
// )] | ||
pub order_type: i32, | ||
/// trigger_price is the trigger price used by stop/take orders | ||
#[prost(string, tag = "4")] | ||
pub trigger_price: ::prost::alloc::string::String, | ||
} | ||
|
||
/// MsgCreateSpotMarketOrder defines a SDK message for creating a new spot market | ||
/// order. | ||
#[allow(clippy::derive_partial_eq_without_eq)] | ||
#[derive( | ||
Clone, | ||
PartialEq, | ||
Eq, | ||
::prost::Message, | ||
::serde::Serialize, | ||
::serde::Deserialize, | ||
::schemars::JsonSchema, | ||
// CosmwasmExt, | ||
)] | ||
// #[proto_message(type_url = "/injective.exchange.v1beta1.MsgCreateSpotMarketOrder")] | ||
pub struct MsgCreateSpotMarketOrder { | ||
#[prost(string, tag = "1")] | ||
pub sender: ::prost::alloc::string::String, | ||
#[prost(message, optional, tag = "2")] | ||
pub order: ::core::option::Option<SpotOrder>, | ||
} | ||
|
||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)] | ||
#[repr(i32)] | ||
#[derive(::serde::Serialize, ::serde::Deserialize, ::schemars::JsonSchema)] | ||
pub enum OrderType { | ||
Unspecified = 0, | ||
Buy = 1, | ||
Sell = 2, | ||
StopBuy = 3, | ||
StopSell = 4, | ||
TakeBuy = 5, | ||
TakeSell = 6, | ||
BuyPo = 7, | ||
SellPo = 8, | ||
BuyAtomic = 9, | ||
SellAtomic = 10, | ||
} |
Oops, something went wrong.