Skip to content

Commit

Permalink
v 1.9
Browse files Browse the repository at this point in the history
  • Loading branch information
aleibovici committed Dec 26, 2021
1 parent 9e4a0c3 commit a0f5901
Show file tree
Hide file tree
Showing 10 changed files with 242 additions and 106 deletions.
54 changes: 20 additions & 34 deletions algorithms/algorithms.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,22 +105,22 @@ func UpdatePendingOrders(
sessionData *types.Session) {

var err error
var orderID int64
var order types.Order
var orderStatus *types.Order

if orderID, _, err = mysql.GetOrderTransactionPending(sessionData); err != nil {
if order, err = mysql.GetOrderTransactionPending(sessionData); err != nil {

/* Cleanly exit ThreadID */
threads.Thread{}.Terminate(sessionData, functions.GetFunctionName()+" - "+err.Error())

}

if orderID != 0 {
if order.OrderID != 0 {

if orderStatus, err = exchange.GetOrder(
configData,
sessionData,
orderID); err != nil {
int64(order.OrderID)); err != nil {

return

Expand Down Expand Up @@ -263,14 +263,9 @@ func isBuyUpmarket(
}

/* This function retrieve the next transaction from Thread database and verify that
the ticker price not half profit close to the transaction.This function avoid multiple
the ticker price is not half profit close to the transaction.This function avoid multiple
upmarket buy close to each other. */
if order.OrderID,
order.Price,
order.ExecutedQuantity,
order.CumulativeQuoteQuantity,
order.TransactTime,
err = mysql.GetThreadLastTransaction(sessionData); err != nil {
if order, err = mysql.GetThreadLastTransaction(sessionData); err != nil {

sessionData.BuyDecisionTreeResult = "Error"

Expand Down Expand Up @@ -1072,18 +1067,21 @@ func SellDecisionTree(

}

/* Force Sell Most recent open order*/
/* Check for Force Sell */
if sessionData.ForceSell {

/* Retrieve the last 'active' BUY transaction for a Thread */
order.OrderID,
order.Price,
order.ExecutedQuantity,
order.CumulativeQuoteQuantity,
order.TransactTime,
_ = mysql.GetThreadLastTransaction(sessionData)
if sessionData.ForceSellOrderID != 0 { /* Force sell a specific orderID */

return true, order
order, err = mysql.GetOrderByOrderID(sessionData) /* Get order details */
sessionData.ForceSellOrderID = 0 /* Clear Force sell OrderID */
return true, order

} else if sessionData.ForceSellOrderID == 0 { /* Force Sell Most recent open order*/

order, err = mysql.GetThreadLastTransaction(sessionData) /* Get order details */
return true, order

}

}

Expand Down Expand Up @@ -1114,12 +1112,7 @@ func SellDecisionTree(
if (sessionData.SymbolFiatFunds - configData.SymbolFiatStash) < configData.BuyQuantityFiatDown {

/* Retrieve the last 'active' BUY transaction for a Thread */
order.OrderID,
order.Price,
order.ExecutedQuantity,
order.CumulativeQuoteQuantity,
order.TransactTime,
_ = mysql.GetThreadLastTransaction(sessionData)
order, err = mysql.GetThreadLastTransaction(sessionData)

if marketData.Price < (order.Price * (1 - configData.BuyRepeatThresholdDown)) {

Expand Down Expand Up @@ -1157,14 +1150,7 @@ func SellDecisionTree(
}

/* Retrieve lowest price order from Thread database */
if order.OrderID,
order.Price,
order.ExecutedQuantity,
order.CumulativeQuoteQuantity,
order.TransactTime,
err = mysql.GetThreadTransactionByPrice(
marketData,
sessionData); err != nil {
if order, err = mysql.GetThreadTransactionByPrice(marketData, sessionData); err != nil {

sessionData.SellDecisionTreeResult = "Error"

Expand Down
6 changes: 4 additions & 2 deletions documentation/HowToUse.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ The higher the value, the more bullish the market needs to be in order to execut

- Diff: this value indicates the difference between current transaction sale price and zero margin sale (includes exchange fee).

- Action [Sell]: The Sell button allows you to execute a sale of an existing order. The 'Diff' lets you know if the order is likely to have a profitable sale or if it is underwater. The sale will occur on the spot market at current market prices.

## STATUS

In the bottom right corner the system status is displayed:
Expand Down Expand Up @@ -141,9 +143,9 @@ In the bottom right corner the system status is displayed:

- Update: write the changes made within the webui into the configuration file.

- Buy market: executes a buy order at the price in that particular moment.
- Buy market: Buy order. The purchase will occur on the spot market at current market prices.

- Sell market: executes a sell order at the price in that particular moment, each press will sell one particular order, press multiple times to sell all.
- Sell market: Sell the top order in the orders table. The sale will occur on the spot market at current market prices.


### TELEGRAM:
Expand Down
24 changes: 23 additions & 1 deletion exchange/exchange.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,17 @@ func BuyTicker(
/* Exit if DryRun mode set to true */
if configData.DryRun {

logger.LogEntry{
Config: configData,
Market: marketData,
Session: sessionData,
Order: &types.Order{
Price: marketData.Price,
},
Message: "BUYDRYRUN",
LogLevel: "InfoLevel",
}.Do()

return

}
Expand Down Expand Up @@ -519,6 +530,17 @@ func SellTicker(
/* Exit if DryRun mode set to true */
if configData.DryRun {

logger.LogEntry{
Config: configData,
Market: marketData,
Session: sessionData,
Order: &types.Order{
Price: marketData.Price,
},
Message: "SELLDRYRUN",
LogLevel: "InfoLevel",
}.Do()

return

}
Expand Down Expand Up @@ -609,7 +631,7 @@ S:
int64(orderResponse.OrderID)); err != nil {

switch {
case strings.Contains(err.Error(), "-2010"), strings.Contains(err.Error(), "-2011"),strings.Contains(err.Error(), "-1021") :
case strings.Contains(err.Error(), "-2010"), strings.Contains(err.Error(), "-2011"), strings.Contains(err.Error(), "-1021"):
/* -2011 Order filled in full before cancelling */
/* -2010 Account has insufficient balance for requested action */
/* -1021 Timestamp for this request was 1000ms ahead of the server's time */
Expand Down
14 changes: 14 additions & 0 deletions logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,13 @@ func (logEntry LogEntry) Do() {
"orderPrice": fmt.Sprintf("%.4f", logEntry.Order.Price),
}).Info(logEntry.Message)

case "BUYDRYRUN":

log.WithFields(log.Fields{
"threadID": logEntry.Session.ThreadID,
"orderPrice": fmt.Sprintf("%.4f", logEntry.Order.Price),
}).Info(logEntry.Message)

case "SELL":

log.WithFields(log.Fields{
Expand All @@ -90,6 +97,13 @@ func (logEntry LogEntry) Do() {
"orderPrice": fmt.Sprintf("%.4f", logEntry.Order.Price),
}).Info(logEntry.Message)

case "SELLDRYRUN":

log.WithFields(log.Fields{
"threadID": logEntry.Session.ThreadID,
"orderPrice": fmt.Sprintf("%.4f", logEntry.Order.Price),
}).Info(logEntry.Message)

case "CANCELED":

if logEntry.Config.Debug {
Expand Down
13 changes: 12 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,18 @@ func (fh *myHandler) handler(w http.ResponseWriter, r *http.Request) {

case "sell":

fh.sessionData.ForceSell = true /* Force sell */
if r.PostFormValue("orderID") == "" { /* Check if the orderID is empty */

fh.sessionData.ForceSellOrderID = 0 /* Force sell most recent order */
fh.sessionData.ForceSell = true /* Force sell */

} else {

fh.sessionData.ForceSellOrderID = functions.StrToInt(r.PostFormValue("orderID")) /* Force sell a specific orderID */
fh.sessionData.ForceSell = true /* Force sell */

}

http.Redirect(w, r, fmt.Sprintf(r.URL.Path), 301) /* Redirect to root 'index' */

case "configTemplate":
Expand Down
99 changes: 74 additions & 25 deletions mysql/cryptopump.sql
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
CREATE DATABASE IF NOT EXISTS `cryptopump` /*!40100 DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci */ /*!80016 DEFAULT ENCRYPTION='N' */;
USE `cryptopump`;
-- MySQL dump 10.13 Distrib 8.0.22, for macos10.15 (x86_64)
-- MySQL dump 10.13 Distrib 8.0.27, for macos11 (x86_64)
--
-- Host: 127.0.0.1 Database: cryptopump
-- ------------------------------------------------------
-- Server version 8.0.23
-- Server version 8.0.27

/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
Expand Down Expand Up @@ -55,7 +55,8 @@ CREATE TABLE `orders` (
`ThreadID` varchar(45) NOT NULL,
`ThreadIDSession` varchar(45) NOT NULL,
PRIMARY KEY (`OrderID`),
UNIQUE KEY `OrderID_UNIQUE` (`OrderID`)
UNIQUE KEY `OrderID_UNIQUE` (`OrderID`),
KEY `orders_idx_side_status` (`Side`,`Status`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

Expand All @@ -77,7 +78,7 @@ CREATE TABLE `session` (
`Status` tinyint(1) NOT NULL,
PRIMARY KEY (`ID`),
UNIQUE KEY `ThreadID_UNIQUE` (`ThreadID`)
) ENGINE=InnoDB AUTO_INCREMENT=1479 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
) ENGINE=InnoDB AUTO_INCREMENT=1565 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
Expand All @@ -96,7 +97,7 @@ CREATE TABLE `thread` (
`Price` float NOT NULL,
`ExecutedQuantity` float NOT NULL,
PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=8928 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
) ENGINE=InnoDB AUTO_INCREMENT=9028 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
Expand Down Expand Up @@ -254,6 +255,40 @@ DELIMITER ;
/*!50003 SET character_set_client = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection = @saved_col_connection */ ;
/*!50003 DROP PROCEDURE IF EXISTS `GetOrderByOrderID` */;
/*!50003 SET @saved_cs_client = @@character_set_client */ ;
/*!50003 SET @saved_cs_results = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client = utf8mb4 */ ;
/*!50003 SET character_set_results = utf8mb4 */ ;
/*!50003 SET collation_connection = utf8mb4_0900_ai_ci */ ;
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `GetOrderByOrderID`(IN in_param_OrderID bigint, IN in_param_ThreadID varchar(45))
BEGIN
DECLARE declared_in_param_orderid BIGINT;
DECLARE declared_in_param_threadid CHAR(50);
SET declared_in_param_orderid = in_param_orderid;
SET declared_in_param_threadid = in_param_threadid;
SELECT
`orders`.`orderid` AS `OrderID`,
`orders`.`price` AS `Price`,
`orders`.`executedquantity` AS `ExecutedQuantity`,
`orders`.`cummulativequoteqty` AS `CummulativeQuoteQty`,
`orders`.`transacttime` AS `TransactTime`
FROM
`orders`
WHERE
(`orders`.`orderid` = declared_in_param_orderid
AND `orders`.`threadid` = declared_in_param_threadid)
LIMIT 1;
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
/*!50003 SET character_set_client = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection = @saved_col_connection */ ;
/*!50003 DROP PROCEDURE IF EXISTS `GetOrderSymbol` */;
/*!50003 SET @saved_cs_client = @@character_set_client */ ;
/*!50003 SET @saved_cs_results = @@character_set_results */ ;
Expand Down Expand Up @@ -405,33 +440,47 @@ DELIMITER ;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `GetProfit`()
BEGIN
SELECT
SUM(`source`.`Profit`) AS `profit`,
SUM(`source`.`Profit`) + (`source`.`Diff`) AS `netprofit`,
AVG(`source`.`Percentage`) AS `avg`
FROM
(SELECT
`orders`.`Side` AS `Side`,
SELECT
SUM(`source`.`Profit`) AS `profit`,
SUM(`source`.`Profit`) + (`source`.`Diff`) AS `netprofit`,
AVG(`source`.`Percentage`) AS `avg`
FROM
(SELECT
`orders`.`Side` AS `Side`,
`Orders`.`Side` AS `Orders__Side`,
`orders`.`Status` AS `Status`,
`Orders`.`Status` AS `Orders__Status`,
`orders`.`ThreadID` AS `ThreadID`,
`Orders`.`CummulativeQuoteQty` AS `Orders__CummulativeQuoteQty`,
`orders`.`CummulativeQuoteQty` AS `CummulativeQuoteQty`,
(`Orders`.`CummulativeQuoteQty` - `orders`.`CummulativeQuoteQty`) AS `Profit`,
((`Orders`.`CummulativeQuoteQty` - `orders`.`CummulativeQuoteQty`) / CASE
WHEN `Orders`.`CummulativeQuoteQty` = 0 THEN NULL
ELSE `Orders`.`CummulativeQuoteQty`
END) AS `Percentage`,
(SELECT sum(`session`.`DiffTotal`) AS `sum` FROM `session`) AS `Diff`
FROM
`orders`
INNER JOIN `orders` `Orders` ON `orders`.`OrderID` = `Orders`.`OrderIDSource`) `source`
((`Orders`.`CummulativeQuoteQty` - `orders`.`CummulativeQuoteQty`) / CASE
WHEN `Orders`.`CummulativeQuoteQty` = 0 THEN NULL
ELSE `Orders`.`CummulativeQuoteQty` END) AS `Percentage`,
(SELECT
sum(`session`.`DiffTotal`) AS `sum`
FROM
`session`) AS `Diff`
FROM
`orders`
INNER JOIN
`orders` `Orders`
ON `orders`.`OrderID` = `Orders`.`OrderIDSource`
WHERE
(`source`.`Side` = 'BUY'
AND `source`.`Orders__Side` = 'SELL'
AND `source`.`Status` = 'FILLED'
AND `source`.`Orders__Status` = 'FILLED');
(
`orders`.`Side` = 'BUY'
)
AND (
`orders`.`Status` = 'FILLED'
)
) `source`
WHERE
(
1 = 1
AND `source`.`Orders__Side` = 'SELL'
AND 1 = 1
AND `source`.`Orders__Status` = 'FILLED'
);
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
Expand Down Expand Up @@ -917,4 +966,4 @@ DELIMITER ;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;

-- Dump completed on 2021-12-08 21:09:38
-- Dump completed on 2021-12-26 8:08:18
Loading

0 comments on commit a0f5901

Please sign in to comment.