Skip to content

Commit

Permalink
Remove useless
Browse files Browse the repository at this point in the history
  • Loading branch information
oldfritter committed Apr 15, 2020
1 parent 583b945 commit 1394954
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 93 deletions.
89 changes: 0 additions & 89 deletions api/v1/order.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"fmt"
"net/http"
"strconv"
"strings"

"github.com/labstack/echo"
. "github.com/oldfritter/goDCE/models"
Expand Down Expand Up @@ -153,74 +152,6 @@ func V1PostOrders(context echo.Context) error {

}

type OrderAttr struct {
Side string `json:"side"`
NewClientOrderId string `json:"new_client_order_id"`
OrderType string `json:"order_type"`
Price decimal.Decimal `json:"price"`
Volume decimal.Decimal `json:"volume"`
}

func V1PostOrdersMulti(context echo.Context) error {
params := context.Get("params").(map[string]string)
user := context.Get("current_user").(User)
var market Market
mainDB := utils.MainDbBegin()
defer mainDB.DbRollback()
if mainDB.Where("name = ?", params["market"]).First(&market).RecordNotFound() {
return utils.BuildError("1021")
}
var orderAttrs []OrderAttr
json.Unmarshal([]byte(strings.Replace(params["orders"], `\"`, `"`, -1)), &orderAttrs)
orders := make([]interface{}, len(orderAttrs))

response := utils.SuccessResponse

for i, orderAttr := range orderAttrs {
var orderType string
locked := orderAttr.Volume
price, volume := orderAttr.Price.Truncate(int32(market.BidFixed)), orderAttr.Volume.Truncate(int32(market.AskFixed))
if price.LessThanOrEqual(decimal.Zero) {
return utils.BuildError("1024")
}
if volume.LessThanOrEqual(decimal.Zero) {
return utils.BuildError("1023")
}
if orderAttr.Side == "buy" {
locked = orderAttr.Volume.Mul(orderAttr.Price)
orderType = "OrderBid"
} else if orderAttr.Side == "sell" {
orderType = "OrderAsk"
} else {
return utils.BuildError("1022")
}
order := Order{
Source: context.Param("platform") + "-APIv1",
State: WAIT,
UserId: user.Id,
MarketId: market.Id,
Volume: volume,
OriginVolume: volume,
Price: price,
OrderType: "limit",
Type: orderType,
Locked: locked,
OriginLocked: locked,
}
err := tryToChangeAccount(context, &order, &market, orderAttr.Side, user.Id, 2)
if err == nil {
pushMessageToMatching(&order, &market, "submit")
orders[i] = order
} else {
response = utils.BuildError("3022")
response.Body = orders
return response
}
}
response.Body = orders
return context.JSON(http.StatusOK, response)
}

func V1PostOrderDelete(context echo.Context) error {
params := context.Get("params").(map[string]string)
user := context.Get("current_user").(User)
Expand All @@ -236,26 +167,6 @@ func V1PostOrderDelete(context echo.Context) error {
return context.JSON(http.StatusOK, response)
}

func V1PostOrdersDelete(context echo.Context) error {
params := context.Get("params").(map[string]string)
user := context.Get("current_user").(User)
ids := strings.Split(params["ids"], ",")
mainDB := utils.MainDbBegin()
defer mainDB.DbRollback()
var orders []Order
if mainDB.Where("id in (?) AND user_id = ?", ids, user.Id).Find(&orders).RecordNotFound() {
return utils.BuildError("2004")
}
for _, order := range orders {
if order.State == 100 {
pushMessageToMatching(&order, &order.Market, "cancel")
}
}
response := utils.SuccessResponse
response.Body = orders
return context.JSON(http.StatusOK, response)
}

func V1PostOrdersClear(context echo.Context) error {
params := context.Get("params").(map[string]string)
user := context.Get("current_user").(User)
Expand Down
4 changes: 2 additions & 2 deletions models/market.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ type OrderCurrency struct {

type Market struct {
CommonModel
Name string `gorm:"type:varchar(16)"`
Code string `gorm:"type:varchar(16)"`
Name string `json:"name"" gorm:"type:varchar(16)"`
Code string `json:"code" gorm:"type:varchar(16)"`
PriceGroupFixed int `json:"price_group_fixed"`
SortOrder int `json:"sort_order"`
AskCurrencyId int `json:"ask_currency_id"`
Expand Down
2 changes: 0 additions & 2 deletions routes/v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ func SetV1Interfaces(e *echo.Echo) {
e.GET("/api/:platform/v1/order", V1GetOrder)
e.GET("/api/:platform/v1/orders", V1GetOrders)
e.POST("/api/:platform/v1/orders", V1PostOrders)
e.POST("/api/:platform/v1/orders/multi2", V1PostOrdersMulti)
e.POST("/api/:platform/v1/order/delete", V1PostOrderDelete)
e.POST("/api/:platform/v1/orders/delete", V1PostOrdersDelete)
e.POST("/api/:platform/v1/orders/clear", V1PostOrdersClear)
e.GET("/api/:platform/v1/tickers", V1GetTickers)
e.GET("/api/:platform/v1/tickers/:market", V1GetTickersMarket)
Expand Down

0 comments on commit 1394954

Please sign in to comment.