This post provides some experiences from making a simple Java app (well, the actual app does something this is just a demo) that connects to Bitfinex to  get the funding rates run as a GraalVM native image.

xChange is one of the most famous Java libraries for integrating with a large number of crypto exchanges. It provides a simple API that Continue reading

When using Infinispan (or any other jBoss library for that matter)  and Logback in the same project you may end up getting this warning when running the project:

ERROR StatusLogger No log4j2 configuration file found. Using default configuration: logging only errors to the console

Maybe you log to a persistent storage and you may miss important error messages, because they are logged to the console.

Solution 1: Start the application with specific parameter

One solution is to add the following parameter when starting the application:

-Dorg.jboss.logging.provider=slf4j

The relevant code is in org.jboss.logging.LoggerProviders which looks for the “org.jboss.logging.provider” environment variable.

 

Solution 2: Exclude log4j libraries from classpath

Another solution is to exclude all logging related classes from the classpath, as in org.jboss.logging.LoggerProviders it looking for various logging related classes and it looks for the logabck related classes at the very end!

When using gradle it is enough to add the following into build.gradle

configurations {
all*.exclude group: ‘org.apache.logging.log4j’
all*.exclude group: ‘org.apache.log4j’
all*.exclude group: ‘org.jboss.logmanager’
}

During the past few months I have been creating some EAs in MQL5. I have also created some microservice like functions for other FinTech related projects (e.g. Market News / custom indicators). All those services are exposed with REST APIs. So there is the need to reuse this functionality from MQL5 Expert Advisors.

There are numerous examples in MQL5 that use WebRequest, however it’s not possible to use them from within backtesting. An error is raised in such cases. The other obvious alternative was to use a custom DLL that will be used from within MQL5 and delegate the REST call to the DLL.

In this direction I have created an opensource library rest-mql and an example on how to use it through MQL5. The library can be found here: https://github.com/cyrus13/rest-mql

The example MQL code can be found here: https://github.com/cyrus13/rest-mql/blob/master/mql5-sample-code/testmqldll.mq5

It is worth mentioning that REST calls certainly slow down the EA and should be used judiciously.

I need to start a MySQL server in order to do some tests. Luckily MySQL has an official docker image. So in 3 simple steps:

Step 1: Download the Image

docker pull mysql/mysql-server:8.0.13

In this case I wanted to download a specific version of MySQL, 8.0.13.

Step 2: Run the Container

docker run -d --name mysql-8 -v /Volumes/USBHDD/mysql/data/:/var/lib/mysql/ -e lower_case_table_names=1 -e MYSQL_ROOT_PASSWORD=root -e MYSQL_ROOT_HOST=% -p 3306:3306 mysql/mysql-server:8.0.13

Explanation of params:

ParameterExplanation
-dDetached mode so that it runs the container in the background.
–name Provide a friendly name to the container so that we can start/stop it in the future
-vI want to store the MySQL data from the container to an external USB Volume mounted on the host at: /Volumes/USBHDD/mysql/data/. So all data saved by MySQL in will be available in the external USB drive. I believe the proper way is to do it using docker volumes, but this is a quick way as the title says.
-e lower_case_table_names=1 The -e parameter allows us to pass properties to the container process. lower_case_table_names=1 is required in a MacOS and Windows Host because the file system is case insensitive.
-e MYSQL_ROOT_PASSWORD=rootThe password of the root user.
-e MYSQL_ROOT_HOST=%By default the root user is only allowed to connect from ‘localhost’ (i.e. from within the container). I want to be able to connect as root from the host machine, that’s why this option is required. Note: This is obviously a security hole, but for a dev environment it should be ok.
-p 3306:3306Map port 3306 (the default MySQL port) from container to host.


Step 3: Connect to container from host

Using MySQL Workbench from the Host machine and connection params:

Host: 127.0.0.1
Username: root
Password: root

we can connect to the MySQL running on the container and create a new DB.

That’s it! Now we may want to stop the container.

Step 4: Stop the container

docker stop mysql-8

Step 5: Start the container again

docker start mysql-8

Connecting again using the MySQL Workbench we can see our data and continue development.

It’s been ages since I have posted some sample code. It’s mainly because I don’t have time to collect and post sample code anymore. This once was a bit more challenging and googling wasn’t help much, so now that I have some time I though I would post some sample code that achieves batch inserts with spring data.

For example this link:
http://forum.spring.io/forum/spring-projects/data/118203-bulk-insert-with-crudrepository indicated that I had to manually get the session and iterate/flush (which was true when using Spring/Hibernate/JPA). But when using the CRUDRepository it appears it’s much simpler.

FULL CODE

Full code sample (maven project) can be found on github: https://github.com/cyrus13/anastasakis-net-sample-code/tree/master/spring-data-batch

You basically need to have the following elements:

  • Add: ?rewriteBatchedStatements=true to the end of the connectionstring.
  • Make sure you use a generator that supports batching in your entity. E.g.
@Id
@GeneratedValue(generator = "generator")
@GenericGenerator(name = "generator", strategy = "increment")
  • Use the: save(Iterable<S> paramIterable); method of the JpaRepository to save the data.
  • Use the: hibernate.jdbc.batch_size configuration.

RESULT

So enabling the query log in MySQL:

SET global general_log = 1;
SET global log_output = 'table';

we can see the following mysql code is executed:

SET autocommit=0;
select max(id) from ExampleEntity;
SHOW WARNINGS;
select @@session.tx_read_only;
insert into ExampleEntity (exampleText, id) values 
('de32bec8-1cf9-4f14-b816-0ab7a00b1539', 4),
('c0c85b32-eb2d-4a69-ade4-ac70ea94241c', 5);
commit;
SET autocommit=1;

Note: Don’t forget to stop logging statements into MySQL general log!

SET global general_log = 0;