All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.finmath.smartcontract.valuation.marketdata.LaunchAGenerator Maven / Gradle / Ivy

package net.finmath.smartcontract.valuation.marketdata;


import com.neovisionaries.ws.client.WebSocket;
import io.reactivex.rxjava3.functions.Consumer;
import jakarta.xml.bind.JAXBContext;
import jakarta.xml.bind.Marshaller;
import net.finmath.smartcontract.model.MarketDataList;
import net.finmath.smartcontract.product.SmartDerivativeContractDescriptor;
import net.finmath.smartcontract.product.xml.SDCXMLParser;
import net.finmath.smartcontract.valuation.marketdata.curvecalibration.CalibrationDataItem;
import net.finmath.smartcontract.valuation.marketdata.generators.MarketDataGeneratorWebsocket;
import net.finmath.smartcontract.valuation.marketdata.generators.WebSocketConnector;

import java.io.File;
import java.io.FileInputStream;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Properties;


public class LaunchAGenerator {


	public static void main(String[] args) throws Exception {

		String sdcXML = new String(LaunchAGenerator.class.getClassLoader().getResourceAsStream("net.finmath.smartcontract.product.xml/smartderivativecontract.xml").readAllBytes(), StandardCharsets.UTF_8);
		SmartDerivativeContractDescriptor sdc = SDCXMLParser.parse(sdcXML);
		List mdItemList = sdc.getMarketdataItemList();

		/* Load connection properties*/
		String connectionPropertiesFile = "";
		Properties properties = new Properties();
		properties.load(new FileInputStream(connectionPropertiesFile));


		/* Init Websockect Connection*/
		final WebSocketConnector connector = new WebSocketConnector(properties);
		final WebSocket socket = connector.getWebSocket();


		/* Market Data Adapter */
		final MarketDataGeneratorWebsocket emitter = new MarketDataGeneratorWebsocket(connector.getAuthJson(), connector.getPosition(), mdItemList);

		socket.addListener(emitter);
		socket.connect();

		/* Write Market Data to File */
		final Consumer marketDataWriter = new Consumer() {

			@Override
			public void accept(MarketDataList s) throws Throwable {

				System.out.println("Consumer MarketDataStorage: Stored Market Data at: ");
				System.out.println(socket.isOpen());
				//TODO replace file
				File file = new File("md_testset3.xml");
				JAXBContext jaxbContext = JAXBContext.newInstance(MarketDataList.class);
				Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
				jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
				jaxbMarshaller.marshal(s, file);
				emitter.closeStreamsAndLogoff(socket);
				socket.sendClose();

			}
		};


		emitter.asObservable().take(1).subscribe(marketDataWriter);


	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy