-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindicator_tools.go
More file actions
163 lines (131 loc) · 5.47 KB
/
indicator_tools.go
File metadata and controls
163 lines (131 loc) · 5.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
package main
import (
"context"
"fmt"
"upbit-mcp-server/indicators"
"upbit-mcp-server/upbit"
"github.com/modelcontextprotocol/go-sdk/mcp"
)
type GetMovingAverageRequest struct {
Market string `json:"market" jsonschema:"Trading pair code representing the market (e.g. KRW-BTC, KRW-ETH ...)"`
Period int `json:"period" jsonschema:"The period to calculate the moving average for."`
Count int `json:"count,omitempty" jsonschema:"Number of candles to retrieve. Max 200."`
}
type GetMovingAverageResult struct {
SMA []float64 `json:"sma"`
EMA []float64 `json:"ema"`
}
type GetMACDRequest struct {
Market string `json:"market" jsonschema:"Trading pair code representing the market (e.g. KRW-BTC, KRW-ETH ...)"`
ShortPeriod int `json:"short_period" jsonschema:"The short period for MACD calculation."`
LongPeriod int `json:"long_period" jsonschema:"The long period for MACD calculation."`
SignalPeriod int `json:"signal_period" jsonschema:"The signal period for MACD calculation."`
Count int `json:"count,omitempty" jsonschema:"Number of candles to retrieve. Max 200."`
}
type GetMACDResult struct {
MACDLine []float64 `json:"macd_line"`
SignalLine []float64 `json:"signal_line"`
Histogram []float64 `json:"histogram"`
}
type GetBollingerBandsRequest struct {
Market string `json:"market" jsonschema:"Trading pair code representing the market (e.g. KRW-BTC, KRW-ETH ...)"`
Period int `json:"period" jsonschema:"The period to calculate the Bollinger Bands for."`
StdDev float64 `json:"std_dev" jsonschema:"The standard deviation to use for the Bollinger Bands."`
Count int `json:"count,omitempty" jsonschema:"Number of candles to retrieve. Max 200."`
}
type GetBollingerBandsResult struct {
SMA []float64 `json:"sma"`
UpperBand []float64 `json:"upper_band"`
LowerBand []float64 `json:"lower_band"`
}
type GetRSIRequest struct {
Market string `json:"market" jsonschema:"Trading pair code representing the market (e.g. KRW-BTC, KRW-ETH ...)"`
Period int `json:"period" jsonschema:"The period to calculate the RSI for."`
Count int `json:"count,omitempty" jsonschema:"Number of candles to retrieve. Max 200."`
}
type GetRSIResult struct {
RSI []float64 `json:"rsi"`
}
type GetOBVRequest struct {
Market string `json:"market" jsonschema:"Trading pair code representing the market (e.g. KRW-BTC, KRW-ETH ...)"`
Count int `json:"count,omitempty" jsonschema:"Number of candles to retrieve. Max 200."`
}
type GetOBVResult struct {
OBV []float64 `json:"obv"`
}
func GetMovingAverage(ctx context.Context, req *mcp.CallToolRequest, params *GetMovingAverageRequest) (*mcp.CallToolResult, *GetMovingAverageResult, error) {
client, ok := ctx.Value(upbitClientKey{}).(*upbit.Client)
if !ok {
return nil, nil, fmt.Errorf("Upbit client not found in context")
}
candles, err := client.GetDayCandles(upbit.RequestParams{
Market: params.Market,
Count: params.Count,
})
if err != nil {
return nil, nil, err
}
sma := indicators.CalculateSMA(candles, params.Period)
ema := indicators.CalculateEMA(candles, params.Period)
return &mcp.CallToolResult{}, &GetMovingAverageResult{SMA: sma, EMA: ema}, nil
}
func GetMACD(ctx context.Context, req *mcp.CallToolRequest, params *GetMACDRequest) (*mcp.CallToolResult, *GetMACDResult, error) {
client, ok := ctx.Value(upbitClientKey{}).(*upbit.Client)
if !ok {
return nil, nil, fmt.Errorf("Upbit client not found in context")
}
candles, err := client.GetDayCandles(upbit.RequestParams{
Market: params.Market,
Count: params.Count,
})
if err != nil {
return nil, nil, err
}
macd, signal, histogram := indicators.CalculateMACD(candles, params.ShortPeriod, params.LongPeriod, params.SignalPeriod)
return &mcp.CallToolResult{}, &GetMACDResult{MACDLine: macd, SignalLine: signal, Histogram: histogram}, nil
}
func GetBollingerBands(ctx context.Context, req *mcp.CallToolRequest, params *GetBollingerBandsRequest) (*mcp.CallToolResult, *GetBollingerBandsResult, error) {
client, ok := ctx.Value(upbitClientKey{}).(*upbit.Client)
if !ok {
return nil, nil, fmt.Errorf("Upbit client not found in context")
}
candles, err := client.GetDayCandles(upbit.RequestParams{
Market: params.Market,
Count: params.Count,
})
if err != nil {
return nil, nil, err
}
sma, upper, lower := indicators.CalculateBollingerBands(candles, params.Period, params.StdDev)
return &mcp.CallToolResult{}, &GetBollingerBandsResult{SMA: sma, UpperBand: upper, LowerBand: lower}, nil
}
func GetRSI(ctx context.Context, req *mcp.CallToolRequest, params *GetRSIRequest) (*mcp.CallToolResult, *GetRSIResult, error) {
client, ok := ctx.Value(upbitClientKey{}).(*upbit.Client)
if !ok {
return nil, nil, fmt.Errorf("Upbit client not found in context")
}
candles, err := client.GetDayCandles(upbit.RequestParams{
Market: params.Market,
Count: params.Count,
})
if err != nil {
return nil, nil, err
}
rsi := indicators.CalculateRSI(candles, params.Period)
return &mcp.CallToolResult{}, &GetRSIResult{RSI: rsi}, nil
}
func GetOBV(ctx context.Context, req *mcp.CallToolRequest, params *GetOBVRequest) (*mcp.CallToolResult, *GetOBVResult, error) {
client, ok := ctx.Value(upbitClientKey{}).(*upbit.Client)
if !ok {
return nil, nil, fmt.Errorf("Upbit client not found in context")
}
candles, err := client.GetDayCandles(upbit.RequestParams{
Market: params.Market,
Count: params.Count,
})
if err != nil {
return nil, nil, err
}
obv := indicators.CalculateOBV(candles)
return &mcp.CallToolResult{}, &GetOBVResult{OBV: obv}, nil
}