Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

position stucked in OPENING state #605

Closed
awikatchikaen opened this issue May 10, 2021 · 13 comments
Closed

position stucked in OPENING state #605

awikatchikaen opened this issue May 10, 2021 · 13 comments
Assignees
Labels
bug Something isn't working
Milestone

Comments

@awikatchikaen
Copy link

I'm in dry/sandbox mode with my kucoin account.

Not sure if it's a bug or misunderstanding but none position are OPENED
logs only show OPENING state for me.

what can cause order not to be fulfilled ? Can i have more logs from cassandre ?

@straumat straumat self-assigned this May 10, 2021
@straumat straumat added the bug Something isn't working label May 10, 2021
@straumat straumat added this to the 4.3.0 milestone May 10, 2021
@straumat
Copy link
Member

Hi it's not normal. Can you show me the values you use for the position creation ?
Can you add a message on onTradeUpdate to see if a trade arrives ?

@straumat
Copy link
Member

straumat commented May 10, 2021

You can get more logs by running this : mvn spring-boot:run -Dspring-boot.run.arguments=--logging.level.tech.cassandre=DEBUG

@awikatchikaen
Copy link
Author

Here's some logs :

Position OPENING : PositionDTO(id=1, positionId=1, type=LONG, strategy=StrategyDTO(id=1, strategyId=1, type=BASIC_TA4J_STRATEGY, name=Simple ta4j strategy, lastPositionIdUsed=0), currencyPair=ETH/USDT, amount=0.3425279557704925537109375 ETH, rules=Stop gain at 5 % / Stop loss at 2 %, status=OPENING, forceClosing=false, openingOrderId=DRY_ORDER_000000001, openingOrder=null, closingOrderId=null, closingOrder=null, lowestGainPrice=null, highestGainPrice=null, latestGainPrice=null)

Trade  : TradeDTO(id=1, tradeId=DRY_TRADE_000000001, type=BID, orderId=DRY_ORDER_000000001, currencyPair=ETH/USDT, amount=0.3425279557704925537109375 ETH, price=2918.75 USDT, fee=0 BTC, userReference=null, timestamp=2021-05-02T06:50+02:00[Europe/Paris])

Position OPENING : PositionDTO(id=2, positionId=2, type=LONG, strategy=StrategyDTO(id=1, strategyId=1, type=BASIC_TA4J_STRATEGY, name=Simple ta4j strategy, lastPositionIdUsed=0), currencyPair=ETH/USDT, amount=0.3075661361217498779296875 ETH, rules=Stop gain at 5 % / Stop loss at 2 %, status=OPENING, forceClosing=false, openingOrderId=DRY_ORDER_000000002, openingOrder=null, closingOrderId=null, closingOrder=null, lowestGainPrice=null, highestGainPrice=null, latestGainPrice=null)

Trade  : TradeDTO(id=2, tradeId=DRY_TRADE_000000002, type=BID, orderId=DRY_ORDER_000000002, currencyPair=ETH/USDT, amount=0.3075661361217498779296875 ETH, price=2920.78 USDT, fee=0 BTC, userReference=null, timestamp=2021-05-02T06:54+02:00[Europe/Paris])

Position OPENING : PositionDTO(id=3, positionId=3, type=LONG, strategy=StrategyDTO(id=1, strategyId=1, type=BASIC_TA4J_STRATEGY, name=Simple ta4j strategy, lastPositionIdUsed=0), currencyPair=ETH/USDT, amount=0.2770150601863861083984375 ETH, rules=Stop gain at 5 % / Stop loss at 2 %, status=OPENING, forceClosing=false, openingOrderId=DRY_ORDER_000000003, openingOrder=null, closingOrderId=null, closingOrder=null, lowestGainPrice=null, highestGainPrice=null, latestGainPrice=null)

Position OPENING : PositionDTO(id=4, positionId=4, type=LONG, strategy=StrategyDTO(id=1, strategyId=1, type=BASIC_TA4J_STRATEGY, name=Simple ta4j strategy, lastPositionIdUsed=0), currencyPair=ETH/USDT, amount=0.2497080862522125244140625 ETH, rules=Stop gain at 5 % / Stop loss at 2 %, status=OPENING, forceClosing=false, openingOrderId=DRY_ORDER_000000004, openingOrder=null, closingOrderId=null, closingOrder=null, lowestGainPrice=null, highestGainPrice=null, latestGainPrice=null)

