package quant.rich;

import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;

import lombok.extern.slf4j.Slf4j;
import nano.CandleStickNewWithIndexExResponse.CandleStickNewWithIndexEx_Response;
import nano.CandleStickRequest.CandleStick_Request;
import nano.CandleStickWithIndexRequest.CandleStickWithIndex_Request;
import quant.rich.emoney.EmoneyAutoApplication;
import quant.rich.emoney.client.EmoneyClient;


@SpringBootTest
@ContextConfiguration(classes = EmoneyAutoApplication.class)
@RunWith(SpringJUnit4ClassRunner.class)
@Slf4j
class EmoneyAutoApplicationTests {

	@Test
	void contextLoads() {
	    EmoneyClient.reloginCheck();
	    
	    CandleStickWithIndex_Request request = new CandleStickWithIndex_Request();
	    
	    CandleStick_Request candleRequest = new CandleStick_Request();
	    candleRequest.setBeginPosition(0)
	        .setDataPeriod(50000)
	        .setExFlag(0).setGoodsId(1300684)
	        .setLastVolume(0).setLimitSize(250)
	        .setReqFhsp(false).setReqHisShares(false);
	    request.candleRequest = candleRequest;
	    
	    //IndexInfo indexRequest = new IndexInfo().setIndexName("CPX");
	    //request.indexRequest = new IndexInfo[] {indexRequest};
	    
	    //emoneyClient.getEmoneyRequestHeader().setXProtocolId(2422).setXRequestIdWithTimestamp();
	    
	    CandleStickNewWithIndexEx_Response response = EmoneyClient.post(
	            request, CandleStickNewWithIndexEx_Response.class,
	            2422, String.valueOf(System.currentTimeMillis()));
	    //JSONObject jo = JSONObject.from(request);
	    ObjectNode jo = new ObjectMapper().valueToTree(response);
	    log.info(jo.toPrettyString());
	    
	}

}
