Skip to content

Commit

Permalink
v2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
aleibovici committed Feb 1, 2022
1 parent f4d5b13 commit 70a58fe
Show file tree
Hide file tree
Showing 9 changed files with 768 additions and 118 deletions.
11 changes: 10 additions & 1 deletion .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
uses: docker/build-push-action@v2
with:
context: .
platforms: linux/amd64
platforms: linux/amd64,linux/arm/v7
file: ./Dockerfile.cryptopump
push: true
tags: ${{ secrets.DOCKER_HUB_USERNAME }}/cryptopump:latest
Expand All @@ -45,5 +45,14 @@ jobs:
push: true
tags: ${{ secrets.DOCKER_HUB_USERNAME }}/cryptopump_db:latest

- name: Build and push
uses: docker/build-push-action@v2
with:
context: .
platforms: linux/arm/v7
file: ./Dockerfile.mariadb
push: true
tags: ${{ secrets.DOCKER_HUB_USERNAME }}/cryptopump_mariadb:latest

- name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }}
2 changes: 2 additions & 0 deletions Dockerfile.mariadb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
FROM yobasystems/alpine-mariadb:10.4.17-armhf
COPY /mysql/cryptopump-mariadb.sql /docker-entrypoint-initdb.d/init.sql
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ CryptoPump is a cryptocurrency trading tool that focuses on extremely high speed
Do not risk money which you are afraid to lose. USE THE SOFTWARE AT YOUR OWN RISK. THE AUTHORS AND ALL AFFILIATES ASSUME NO RESPONSIBILITY FOR YOUR TRADING RESULTS.

Always start by running a this trading tool in Dry-run or TestNet and do not engage money before you understand how it works and what profit/loss you should expect.
#### - CryptoPump is now available as a self-contained Docker container set. Check it out at https://hub.docker.com/repository/docker/andreleibovici/cryptopump
#### - CryptoPump is now available as a self-contained Docker container set for linux/amd64 and linux/arm/v7 (Raspberry Pi). Check it out at https://hub.docker.com/repository/docker/andreleibovici/cryptopump

- CryptoPump is a cryptocurrency trading tool that focuses on extremely high speed and flexibility. The algorithms utilize Go Language and the exchange WebSockets to react in real-time to market movements based on Bollinger statistical analysis and pre-defined profit margins.

Expand Down
154 changes: 45 additions & 109 deletions algorithms/algorithms.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package algorithms
import (
"encoding/json"
"errors"
"fmt"
"strings"
"sync"
"time"

Expand Down Expand Up @@ -578,50 +576,33 @@ func WsUserDataServe(
LogLevel: "DebugLevel",
}.Do()

switch {
case strings.Contains(err.Error(), "1001"):
/* -1001 DISCONNECTED Internal error; unable to process your request. Please try again. */

exchange.GetClient(configData, sessionData) /* Reconnect exchange client */

case strings.Contains(err.Error(), "1006"):
/* -1006 UNEXPECTED_RESP An unexpected response was received from the message bus. Execution status unknown. */
/* Error Codes for Binance https://github.com/binance/binance-spot-api-docs/blob/master/errors.md */

exchange.GetClient(configData, sessionData) /* Reconnect exchange client */
}

case strings.Contains(err.Error(), "read: operation timed out"):
/* read tcp X.X.X.X:port->X.X.X.X:port: read: operation timed out */
for {

exchange.GetClient(configData, sessionData) /* Reconnect exchange client */
doneC, stopC, err = exchange.WsUserDataServe(configData, sessionData, wsHandler, errHandler) /* Start websocket channel */

case strings.Contains(err.Error(), "read: connection reset by peer"):
/* read tcp X.X.X.X:port->X.X.X.X:port: read: connection reset by peer */
if err != nil { /* If websocket channel is not connected */

exchange.GetClient(configData, sessionData) /* Reconnect exchange client */
panic(err) /* Panic */

}

Channel{}.SetTrue(sessionData) /* Set all goroutine channels to stop */
Channel{
name: "WsUserDataServe",
}.Stop(stopC, wg, configData, sessionData) /* Stop goroutine channel */

/* Retrieve NEW WsUserDataServe listen key for user stream service when there's an error */
sessionData.ListenKey, err = exchange.GetUserStreamServiceListenKey(configData, sessionData)

}

doneC, stopC, err = exchange.WsUserDataServe(configData, sessionData, wsHandler, errHandler)
<-doneC

if err != nil {
logger.LogEntry{ /* Log Entry */
Config: configData,
Market: nil,
Session: sessionData,
Order: &types.Order{},
Message: functions.GetFunctionName() + " - " + "websocket channel disconnected, trying to re-establish",
LogLevel: "DebugLevel",
}.Do()

fmt.Println(err)
time.Sleep(time.Second / 3) /* Sleep for 3 seconds */

}

<-doneC

}