Trade  : TradeDTO(id=3, tradeId=DRY_TRADE_000000003, type=BID, orderId=DRY_ORDER_000000003, currencyPair=ETH/USDT, amount=0.2770150601863861083984375 ETH, price=2920.21 USDT, fee=0 BTC, userReference=null, timestamp=2021-05-02T07:01+02:00[Europe/Paris])

Trade  : TradeDTO(id=4, tradeId=DRY_TRADE_000000004, type=BID, orderId=DRY_ORDER_000000004, currencyPair=ETH/USDT, amount=0.2497080862522125244140625 ETH, price=2919.27 USDT, fee=0 BTC, userReference=null, timestamp=2021-05-02T07:02+02:00[Europe/Paris])

Position OPENING : PositionDTO(id=5, positionId=5, type=LONG, strategy=StrategyDTO(id=1, strategyId=1, type=BASIC_TA4J_STRATEGY, name=Simple ta4j strategy, lastPositionIdUsed=0), currencyPair=ETH/USDT, amount=0.22485072910785675048828125 ETH, rules=Stop gain at 5 % / Stop loss at 2 %, status=OPENING, forceClosing=false, openingOrderId=DRY_ORDER_000000005, openingOrder=null, closingOrderId=null, closingOrder=null, lowestGainPrice=null, highestGainPrice=null, latestGainPrice=null)

Trade  : TradeDTO(id=5, tradeId=DRY_TRADE_000000005, type=BID, orderId=DRY_ORDER_000000005, currencyPair=ETH/USDT, amount=0.22485072910785675048828125 ETH, price=2920.87 USDT, fee=0 BTC, userReference=null, timestamp=2021-05-02T07:03+02:00[Europe/Paris])

Position OPENING : PositionDTO(id=6, positionId=6, type=LONG, strategy=StrategyDTO(id=1, strategyId=1, type=BASIC_TA4J_STRATEGY, name=Simple ta4j strategy, lastPositionIdUsed=0), currencyPair=ETH/USDT, amount=0.2022342681884765625 ETH, rules=Stop gain at 5 % / Stop loss at 2 %, status=OPENING, forceClosing=false, openingOrderId=DRY_ORDER_000000006, openingOrder=null, closingOrderId=null, closingOrder=null, lowestGainPrice=null, highestGainPrice=null, latestGainPrice=null)

Trade  : TradeDTO(id=6, tradeId=DRY_TRADE_000000006, type=BID, orderId=DRY_ORDER_000000006, currencyPair=ETH/USDT, amount=0.2022342681884765625 ETH, price=2918.03 USDT, fee=0 BTC, userReference=null, timestamp=2021-05-02T07:04+02:00[Europe/Paris])

@straumat
Copy link
Member

Thx! what release do you use?
Can you add a log on orders too ? Thx

@straumat
Copy link
Member

Your position amount amount=0.3425279557704925537109375 ETH is different from the trade amount amount=0.3075661361217498779296875 ETH. This is very strange, as the trade created by Cassandre uses the amount in the position. and here, it's different (explaining why it's stuck in OPENING).
Can you copy/pase code me the code of the position creation ? Thx

@awikatchikaen
Copy link
Author

nothing special here :

if (canBuy(new BigDecimal(qteToBuy))) {
                // Create rules.
                PositionRulesDTO rules = PositionRulesDTO
                        .builder()
                        .stopGainPercentage(TAKE_PROFIT_PERCENTAGE)
                        .stopLossPercentage(STOP_LOSS_PERCENTAGE)
                        .build();
                // Create position.
                createLongPosition(
                        new CurrencyPairDTO(ETH, USDT),
                        new BigDecimal(qteToBuy),
                        rules);
            }

@straumat
Copy link
Member

Can you provide the value of the constants, I want to reproduce your code in a unit test.

@awikatchikaen
Copy link
Author

awikatchikaen commented May 10, 2021

