Search in sources :

Example 11 with BitfinexOrder

use of com.github.jnidzwetzki.bitfinex.v2.entity.BitfinexOrder in project crypto-bot by jnidzwetzki.

the class TestPersistence method testTradePersistence.

/**
 * Test testade persistence
 */
@Test
public void testTradePersistence() {
    final BitfinexOrder order = new BitfinexOrder(BitfinexCurrencyPair.BTC_USD, BitfinexOrderType.EXCHANGE_LIMIT, 0, 0, 0, 0, false, false, -1);
    final Trade trade = new Trade("ABC", TradeDirection.LONG, BitfinexCurrencyPair.BTC_USD, 1);
    trade.getOrdersOpen().add(order);
    trade.setTradeState(TradeState.OPEN);
    final Session session = sessionFactory.openSession();
    session.beginTransaction();
    @SuppressWarnings("unchecked") final List<Trade> result1 = session.createQuery("from Trade t").list();
    Assert.assertTrue(result1.isEmpty());
    session.save(trade);
    session.getTransaction().commit();
    session.beginTransaction();
    @SuppressWarnings("unchecked") final List<Trade> result2 = session.createQuery("from Trade t").list();
    session.getTransaction().commit();
    session.close();
    Assert.assertEquals(1, result2.size());
}
Also used : Trade(com.github.jnidzwetzki.cryptobot.entity.Trade) BitfinexOrder(com.github.jnidzwetzki.bitfinex.v2.entity.BitfinexOrder) Session(org.hibernate.Session) Test(org.junit.Test)

Example 12 with BitfinexOrder

use of com.github.jnidzwetzki.bitfinex.v2.entity.BitfinexOrder in project bitfinex-v2-wss-api-java by jnidzwetzki.

the class CommandsTest method testOrderCommand.

/**
 * Test the order command
 * @throws CommandException
 */
@Test
public void testOrderCommand() throws CommandException {
    final BitfinexOrder order = BitfinexOrderBuilder.create(BitfinexCurrencyPair.BCH_USD, BitfinexOrderType.EXCHANGE_STOP, 2).setHidden().setPostOnly().withPrice(12).withPriceAuxLimit(23).withPriceTrailing(23).withGroupId(4).build();
    final OrderCommand command = new OrderCommand(order);
    final BitfinexApiBroker bitfinexApiBroker = buildMockedBitfinexConnection();
    final String commandValue = command.getCommand(bitfinexApiBroker);
    Assert.assertNotNull(commandValue);
    Assert.assertTrue(commandValue.length() > 10);
}
Also used : BitfinexApiBroker(com.github.jnidzwetzki.bitfinex.v2.BitfinexApiBroker) CancelOrderCommand(com.github.jnidzwetzki.bitfinex.v2.commands.CancelOrderCommand) OrderCommand(com.github.jnidzwetzki.bitfinex.v2.commands.OrderCommand) BitfinexOrder(com.github.jnidzwetzki.bitfinex.v2.entity.BitfinexOrder) Test(org.junit.Test)

Example 13 with BitfinexOrder

use of com.github.jnidzwetzki.bitfinex.v2.entity.BitfinexOrder in project bitfinex-v2-wss-api-java by jnidzwetzki.

the class CommandsTest method testCommandsJSON.

/**
 * Call all commands and check for excepion
 * @throws CommandException
 */
@Test
public void testCommandsJSON() throws CommandException {
    final BitfinexOrder order = BitfinexOrderBuilder.create(BitfinexCurrencyPair.BCH_USD, BitfinexOrderType.EXCHANGE_STOP, 2).build();
    final BitfinexCandlestickSymbol candleSymbol = new BitfinexCandlestickSymbol(BitfinexCurrencyPair.BCH_USD, Timeframe.HOUR_1);
    final OrderbookConfiguration orderbookConfiguration = new OrderbookConfiguration(BitfinexCurrencyPair.BCH_USD, OrderBookPrecision.P0, OrderBookFrequency.F0, 50);
    final RawOrderbookConfiguration rawOrderbookConfiguration = new RawOrderbookConfiguration(BitfinexCurrencyPair.BAT_BTC);
    final List<AbstractAPICommand> commands = Arrays.asList(new AuthCommand(), new CancelOrderCommand(123), new CancelOrderGroupCommand(1), new OrderCommand(order), new PingCommand(), new SubscribeCandlesCommand(candleSymbol), new SubscribeTickerCommand(new BitfinexTickerSymbol(BitfinexCurrencyPair.BCH_USD)), new SubscribeTradesCommand(new BitfinexExecutedTradeSymbol(BitfinexCurrencyPair.BAT_BTC)), new SubscribeOrderbookCommand(orderbookConfiguration), new SubscribeRawOrderbookCommand(rawOrderbookConfiguration), new UnsubscribeChannelCommand(12));
    final BitfinexApiBroker bitfinexApiBroker = buildMockedBitfinexConnection();
    for (final AbstractAPICommand command : commands) {
        final String commandValue = command.getCommand(bitfinexApiBroker);
        Assert.assertNotNull(commandValue);
        Assert.assertTrue(commandValue.length() > 10);
    }
}
Also used : BitfinexExecutedTradeSymbol(com.github.jnidzwetzki.bitfinex.v2.entity.symbol.BitfinexExecutedTradeSymbol) CancelOrderCommand(com.github.jnidzwetzki.bitfinex.v2.commands.CancelOrderCommand) OrderCommand(com.github.jnidzwetzki.bitfinex.v2.commands.OrderCommand) SubscribeOrderbookCommand(com.github.jnidzwetzki.bitfinex.v2.commands.SubscribeOrderbookCommand) CancelOrderGroupCommand(com.github.jnidzwetzki.bitfinex.v2.commands.CancelOrderGroupCommand) OrderbookConfiguration(com.github.jnidzwetzki.bitfinex.v2.entity.OrderbookConfiguration) RawOrderbookConfiguration(com.github.jnidzwetzki.bitfinex.v2.entity.RawOrderbookConfiguration) UnsubscribeChannelCommand(com.github.jnidzwetzki.bitfinex.v2.commands.UnsubscribeChannelCommand) SubscribeTradesCommand(com.github.jnidzwetzki.bitfinex.v2.commands.SubscribeTradesCommand) BitfinexTickerSymbol(com.github.jnidzwetzki.bitfinex.v2.entity.symbol.BitfinexTickerSymbol) AbstractAPICommand(com.github.jnidzwetzki.bitfinex.v2.commands.AbstractAPICommand) CancelOrderCommand(com.github.jnidzwetzki.bitfinex.v2.commands.CancelOrderCommand) PingCommand(com.github.jnidzwetzki.bitfinex.v2.commands.PingCommand) SubscribeCandlesCommand(com.github.jnidzwetzki.bitfinex.v2.commands.SubscribeCandlesCommand) RawOrderbookConfiguration(com.github.jnidzwetzki.bitfinex.v2.entity.RawOrderbookConfiguration) SubscribeTickerCommand(com.github.jnidzwetzki.bitfinex.v2.commands.SubscribeTickerCommand) BitfinexApiBroker(com.github.jnidzwetzki.bitfinex.v2.BitfinexApiBroker) BitfinexCandlestickSymbol(com.github.jnidzwetzki.bitfinex.v2.entity.symbol.BitfinexCandlestickSymbol) BitfinexOrder(com.github.jnidzwetzki.bitfinex.v2.entity.BitfinexOrder) AuthCommand(com.github.jnidzwetzki.bitfinex.v2.commands.AuthCommand) SubscribeRawOrderbookCommand(com.github.jnidzwetzki.bitfinex.v2.commands.SubscribeRawOrderbookCommand) Test(org.junit.Test)

Aggregations

BitfinexOrder (com.github.jnidzwetzki.bitfinex.v2.entity.BitfinexOrder)11 Test (org.junit.Test)6 BitfinexApiBroker (com.github.jnidzwetzki.bitfinex.v2.BitfinexApiBroker)5 APIException (com.github.jnidzwetzki.bitfinex.v2.entity.APIException)5 CancelOrderCommand (com.github.jnidzwetzki.bitfinex.v2.commands.CancelOrderCommand)4 OrderCommand (com.github.jnidzwetzki.bitfinex.v2.commands.OrderCommand)4 ExchangeOrder (com.github.jnidzwetzki.bitfinex.v2.entity.ExchangeOrder)4 ConnectionCapabilities (com.github.jnidzwetzki.bitfinex.v2.entity.ConnectionCapabilities)3 CancelOrderGroupCommand (com.github.jnidzwetzki.bitfinex.v2.commands.CancelOrderGroupCommand)2 BitfinexCurrencyPair (com.github.jnidzwetzki.bitfinex.v2.entity.BitfinexCurrencyPair)2 OrderManager (com.github.jnidzwetzki.bitfinex.v2.manager.OrderManager)2 Retryer (org.bboxdb.commons.Retryer)2 Session (org.hibernate.Session)2 AbstractAPICommand (com.github.jnidzwetzki.bitfinex.v2.commands.AbstractAPICommand)1 AuthCommand (com.github.jnidzwetzki.bitfinex.v2.commands.AuthCommand)1 PingCommand (com.github.jnidzwetzki.bitfinex.v2.commands.PingCommand)1 SubscribeCandlesCommand (com.github.jnidzwetzki.bitfinex.v2.commands.SubscribeCandlesCommand)1 SubscribeOrderbookCommand (com.github.jnidzwetzki.bitfinex.v2.commands.SubscribeOrderbookCommand)1 SubscribeRawOrderbookCommand (com.github.jnidzwetzki.bitfinex.v2.commands.SubscribeRawOrderbookCommand)1 SubscribeTickerCommand (com.github.jnidzwetzki.bitfinex.v2.commands.SubscribeTickerCommand)1