Skip to content

Commit e361a17

Browse files
committed
api code fix
1 parent 21e2471 commit e361a17

File tree

3 files changed

+34
-15
lines changed

3 files changed

+34
-15
lines changed

.github/workflows/docker_image.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ jobs:
4040
with:
4141
context: .
4242
push: true
43+
platforms: linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64
4344
tags: ${{ github.repository }}:${{ steps.get_version.outputs.version-without-v }}
4445

4546
- name: Image digest

Makefile

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1-
.PHONY: help build build-linux clean
1+
.PHONY: help build clean
22

33
.DEFAULT_GOAL := help
44

5-
build: ## build binary
6-
go build -trimpath -o ./bin/freqtrade-proxy
5+
build: ## build binaries
6+
go build -trimpath -o ./bin/freqtrade-proxy-darwin-amd64
7+
for arch in "linux/amd64" "linux/arm/v6" "linux/arm/v7" "linux/arm64" ; do \
8+
echo $${arch//\//-}; \
9+
docker run --platform $$arch -v $(PWD):/tmp/src golang:buster /bin/bash -c "cd /tmp/src && go build -trimpath -o ./bin/freqtrade-proxy-"$${arch//\//-} ;\
10+
done
711

812
clean: ## clean
9-
rm ./bin/freqtrade-proxy
10-
11-
build-linux: ## build linux-binary
12-
docker run -v $(PWD):/tmp/src golang:buster /bin/bash -c "cd /tmp/src && make build"
13+
rm ./bin/freqtrade-proxy*
1314

1415
help:
1516
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'

proxy/kucoin/kucoin.go

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package kucoin
22

33
import (
4+
"encoding/json"
45
"fmt"
56
"strings"
67
"sync"
@@ -156,7 +157,7 @@ func (ws *ws) serveFor(store *store.Store) {
156157
}
157158
}
158159

159-
func (kucoin *kucoin) getKlines(pair string, timeframe string, startAt int64, endAt int64, retryCount int) (sdk.KLinesModel, error) {
160+
func (kucoin *kucoin) getKlines(pair string, timeframe string, startAt int64, endAt int64, retryCount int) (sdk.KLinesModel, *sdk.ApiResponse, error) {
160161
var (
161162
resp *sdk.ApiResponse
162163
err error
@@ -169,19 +170,19 @@ func (kucoin *kucoin) getKlines(pair string, timeframe string, startAt int64, en
169170
break
170171
}
171172

172-
if i == retryCount {
173-
return sdk.KLinesModel{}, err
173+
if i == retryCount || resp.Code != "429000" { //This type of Candlestick is currently not provided
174+
return sdk.KLinesModel{}, resp, err
174175
}
175176

176-
time.Sleep(time.Millisecond * 150)
177+
time.Sleep(time.Millisecond * 100)
177178
}
178179

179180
candlesModel := sdk.KLinesModel{}
180181
if err := resp.ReadData(&candlesModel); err != nil {
181-
return candlesModel, err
182+
return candlesModel, resp, err
182183
}
183184

184-
return candlesModel, nil
185+
return candlesModel, resp, nil
185186
}
186187

187188
func (kucoin *kucoin) timeframeToDuration(timeframe string) time.Duration {
@@ -219,6 +220,17 @@ func (kucoin *kucoin) truncateTs(timeframe string, ts time.Time) time.Time {
219220
return ts.Truncate(kucoin.timeframeToDuration(timeframe))
220221
}
221222

223+
type apiResp struct {
224+
Code string `json:"code"`
225+
RawData json.RawMessage `json:"data,omitempty"`
226+
Message string `json:"msg"`
227+
}
228+
229+
func (resp *apiResp) json() []byte {
230+
data, _ := json.Marshal(resp)
231+
return data
232+
}
233+
222234
func (kucoin *kucoin) Start(port int) {
223235
router := routing.New()
224236

@@ -239,9 +251,14 @@ func (kucoin *kucoin) Start(port int) {
239251
candles := kucoin.store.Get("kucoin", pair, timeframe, startTruncated, endTruncated, kucoin.timeframeToDuration(timeframe))
240252

241253
if len(candles) == 0 {
242-
candlesModel, err := kucoin.getKlines(pair, timeframe, startTruncated.Unix(), endAt, 3)
254+
candlesModel, resp, err := kucoin.getKlines(pair, timeframe, startTruncated.Unix(), endAt, 3)
243255
if err != nil {
244-
return err
256+
logrus.Warn(err)
257+
258+
c.Response.SetStatusCode(200)
259+
c.Response.SetBody((&apiResp{Code: resp.Code, RawData: resp.RawData, Message: resp.Message}).json())
260+
261+
return nil
245262
}
246263

247264
for _, c := range candlesModel {

0 commit comments

Comments
 (0)