mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-13 23:16:45 +00:00
* gctcli: modifyorder stubs * gctcli: add ModifyOrderRequest and ModifyOrderResponse in rpc.proto * gctcli: regenerate rpc.pb.go after the addition of ModifyOrder structs * gctrpc: add ModifyOrder() and regenerate dependent files * gctcli: modifyorder command now uses newly generated ModifyOrder() RPC * exchanges/order/orders.go: use time.Time.Equal() instead of == * gctrpc: update ModifyOrderRequest and ModifyResponse and regenerate gRPC * gctcli/commands: rework modifyorder * engine: implement RPCServer.ModifyOrder * engine: commit an initial version OrderManager.Modify(), still does not update state of managed orders * engine: OrderManager.Modify now updates the inner state of managed orders, but introduces race conditions, needs fixes * engine/order_manager.go: comply with golangci-lint * gctcli: fix getOrderCommand.ArgsUsage * gctcli: fix getModifyOrderCommand args and ArgsUsage * engine: OrderManager.Modify() now correctly updates price of modified order * engine: RPCServer.ModifyOrder now uses checkParams() as advised * exchanges: (1) IBotExchange.ModifyOrder now returns a Modify struct, (2) all exchanges are updated to comply with that change * exchanges/order: Detail.UpdateOrderFromModify also updates the ID * engine/order_manager: add store.modifyExisting() and use it in OrderManager.Modify to update (on success) the state of the modified order * exchanges: Bitfinex.ModifyOrder() now returns the ID in case of an error * engine: OrdetManager.Modify() now emits an order event * exchanges/bithumb: proper order.payment_currency key * engine/order_manager: populate more Modify fields as they are needed by (some) exchanges, add comments * engine: test OrderManager.Modify() * engine: test store.modifyExisting() * engine: write a docstring for store.modifyExisting * engine: OrderManager.Modify() now also sets Modify.Price and Modify.Amount in case of zero values * engine: TestOrderManager_Modify() now verify the effects of price and/or amount set to 0 * engine: OrderManger.Modify() now uses the commsManager to let observers know of errors * engine: TestOrderManager_Modify() uses t.Fatal() * engine: TestOrderManager_Modify() and TestStore_modifyOrder() supply t.Error() with proper messages * exchanges/order_manager_test: fix a golangci-lint complaint * engine/order_manager: fix an error comparison bug and simplify * gctcli/commands: check if either price or amount is set, otherwise we would waste an API call
160 lines
3.7 KiB
Go
160 lines
3.7 KiB
Go
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"log"
|
|
"os"
|
|
"path/filepath"
|
|
"runtime"
|
|
|
|
"github.com/thrasher-corp/gocryptotrader/common"
|
|
"github.com/thrasher-corp/gocryptotrader/core"
|
|
"github.com/thrasher-corp/gocryptotrader/gctrpc/auth"
|
|
"github.com/urfave/cli/v2"
|
|
"google.golang.org/grpc"
|
|
"google.golang.org/grpc/credentials"
|
|
)
|
|
|
|
var (
|
|
host string
|
|
username string
|
|
password string
|
|
pairDelimiter string
|
|
certPath string
|
|
)
|
|
|
|
func jsonOutput(in interface{}) {
|
|
j, err := json.MarshalIndent(in, "", " ")
|
|
if err != nil {
|
|
return
|
|
}
|
|
fmt.Print(string(j))
|
|
}
|
|
|
|
func setupClient() (*grpc.ClientConn, error) {
|
|
creds, err := credentials.NewClientTLSFromFile(certPath, "")
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
opts := []grpc.DialOption{grpc.WithTransportCredentials(creds),
|
|
grpc.WithPerRPCCredentials(auth.BasicAuth{
|
|
Username: username,
|
|
Password: password,
|
|
}),
|
|
}
|
|
conn, err := grpc.Dial(host, opts...)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return conn, err
|
|
}
|
|
|
|
func main() {
|
|
app := cli.NewApp()
|
|
app.Name = "gctcli"
|
|
app.Version = core.Version(true)
|
|
app.EnableBashCompletion = true
|
|
app.Usage = "command line interface for managing the gocryptotrader daemon"
|
|
app.Flags = []cli.Flag{
|
|
&cli.StringFlag{
|
|
Name: "rpchost",
|
|
Value: "localhost:9052",
|
|
Usage: "the gRPC host to connect to",
|
|
Destination: &host,
|
|
},
|
|
&cli.StringFlag{
|
|
Name: "rpcuser",
|
|
Value: "admin",
|
|
Usage: "the gRPC username",
|
|
Destination: &username,
|
|
},
|
|
&cli.StringFlag{
|
|
Name: "rpcpassword",
|
|
Value: "Password",
|
|
Usage: "the gRPC password",
|
|
Destination: &password,
|
|
},
|
|
&cli.StringFlag{
|
|
Name: "delimiter",
|
|
Value: "-",
|
|
Usage: "the default currency pair delimiter used to standardise currency pair input",
|
|
Destination: &pairDelimiter,
|
|
},
|
|
&cli.StringFlag{
|
|
Name: "cert",
|
|
Value: filepath.Join(common.GetDefaultDataDir(runtime.GOOS), "tls", "cert.pem"),
|
|
Usage: "the path to TLS cert of the gRPC server",
|
|
Destination: &certPath,
|
|
},
|
|
}
|
|
app.Commands = []*cli.Command{
|
|
getInfoCommand,
|
|
getSubsystemsCommand,
|
|
enableSubsystemCommand,
|
|
disableSubsystemCommand,
|
|
getRPCEndpointsCommand,
|
|
getCommunicationRelayersCommand,
|
|
getExchangesCommand,
|
|
enableExchangeCommand,
|
|
disableExchangeCommand,
|
|
getExchangeOTPCommand,
|
|
getExchangeOTPsCommand,
|
|
getExchangeInfoCommand,
|
|
getTickerCommand,
|
|
getTickersCommand,
|
|
getOrderbookCommand,
|
|
getOrderbooksCommand,
|
|
getAccountInfoCommand,
|
|
getAccountInfoStreamCommand,
|
|
updateAccountInfoCommand,
|
|
getConfigCommand,
|
|
getPortfolioCommand,
|
|
getPortfolioSummaryCommand,
|
|
addPortfolioAddressCommand,
|
|
removePortfolioAddressCommand,
|
|
getForexProvidersCommand,
|
|
getForexRatesCommand,
|
|
getOrdersCommand,
|
|
getManagedOrdersCommand,
|
|
getOrderCommand,
|
|
submitOrderCommand,
|
|
simulateOrderCommand,
|
|
whaleBombCommand,
|
|
cancelOrderCommand,
|
|
cancelBatchOrdersCommand,
|
|
cancelAllOrdersCommand,
|
|
modifyOrderCommand,
|
|
getEventsCommand,
|
|
addEventCommand,
|
|
removeEventCommand,
|
|
getCryptocurrencyDepositAddressesCommand,
|
|
getCryptocurrencyDepositAddressCommand,
|
|
withdrawCryptocurrencyFundsCommand,
|
|
withdrawFiatFundsCommand,
|
|
withdrawalRequestCommand,
|
|
getLoggerDetailsCommand,
|
|
setLoggerDetailsCommand,
|
|
exchangePairManagerCommand,
|
|
getOrderbookStreamCommand,
|
|
getExchangeOrderbookStreamCommand,
|
|
getTickerStreamCommand,
|
|
getExchangeTickerStreamCommand,
|
|
getAuditEventCommand,
|
|
getHistoricCandlesCommand,
|
|
getHistoricCandlesExtendedCommand,
|
|
findMissingSavedCandleIntervalsCommand,
|
|
gctScriptCommand,
|
|
websocketManagerCommand,
|
|
tradeCommand,
|
|
dataHistoryCommands,
|
|
}
|
|
|
|
err := app.Run(os.Args)
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
}
|