tradingbot.stoploss=2
tradingbot.takeprofit=5


    @Value("${tradingbot.stoploss}")
    public Float STOP_LOSS_PERCENTAGE;

    @Value("${tradingbot.takeprofit}")
    public Float TAKE_PROFIT_PERCENTAGE;

Seems var qteToBuy type is source of problem.
double and float doesn't open position but integer do

@straumat
Copy link
Member

@awikatchikaen you have to use BigDecimal for amount! can you try ?

@awikatchikaen
Copy link
Author

It's converted to bigDecimal.
I've tried this code :

      BigDecimal qteToBuy= new BigDecimal(0.1);
...
           if (canBuy(qteToBuy)) {
               // Create rules.
               PositionRulesDTO rules = PositionRulesDTO
                       .builder()
                       .stopGainPercentage(TAKE_PROFIT_PERCENTAGE)
                       .stopLossPercentage(STOP_LOSS_PERCENTAGE)
                       .build();
               // Create position.
               createLongPosition(
                       new CurrencyPairDTO(ETH, USDT),
                       qteToBuy,
                       rules);
           }

but still nothing : 


 > Position OPENING : PositionDTO(id=1, positionId=1, type=LONG, strategy=StrategyDTO(id=1, strategyId=1, type=BASIC_TA4J_STRATEGY, name=Simple ta4j strategy, lastPositionIdUsed=0), currencyPair=ETH/USDT, amount=0.1000000000000000055511151231257827021181583404541015625 ETH, rules=Stop gain at 5 % / Stop loss at 2 %, status=OPENING, forceClosing=false, openingOrderId=DRY_ORDER_000000001, openingOrder=null, closingOrderId=null, closingOrder=null, lowestGainPrice=null, highestGainPrice=null, latestGainPrice=null)
 > Trade  : TradeDTO(id=1, tradeId=DRY_TRADE_000000001, type=BID, orderId=DRY_ORDER_000000001, currencyPair=ETH/USDT, amount=0.1000000000000000055511151231257827021181583404541015625 ETH, price=2918.75 USDT, fee=0 BTC, userReference=null, timestamp=2021-05-02T06:50+02:00[Europe/Paris])
 > Position OPENING : PositionDTO(id=2, positionId=2, type=LONG, strategy=StrategyDTO(id=1, strategyId=1, type=BASIC_TA4J_STRATEGY, name=Simple ta4j strategy, lastPositionIdUsed=0), currencyPair=ETH/USDT, amount=0.1000000000000000055511151231257827021181583404541015625 ETH, rules=Stop gain at 5 % / Stop loss at 2 %, status=OPENING, forceClosing=false, openingOrderId=DRY_ORDER_000000002, openingOrder=null, closingOrderId=null, closingOrder=null, lowestGainPrice=null, highestGainPrice=null, latestGainPrice=null)
 > Trade  : TradeDTO(id=2, tradeId=DRY_TRADE_000000002, type=BID, orderId=DRY_ORDER_000000002, currencyPair=ETH/USDT, amount=0.1000000000000000055511151231257827021181583404541015625 ETH, price=2920.78 USDT, fee=0 BTC, userReference=null, timestamp=2021-05-02T06:54+02:00[Europe/Paris])

@straumat
Copy link
Member

@awikatchikaen you have to write BigDecimal qteToBuy= new BigDecimal("0.1");

@awikatchikaen
Copy link
Author

ok, that works with the quote.
But BigDecimal are not useful for math operation (I made some calcul to know amount to buy).
I'll do with it for now, but it's weird that what follow doesn't work

        Double qte= 0.1;
        BigDecimal qteToBuy = new BigDecimal(qte);

if (canBuy(qteToBuy)) {
               // Create rules.
               PositionRulesDTO rules = PositionRulesDTO
                       .builder()
                       .stopGainPercentage(TAKE_PROFIT_PERCENTAGE)
                       .stopLossPercentage(STOP_LOSS_PERCENTAGE)
                       .build();
               // Create position.
               createLongPosition(
                       new CurrencyPairDTO(ETH, USDT),
                       qteToBuy,
                       rules);
           }

@straumat
Copy link
Member

@awikatchikaen I completely agree with that BigDecimal are really not fun! (they are one of the reasons why I created position so most calculus will be made in my code) but working with cryptocurrency and all their digits, you need BigDecimal precision

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants