mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-26 08:45:16 +00:00
cmd/order: add market order support
This commit is contained in:
parent
90b633158a
commit
889318ddcb
|
@ -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")
|
||||
|
|
Loading…
Reference in New Issue
Block a user