Skip to content

Commit 4fbb076

Browse files
committed
add place order api
1 parent 990fea6 commit 4fbb076

File tree

4 files changed

+360
-1
lines changed

4 files changed

+360
-1
lines changed

pkg/exchange/hyperliquid/exchange.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
)
1313

1414
const (
15-
PlatformToken = "HYPE"
15+
HYPE = "HYPE"
1616

1717
ID types.ExchangeName = "hyperliquid"
1818
)
@@ -51,6 +51,10 @@ func (e *Exchange) Name() types.ExchangeName {
5151
return types.ExchangeHyperliquid
5252
}
5353

54+
func (e *Exchange) PlatformFeeCurrency() string {
55+
return HYPE
56+
}
57+
5458
func (e *Exchange) QueryMarkets(ctx context.Context) (types.MarketMap, error) {
5559
if err := restSharedLimiter.Wait(ctx); err != nil {
5660
return nil, fmt.Errorf("markets rate limiter wait error: %w", err)
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package hyperapi
2+
3+
import (
4+
"github.com/c9s/requestgen"
5+
)
6+
7+
//go:generate -command GetRequest requestgen -method GET -responseType .APIResponse -responseDataField Response.Data
8+
//go:generate -command PostRequest requestgen -method POST -responseType .APIResponse -responseDataField Response.Data
9+
10+
type OrderResponse struct {
11+
Statuses []struct {
12+
Resting struct {
13+
Oid string `json:"oid"`
14+
Error string `json:"error"`
15+
Filled struct {
16+
TotalSz string `json:"totalSz"`
17+
AvgPx string `json:"avgPx"`
18+
Oid int64 `json:"oid"`
19+
} `json:"filled"`
20+
} `json:"resting"`
21+
} `json:"statuses"`
22+
}
23+
24+
//go:generate PostRequest -url "/exchange" -type PlaceOrderRequest -responseDataType OrderResponse
25+
type PlaceOrderRequest struct {
26+
client requestgen.AuthenticatedAPIClient
27+
28+
metaType InfoReqType `param:"type" default:"order" validValues:"order"`
29+
30+
orders []struct {
31+
asset string `param:"a"`
32+
isBuy bool `param:"b"`
33+
size string `param:"s"`
34+
price string `param:"p"`
35+
reduceOnly bool `param:"r"`
36+
clientOrderID *string `param:"c"`
37+
orderType struct {
38+
limit *struct {
39+
tif string `param:"tif" validValues:"Alo,Ioc,Gtc"`
40+
} `param:"limit"`
41+
trigger *struct {
42+
isMarket bool `param:"isMarket"`
43+
triggerPx string `param:"triggerPx"`
44+
tpsl string `param:"tpsl" validValues:"tp,sl"`
45+
}
46+
} `param:"t"`
47+
} `param:"orders"`
48+
49+
grouping string `param:"grouping" default:"na" validValues:"na,normalTpsl,positionTpsl"`
50+
51+
builder *struct {
52+
feeAddress string `param:"b"`
53+
feeSize string `param:"f"`
54+
} `param:"builder"`
55+
}
56+
57+
func (c *Client) NewPlaceOrderRequest() *PlaceOrderRequest {
58+
return &PlaceOrderRequest{
59+
client: c,
60+
metaType: Order,
61+
}
62+
}

pkg/exchange/hyperliquid/hyperapi/place_order_request_requestgen.go

Lines changed: 282 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/exchange/hyperliquid/hyperapi/types.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package hyperapi
22

3+
import "encoding/json"
4+
35
type SignatureResult struct {
46
R string `json:"r"`
57
S string `json:"s"`
@@ -11,4 +13,13 @@ type InfoReqType string
1113
const (
1214
Meta InfoReqType = "meta"
1315
SpotMeta InfoReqType = "spotMeta"
16+
Order InfoReqType = "order"
1417
)
18+
19+
type APIResponse struct {
20+
Status string `json:"status"`
21+
Response struct {
22+
Type string `json:"type"`
23+
Data json.RawMessage `json:"data"`
24+
} `json:"response"`
25+
}

0 commit comments

Comments
 (0)