mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-06-08 15:11:07 +00:00
exchanges: Initial context propagation (#744)
* gct: phase one context awareness pass * exchanges: context propagation pass * common/requester: force context requirement * gctcli/exchanges: linter fix * rpcserver: fix test using dummy rpc server * backtester: fix comments * grpc: add correct cancel and timeout for commands * rpcserver_test: add comment on dummy server * common: deprecated SendHTTPGetRequest * linter: fix * linter: turn on no context check * apichecker: fix context linter issue * binance: use param context * common: remove checks as this gets executed before main * common: change mutex to RW as clients can be used by multiple go routines. * common: remove init and JIT default client. Unexport global variables and add protection. * common: Add comments * bithumb: after dinner mints fix
This commit is contained in:
@@ -71,9 +71,11 @@ const (
|
||||
)
|
||||
|
||||
var (
|
||||
verbose, add, create, testMode bool
|
||||
apiKey, apiToken, trelloBoardID, trelloBoardName, trelloListID, trelloChecklistID, trelloCardID, exchangeName, checkType, tokenData, key, val, tokenDataEnd, textTokenData, dateFormat, regExp, checkString, path string
|
||||
configData, testConfigData, usageData Config
|
||||
verbose, add, create, testMode bool
|
||||
apiKey, apiToken, trelloBoardID, trelloBoardName, trelloListID,
|
||||
trelloChecklistID, trelloCardID, exchangeName, checkType, tokenData,
|
||||
key, val, tokenDataEnd, textTokenData, dateFormat, regExp, path string
|
||||
configData, testConfigData, usageData Config
|
||||
)
|
||||
|
||||
func main() {
|
||||
@@ -606,9 +608,9 @@ func fillData(exchName, checkType string, data interface{}) (ExchangeInfo, error
|
||||
// htmlScrapeDefault gets check string data for the default cases
|
||||
func htmlScrapeDefault(htmlData *HTMLScrapingData) ([]string, error) {
|
||||
var resp []string
|
||||
temp, err := http.Get(htmlData.Path)
|
||||
temp, err := sendHTTPGetRequest(htmlData.Path, nil)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
return nil, err
|
||||
}
|
||||
defer temp.Body.Close()
|
||||
tokenizer := html.NewTokenizer(temp.Body)
|
||||
@@ -660,13 +662,14 @@ loop:
|
||||
|
||||
// htmlScrapeBTSE gets the check string for BTSE exchange
|
||||
func htmlScrapeBTSE(htmlData *HTMLScrapingData) ([]string, error) {
|
||||
var resp []string
|
||||
temp, err := http.Get(htmlData.Path)
|
||||
temp, err := sendHTTPGetRequest(htmlData.Path, nil)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
return nil, err
|
||||
}
|
||||
defer temp.Body.Close()
|
||||
tokenizer := html.NewTokenizer(temp.Body)
|
||||
|
||||
var resp []string
|
||||
loop:
|
||||
for {
|
||||
next := tokenizer.Next()
|
||||
@@ -693,9 +696,9 @@ loop:
|
||||
// htmlScrapeBitmex gets the check string for Bitmex exchange
|
||||
func htmlScrapeBitmex(htmlData *HTMLScrapingData) ([]string, error) {
|
||||
var resp []string
|
||||
temp, err := http.Get(htmlData.Path)
|
||||
temp, err := sendHTTPGetRequest(htmlData.Path, nil)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
return nil, err
|
||||
}
|
||||
defer temp.Body.Close()
|
||||
tokenizer := html.NewTokenizer(temp.Body)
|
||||
@@ -731,11 +734,12 @@ loop:
|
||||
|
||||
// htmlScrapeHitBTC gets the check string for HitBTC Exchange
|
||||
func htmlScrapeHitBTC(htmlData *HTMLScrapingData) ([]string, error) {
|
||||
temp, err := http.Get(htmlData.Path)
|
||||
temp, err := sendHTTPGetRequest(htmlData.Path, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer temp.Body.Close()
|
||||
|
||||
a, err := ioutil.ReadAll(temp.Body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -766,9 +770,9 @@ func htmlScrapeHitBTC(htmlData *HTMLScrapingData) ([]string, error) {
|
||||
// htmlScrapeBTCMarkets gets the check string for BTCMarkets exchange
|
||||
func htmlScrapeBTCMarkets(htmlData *HTMLScrapingData) ([]string, error) {
|
||||
var resp []string
|
||||
temp, err := http.Get(htmlData.Path)
|
||||
temp, err := sendHTTPGetRequest(htmlData.Path, nil)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
return nil, err
|
||||
}
|
||||
defer temp.Body.Close()
|
||||
tempData, err := ioutil.ReadAll(temp.Body)
|
||||
@@ -787,9 +791,9 @@ func htmlScrapeBTCMarkets(htmlData *HTMLScrapingData) ([]string, error) {
|
||||
// htmlScrapeOk gets the check string for Okex
|
||||
func htmlScrapeOk(htmlData *HTMLScrapingData) ([]string, error) {
|
||||
var resp []string
|
||||
temp, err := http.Get(htmlData.Path)
|
||||
temp, err := sendHTTPGetRequest(htmlData.Path, nil)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
return nil, err
|
||||
}
|
||||
defer temp.Body.Close()
|
||||
tokenizer := html.NewTokenizer(temp.Body)
|
||||
@@ -841,11 +845,12 @@ loop:
|
||||
|
||||
// htmlScrapeANX gets the check string for BTCMarkets exchange
|
||||
func htmlScrapeANX(htmlData *HTMLScrapingData) ([]string, error) {
|
||||
temp, err := http.Get(htmlData.Path)
|
||||
temp, err := sendHTTPGetRequest(htmlData.Path, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer temp.Body.Close()
|
||||
|
||||
a, err := ioutil.ReadAll(temp.Body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -875,16 +880,15 @@ func htmlScrapeANX(htmlData *HTMLScrapingData) ([]string, error) {
|
||||
|
||||
// htmlScrapeExmo gets the check string for Exmo Exchange
|
||||
func htmlScrapeExmo(htmlData *HTMLScrapingData) ([]string, error) {
|
||||
temp, err := http.NewRequest(http.MethodGet, htmlData.Path, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
temp.Header.Set("User-Agent", "GCT")
|
||||
httpClient := &http.Client{}
|
||||
httpResp, err := httpClient.Do(temp)
|
||||
header := map[string]string{
|
||||
"User-Agent": "GCT",
|
||||
}
|
||||
|
||||
httpResp, err := sendHTTPGetRequest(htmlData.Path, header)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
defer httpResp.Body.Close()
|
||||
a, err := ioutil.ReadAll(httpResp.Body)
|
||||
if err != nil {
|
||||
@@ -902,9 +906,9 @@ func htmlScrapeExmo(htmlData *HTMLScrapingData) ([]string, error) {
|
||||
// htmlScrapePoloniex gets the check string for Poloniex Exchange
|
||||
func htmlScrapePoloniex(htmlData *HTMLScrapingData) ([]string, error) {
|
||||
var resp []string
|
||||
temp, err := http.Get(htmlData.Path)
|
||||
temp, err := sendHTTPGetRequest(htmlData.Path, nil)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
return nil, err
|
||||
}
|
||||
defer temp.Body.Close()
|
||||
tokenizer := html.NewTokenizer(temp.Body)
|
||||
@@ -955,9 +959,9 @@ loop:
|
||||
// htmlScrapeItBit gets the check string for ItBit Exchange
|
||||
func htmlScrapeItBit(htmlData *HTMLScrapingData) ([]string, error) {
|
||||
var resp []string
|
||||
temp, err := http.Get(htmlData.Path)
|
||||
temp, err := sendHTTPGetRequest(htmlData.Path, nil)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
return nil, err
|
||||
}
|
||||
defer temp.Body.Close()
|
||||
tokenizer := html.NewTokenizer(temp.Body)
|
||||
@@ -989,11 +993,12 @@ loop:
|
||||
|
||||
// htmlScrapeBitstamp gets the check string for Bitstamp Exchange
|
||||
func htmlScrapeBitstamp(htmlData *HTMLScrapingData) ([]string, error) {
|
||||
temp, err := http.Get(htmlData.Path)
|
||||
temp, err := sendHTTPGetRequest(htmlData.Path, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer temp.Body.Close()
|
||||
|
||||
a, err := ioutil.ReadAll(temp.Body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -1010,9 +1015,9 @@ func htmlScrapeBitstamp(htmlData *HTMLScrapingData) ([]string, error) {
|
||||
// htmlScrapeAlphaPoint gets the check string for Kraken Exchange
|
||||
func htmlScrapeAlphaPoint(htmlData *HTMLScrapingData) ([]string, error) {
|
||||
var resp []string
|
||||
temp, err := http.Get(htmlData.Path)
|
||||
temp, err := sendHTTPGetRequest(htmlData.Path, nil)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
return nil, err
|
||||
}
|
||||
defer temp.Body.Close()
|
||||
tokenizer := html.NewTokenizer(temp.Body)
|
||||
@@ -1065,9 +1070,9 @@ loop:
|
||||
// htmlScrapeYobit gets the check string for Yobit Exchange
|
||||
func htmlScrapeYobit(htmlData *HTMLScrapingData) ([]string, error) {
|
||||
var resp []string
|
||||
temp, err := http.Get(htmlData.Path)
|
||||
temp, err := sendHTTPGetRequest(htmlData.Path, nil)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
return nil, err
|
||||
}
|
||||
defer temp.Body.Close()
|
||||
tokenizer := html.NewTokenizer(temp.Body)
|
||||
@@ -1123,11 +1128,12 @@ loop:
|
||||
|
||||
// htmlScrapeLocalBitcoins gets the check string for Yobit Exchange
|
||||
func htmlScrapeLocalBitcoins(htmlData *HTMLScrapingData) ([]string, error) {
|
||||
temp, err := http.Get(htmlData.Path)
|
||||
temp, err := sendHTTPGetRequest(htmlData.Path, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer temp.Body.Close()
|
||||
|
||||
a, err := ioutil.ReadAll(temp.Body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -1463,9 +1469,9 @@ func trelloCreateNewChecklist() error {
|
||||
// htmlScrapeKraken gets the check string for Kraken Exchange
|
||||
func htmlScrapeKraken(htmlData *HTMLScrapingData) ([]string, error) {
|
||||
var resp []string
|
||||
temp, err := http.Get(htmlData.Path)
|
||||
temp, err := sendHTTPGetRequest(htmlData.Path, nil)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
return nil, err
|
||||
}
|
||||
defer temp.Body.Close()
|
||||
tokenizer := html.NewTokenizer(temp.Body)
|
||||
@@ -1520,9 +1526,9 @@ loop:
|
||||
func htmlScrapeBitflyer(htmlData *HTMLScrapingData) ([]string, error) {
|
||||
var resp []string
|
||||
var tempArray []string
|
||||
temp, err := http.Get(htmlData.Path)
|
||||
temp, err := sendHTTPGetRequest(htmlData.Path, nil)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
return nil, err
|
||||
}
|
||||
defer temp.Body.Close()
|
||||
tokenizer := html.NewTokenizer(temp.Body)
|
||||
@@ -1571,7 +1577,7 @@ loop:
|
||||
|
||||
// htmlScrapeFTX gets the check string for FTX exchange
|
||||
func htmlScrapeFTX(htmlData *HTMLScrapingData) ([]string, error) {
|
||||
temp, err := http.Get(htmlData.Path)
|
||||
temp, err := sendHTTPGetRequest(htmlData.Path, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -1660,11 +1666,12 @@ loop:
|
||||
|
||||
// htmlScrapeBitfinex gets the check string for Bitfinex exchange
|
||||
func htmlScrapeBitfinex(htmlData *HTMLScrapingData) ([]string, error) {
|
||||
temp, err := http.Get(htmlData.Path)
|
||||
temp, err := sendHTTPGetRequest(htmlData.Path, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer temp.Body.Close()
|
||||
|
||||
a, err := ioutil.ReadAll(temp.Body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -1693,11 +1700,12 @@ func htmlScrapeBitfinex(htmlData *HTMLScrapingData) ([]string, error) {
|
||||
|
||||
// htmlScrapeBinance gets checkstring for binance exchange
|
||||
func htmlScrapeBinance(htmlData *HTMLScrapingData) ([]string, error) {
|
||||
temp, err := http.Get(htmlData.Path)
|
||||
temp, err := sendHTTPGetRequest(htmlData.Path, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer temp.Body.Close()
|
||||
|
||||
tokenizer := html.NewTokenizer(temp.Body)
|
||||
var resp []string
|
||||
loop:
|
||||
@@ -1744,3 +1752,18 @@ loop:
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func sendHTTPGetRequest(path string, headers map[string]string) (*http.Response, error) {
|
||||
req, err := http.NewRequestWithContext(context.TODO(),
|
||||
http.MethodGet,
|
||||
path,
|
||||
nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for k, v := range headers {
|
||||
req.Header.Set(k, v)
|
||||
}
|
||||
return http.DefaultClient.Do(req)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user