Skip to content

Commit

Permalink
Merge pull request #17 from itsphat/dev
Browse files Browse the repository at this point in the history
Update system
  • Loading branch information
heyphat authored Jan 25, 2022
2 parents 472eb6c + 73da8f6 commit b0752a0
Show file tree
Hide file tree
Showing 42 changed files with 1,313 additions and 776 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
configs/deploy.configs.json
configs/test_results/*
configs/signals/*

internal/cmd/market/test_result
scripts/dev
43 changes: 43 additions & 0 deletions cmd/app/notifier.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package main

import (
"encoding/json"
"net/http"
"sort"
"strconv"
"strings"
"time"

"github.com/gorilla/mux"
)
Expand All @@ -26,3 +29,43 @@ func addChatIDs(w http.ResponseWriter, req *http.Request) {
market.AddChatIDs(cids)
w.WriteHeader(http.StatusOK)
}

func getNotifications(w http.ResponseWriter, req *http.Request) {
notis := market.GetNotifications()
if len(notis) == 0 {
w.WriteHeader(http.StatusOK)
return
}
type Noti struct {
Ticker string `json:"ticker"`
Strategy string `json:"strategy"`
LastSent time.Time `json:"last_sent"`
}
out := struct {
Notis []Noti `json:"notis"`
}{}
for k, v := range notis {
names := strings.Split(k, "-")
if len(names) < 2 {
continue
}
out.Notis = append(out.Notis, Noti{
Ticker: names[0],
Strategy: names[1],
LastSent: v,
})
}
sort.Slice(out.Notis, func(i, j int) bool {
return out.Notis[i].LastSent.After(out.Notis[j].LastSent)
})
bts, err := json.Marshal(out)
if err != nil {
logger.Error.Println(err)
InternalError(w)
return
}
header := w.Header()
header.Set("Content-Length", strconv.Itoa(len(bts)))
w.WriteHeader(http.StatusOK)
w.Write(bts)
}
12 changes: 8 additions & 4 deletions cmd/app/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,22 +108,26 @@ func Mux(middleware Func) *mux.Router {
middleware(http.HandlerFunc(watchlist))).Methods("GET")
router.Handle("/watcher/last/{ticker}",
middleware(http.HandlerFunc(last))).Methods("GET")
router.Handle("/watcher/watch/{ticker}",
middleware(http.HandlerFunc(watch))).Methods("POST")
router.Handle("/watcher/is_synced/{ticker}/{frame}",
middleware(http.HandlerFunc(synced))).Methods("GET")
router.Handle("/watcher/watch/{ticker}",
middleware(http.HandlerFunc(watch))).Methods("POST")
router.Handle("/watcher/drop/{ticker}",
middleware(http.HandlerFunc(dropRunner))).Methods("POST")

// evaluator endpoints
router.Handle("/evaluator/list",
middleware(http.HandlerFunc(listSignals))).Methods("GET")
router.Handle("/evaluator/add_signal/{patterns}",
router.Handle("/evaluator/add/{patterns}",
middleware(http.HandlerFunc(addSignal))).Methods("POST")
router.Handle("/evaluator/drop_signals/{names}",
router.Handle("/evaluator/drop/{names}",
middleware(http.HandlerFunc(dropSignals))).Methods("POST")

// notifier enpoints
router.Handle("/notifier/add_chat_ids/{chat_ids}",
middleware(http.HandlerFunc(addChatIDs))).Methods("POST")
router.Handle("/notifier/get_notifications",
middleware(http.HandlerFunc(getNotifications))).Methods("GET")

// tester endpoints
router.Handle("/tester/test/{ticker}",
Expand Down
49 changes: 41 additions & 8 deletions cmd/app/watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"fmt"
"net/http"
"strconv"
"strings"
"time"

"github.com/gorilla/mux"
Expand All @@ -31,12 +30,37 @@ func watchlist(w http.ResponseWriter, req *http.Request) {
}

func watch(w http.ResponseWriter, req *http.Request) {
str, ok := mux.Vars(req)["ticker"]
tickers, ok := parseVars(mux.Vars(req), "ticker")
if !ok {
w.WriteHeader(http.StatusBadRequest)
return
}
mk, ok := parseOptions(req.URL.Query(), "market")
if !ok {
mk = []string{"CASH"}
}
for _, t := range tickers {
if err := market.Watch(t, mk[0]); err != nil {
logger.Error.Println(err)
InternalError(w)
return
}
}
w.WriteHeader(http.StatusOK)
}

func dropRunner(w http.ResponseWriter, req *http.Request) {
tickers, ok := parseVars(mux.Vars(req), "ticker")
if !ok {
w.WriteHeader(http.StatusBadRequest)
return
}
for _, t := range strings.Split(str, ",") {
if err := market.Watch(t); err != nil {
mk, ok := parseOptions(req.URL.Query(), "market")
if !ok {
mk = []string{"CASH"}
}
for _, t := range tickers {
if err := market.Drop(t, mk[0]); err != nil {
logger.Error.Println(err)
InternalError(w)
return
Expand All @@ -46,17 +70,26 @@ func watch(w http.ResponseWriter, req *http.Request) {
}

func last(w http.ResponseWriter, req *http.Request) {
strs, ok := parseVars(mux.Vars(req), "ticker")
tickers, ok := parseVars(mux.Vars(req), "ticker")
if !ok {
w.WriteHeader(http.StatusBadRequest)
return
}
if !market.IsWatchingOn(strs[0]) {
mk, ok := parseOptions(req.URL.Query(), "market")
if !ok {
mk = []string{"CASH"}
}
//strs, ok := parseVars(mux.Vars(req), "ticker")
//if !ok {
// w.WriteHeader(http.StatusBadRequest)
// return
//}
if !market.IsWatchingOn(tickers[0], mk[0]) {
w.WriteHeader(http.StatusNotFound)
return
}
clast := market.LastCandles(strs[0])
ilast := market.LastIndicators(strs[0])
clast := market.LastCandles(tickers[0])
ilast := market.LastIndicators(tickers[0])
type candles struct {
Candles tax.CandlesJSON `json:"candles"`
Indicators tax.IndicatorsJSON `json:"indicators"`
Expand Down
8 changes: 7 additions & 1 deletion configs/configs.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
"alpaca": {
"api_key": "your_key",
"secret_key": "your_key"
},
"coinmarketcap": {
"api_key": "your_key"
}
},
"notifier": {
Expand All @@ -38,8 +41,9 @@
}
},
"watcher": {
"base_market": "USDT",
"watchlist": [
"(?=(?<!(BUSD|BVND|PAX|DAI|TUSD|USDC|VAI|BRL|AUD|BIRD|EUR|GBP|BIDR|DOWN|UP|BEAR|BULL))USDT)(?=USDT$)"
"(?=(?<!(USDP|SUSD|BUSD|BVND|PAX|DAI|TUSD|USDC|VAI|BRL|AUD|BIRD|EUR|GBP|BIDR|DOWN|UP|BEAR|BULL))USDT)(?=USDT$)"
],
"runner": {
"frames": [
Expand All @@ -48,6 +52,8 @@
"indicators": {
"MovingAverge": [9, 26, 50],
"VolumeMovingAverage": [200],
"LowHighChangeMovingAverage": [200],
"OpenCloseAbsoluteChangeMovingAverage": [200],
"ExponentialMovingAverage": [99, 200],
"BollingerUpperBand": [26, 50],
"BollingerLowerBand": [26, 50],
Expand Down
111 changes: 0 additions & 111 deletions configs/signals/bullish.json

This file was deleted.

37 changes: 0 additions & 37 deletions configs/signals/condition_groups.json

This file was deleted.

32 changes: 0 additions & 32 deletions configs/signals/conditions.json

This file was deleted.

Loading

0 comments on commit b0752a0

Please sign in to comment.