// WsKline The Kline/Candlestick Stream push updates to the current klines/candlestick every second.
Expand Down Expand Up @@ -696,52 +677,33 @@ func WsKline(
LogLevel: "DebugLevel",
}.Do()

switch {
case strings.Contains(err.Error(), "1006"):
/* -1006 UNEXPECTED_RESP An unexpected response was received from the message bus. Execution status unknown. */
/* Error Codes for Binance https://github.com/binance/binance-spot-api-docs/blob/master/errors.md */

exchange.GetClient(configData, sessionData) /* Reconnect exchange client */

case strings.Contains(err.Error(), "EOF"):
/* -unexpected EOF An unexpected response was received from the message bus. Execution status unknown. */

return

case strings.Contains(err.Error(), "1001"):
/* -1001 DISCONNECTED Internal error; unable to process your request. Please try again. */

exchange.GetClient(configData, sessionData) /* Reconnect exchange client */
}

case strings.Contains(err.Error(), "read: operation timed out"):
/* read tcp X.X.X.X:port->X.X.X.X:port: read: operation timed out */
for {

exchange.GetClient(configData, sessionData) /* Reconnect exchange client */
doneC, stopC, err = exchange.WsKlineServe(configData, sessionData, wsHandler, errHandler) /* Start websocket channel */

case strings.Contains(err.Error(), "read: connection reset by peer"):
/* read tcp X.X.X.X:port->X.X.X.X:port: read: connection reset by peer */
if err != nil { /* If websocket channel is not connected */

exchange.GetClient(configData, sessionData) /* Reconnect exchange client */
panic(err) /* Panic */

}

Channel{}.SetTrue(sessionData) /* Set all goroutine channels to stop */
Channel{
name: "WsKline",
}.Stop(stopC, wg, configData, sessionData) /* Stop goroutine channel */

}

doneC, stopC, err = exchange.WsKlineServe(configData, sessionData, wsHandler, errHandler)
<-doneC

if err != nil {
logger.LogEntry{ /* Log Entry */
Config: configData,
Market: marketData,
Session: sessionData,
Order: &types.Order{},
Message: functions.GetFunctionName() + " - " + "websocket channel disconnected, trying to re-establish",
LogLevel: "DebugLevel",
}.Do()

fmt.Println(err)
time.Sleep(time.Second / 3) /* Sleep for 3 seconds */

}

<-doneC

}

// WsBookTicker Pushes any update to the best bid or asks price or quantity in real-time for a specified symbol
Expand Down Expand Up @@ -854,59 +816,33 @@ func WsBookTicker(
LogLevel: "DebugLevel",
}.Do()

switch {
case strings.Contains(err.Error(), "1006"):
/* -1006 UNEXPECTED_RESP An unexpected response was received from the message bus. Execution status unknown. */
/* Error Codes for Binance https://github.com/binance/binance-spot-api-docs/blob/master/errors.md */

exchange.GetClient(configData, sessionData) /* Reconnect exchange client */

case strings.Contains(err.Error(), "1008"):
/* websocket: close 1008 (policy violation): Pong timeout */
/* 1008 indicates that an endpoint is terminating the connection
because it has received a message that violates its policy. This
is a generic status code that can be returned when there is no
other more suitable status code (e.g., 1003 or 1009) or if there
is a need to hide specific details about the policy. */

exchange.GetClient(configData, sessionData) /* Reconnect exchange client */

return

case strings.Contains(err.Error(), "EOF"):
/* -unexpected EOF An unexpected response was received from the message bus. Execution status unknown. */

return
}

