-
Notifications
You must be signed in to change notification settings - Fork 0
/
crypto-trading-sim.c
56 lines (43 loc) · 1.47 KB
/
crypto-trading-sim.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <stdio.h>
#include <string.h>
int main(int argc, char* argv[]){
double fee1 = 0.001; // fee for currency1 -> currency2
double fee2 = 0.001; // fee for currency2 -> currency1
if (argc > 1){
sscanf(argv[1], "%lf", &fee1);
sscanf(argv[2], "%lf", &fee2);
}
else {
printf("You can run %s with 2 floats for the fees. Default is 0.001 (0.1%%)\n\n", argv[0]);
}
double fees_mult = (1.0 - fee1) * (1.0 - fee2);
printf("First currency: ");
char currency1[20];
scanf("%s", currency1);
printf("Second currency: ");
char currency2[20];
scanf("%s", currency2);
printf("\nRate when bought: ");
double buyrate;
scanf("%lf", &buyrate);
double j = buyrate / fees_mult;
printf("Amount of %s spent to buy %s: ", currency1, currency2);
double coin1;
scanf("%lf", &coin1);
printf("You can profit if you sell at rate \t > %lf (x%.4lf)\n", j, j/buyrate);
printf("What %% profit do you want: ");
double perc_prof;
scanf("%lf", &perc_prof);
double mult_prof = perc_prof/100.0 + 1.0;
printf("For >=%.2lf%% profit you sell at rate \t>= %lf (x%.4lf)\n\n\n", perc_prof, buyrate*mult_prof/fees_mult, mult_prof/fees_mult);
while (1) {
printf("Current rate: ");
double sellrate;
scanf("%lf", &sellrate);
double factor = fees_mult*sellrate / buyrate;
double coin3 = factor*coin1;
double profit = coin3 - coin1;
printf("Profit by factor of %lf\nFrom\t\t%lf%s\nto\t\t%lf%s\nProfit\t\t%lf%s\n\n", factor, coin1, currency1, coin3, currency1, profit, currency1);
}
return 0;
}