#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>

void Usage(void){
	printf("./contractloss contracts entry exit\n");
}

int main(int argc, char **argv){

//$6.95 plus $0.75
	double gain_loss_per_inc = 25.0;//7.81; //31.25; //10.0; //25.0; //5.0; //12.5;
	double comm_per_contract = 0;//0.75; //3.71;
	double comm_per_trade = 0; //6.95;
	double contracts = 0;
	double entry_price = 0;
	double exit_price = 0;
	double difference = 0;
	double tmp1 = 0;
	double tmp2 = 0;
	double total_comm = 0;

	if(argc < 3){
		Usage();
		return 0;
	}

	contracts = atof(argv[1]);
	entry_price = atof(argv[2]);
	exit_price = atof(argv[3]);


	//calculate number of increments (half tenths of cents for copper)

	//if(entry_price > exit_price)
	//	difference = entry_price - exit_price;
	//else
	difference = exit_price - entry_price;
	//multiply out
	// x200, x20, x2, x1
//	tmp1 = difference / 0.03125;
//	tmp1 = difference / 0.0005;
//	tmp1 = difference / 0.1;
	tmp1 = difference / 0.005;
//tmp1 = difference / 0.01;
//tmp1 = difference / 0.003134796;

	total_comm = (comm_per_contract * contracts * 2) + (comm_per_trade*2);

	tmp2 = (tmp1 * gain_loss_per_inc * contracts);


	tmp2 -= total_comm;

	if(tmp2 <= 0){	//loss
		printf("loss: %lf\n", tmp2);
	}else{
		printf("gain: %lf\n", tmp2);
	}
/*
	if(entry_price < exit_price){ //gain
		tmp2 -= total_comm;
		printf("gain: %lf\n", tmp2);
	}else{
		tmp2 += total_comm;
		tmp2 *= -1;
		printf("loss: %lf\n", tmp2);
	}
*/

	return 0;
}