case strings.Contains(err.Error(), "read: operation timed out"):
/* read tcp X.X.X.X:port->X.X.X.X:port: read: operation timed out */
for {

exchange.GetClient(configData, sessionData) /* Reconnect exchange client */
doneC, stopC, err = exchange.WsBookTickerServe(configData, sessionData, wsHandler, errHandler) /* Start websocket channel */

case strings.Contains(err.Error(), "read: connection reset by peer"):
/* read tcp X.X.X.X:port->X.X.X.X:port: read: connection reset by peer */
if err != nil { /* If websocket channel is not connected */

exchange.GetClient(configData, sessionData) /* Reconnect exchange client */
panic(err) /* Panic */

}

Channel{}.SetTrue(sessionData) /* Set all goroutine channels to stop */
Channel{
name: "WsBookTicker",
}.Stop(stopC, wg, configData, sessionData) /* Stop goroutine channel */

}
<-doneC

doneC, stopC, err = exchange.WsBookTickerServe(configData, sessionData, wsHandler, errHandler)

if err != nil {
logger.LogEntry{ /* Log Entry */
Config: configData,
Market: marketData,
Session: sessionData,
Order: &types.Order{},
Message: functions.GetFunctionName() + " - " + "websocket channel disconnected, trying to re-establish",
LogLevel: "DebugLevel",
}.Do()

fmt.Println(err)
time.Sleep(time.Second / 3) /* Sleep for 3 seconds */

}

<-doneC

}

// BuyDecisionTree BUY decision routine
Expand Down
4 changes: 3 additions & 1 deletion documentation/HowToInstall.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
## HOW TO INSTALL

Cryptopump can be used on Windows and Linux (with a MYSQL database is present and usable) or in a self-contained Docker environment.
Cryptopump can be used on Windows or Linux (with a MySQL or MariaDB database) or in a self-contained Docker environment.

### DOCKER:

#### - CryptoPump is now available as a self-contained Docker container set for linux/amd64 and linux/arm/v7 (Raspberry Pi). Check it out at https://hub.docker.com/repository/docker/andreleibovici/cryptopump

This is the easiest way to get CryptoPump up and running. The Docker Compose file provides all the necessary components to run the system.

1 - Create a directory for the project.
Expand Down
47 changes: 47 additions & 0 deletions documentation/docker-compose-rpi-example.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
version: '3.6'

services:

cryptopump_db:
image: andreleibovici/cryptopump_mariadb:latest
container_name: cryptopump_db
environment:
MYSQL_ROOT_PASSWORD: password # change this
ports:
- "3306:3306"
tty: true
cap_add:
- SYS_NICE # CAP_SYS_NICE
volumes:
- db_data:/var/lib/mysql # database files
- /etc/localtime:/etc/localtime:ro # timezone
networks:
- backend

cryptopump_app:
image: andreleibovici/cryptopump:latest
container_name: cryptopump_app
restart: always
environment:
- DB_USER=root
- DB_PASS=password # change this
- DB_TCP_HOST=cryptopump_db
- DB_PORT=3306
- DB_NAME=cryptopump
ports:
- "8080-8090:8080-8090"
tty: true
volumes:
- config_data:/go/src/cryptopump/config # config files
- /etc/localtime:/etc/localtime:ro # timezone
networks:
- backend
depends_on:
- cryptopump_db

networks:
backend:

volumes:
db_data:
config_data:
4 changes: 2 additions & 2 deletions exchange/binance.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,8 @@ func binanceMapExchangeInfo(sessionData *types.Session, from *binance.ExchangeIn
func binanceGetClient(
configData *types.Config) *binance.Client {

binance.WebsocketKeepalive = false
binance.WebsocketTimeout = time.Second * 30
binance.WebsocketKeepalive = false /* Disable websocket keepalive */
binance.WebsocketTimeout = time.Second * 100 /* Set websocket timeout */

/* If the -test.v flag is set, the testnet API is used */
if flag.Lookup("test.v") != nil {
Expand Down
Loading

0 comments on commit 70a58fe

Please sign in to comment.