cmd/order: add market order support

This commit is contained in:
c9s 2022-09-07 02:17:56 +08:00
parent 90b633158a
commit 889318ddcb
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54

View File

@ -300,7 +300,6 @@ var submitOrderCmd = &cobra.Command{
"session",
"symbol",
"side",
"price",
"quantity",
}),
RunE: func(cmd *cobra.Command, args []string) error {
@ -329,6 +328,11 @@ var submitOrderCmd = &cobra.Command{
return fmt.Errorf("can not get price: %w", err)
}
asMarketOrder, err := cmd.Flags().GetBool("market")
if err != nil {
return err
}
quantity, err := cmd.Flags().GetString("quantity")
if err != nil {
return fmt.Errorf("can not get quantity: %w", err)
@ -363,12 +367,23 @@ var submitOrderCmd = &cobra.Command{
Side: types.SideType(strings.ToUpper(side)),
Type: types.OrderTypeLimit,
Quantity: fixedpoint.MustNewFromString(quantity),
Price: fixedpoint.MustNewFromString(price),
Market: market,
TimeInForce: "GTC",
MarginSideEffect: types.MarginOrderSideEffectType(marginOrderSideEffect),
}
if asMarketOrder {
so.Type = types.OrderTypeMarket
so.Price = fixedpoint.Zero
} else {
if len(price) == 0 {
return fmt.Errorf("price is required for limit order submission")
}
so.Type = types.OrderTypeLimit
so.Price = fixedpoint.MustNewFromString(price)
so.TimeInForce = types.TimeInForceGTC
}
co, err := session.Exchange.SubmitOrders(ctx, so)
if err != nil {
return err
@ -392,6 +407,7 @@ func init() {
submitOrderCmd.Flags().String("side", "", "the trading side: buy or sell")
submitOrderCmd.Flags().String("price", "", "the trading price")
submitOrderCmd.Flags().String("quantity", "", "the trading quantity")
submitOrderCmd.Flags().Bool("market", false, "submit order as a market order")
submitOrderCmd.Flags().String("margin-side-effect", "", "margin order side effect")
executeOrderCmd.Flags().String("session", "", "the exchange session name for sync")