Skip to content

Commit

Permalink
first test
Browse files Browse the repository at this point in the history
  • Loading branch information
neo1777 committed Feb 25, 2021
1 parent af47d7f commit 380578a
Show file tree
Hide file tree
Showing 6 changed files with 472 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ distance_ord=500
delta_order=1
n_order=4
limit_order=10
trading=true
trading=false
time_print=300000
---

Expand Down
198 changes: 196 additions & 2 deletions lib/class_ftx.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'dart:convert';
import 'package:pausable_timer/pausable_timer.dart';

class PrimitiveWrapper {
Expand All @@ -17,7 +18,6 @@ class PrimitiveWrapper {
Set list_orders_buy;
Set list_orders_exec;
Set list_orders_delete;
//Set list_orders_fills;
var increment;
var increment_base;
var sizeIncrement;
Expand Down Expand Up @@ -54,7 +54,6 @@ class PrimitiveWrapper {
this.list_orders_buy,
this.list_orders_exec,
this.list_orders_delete,
//this.list_orders_fills,
this.increment,
this.increment_base,
this.sizeIncrement,
Expand All @@ -73,3 +72,198 @@ class PrimitiveWrapper {
this.open_orders,
this.type});
}

/////////////////////////////////////////////////
// To parse this JSON data, do
//
// final historical = historicalFromMap(jsonString);
Historical historicalFromMap(String str) =>
Historical.fromMap(json.decode(str));

String historicalToMap(Historical data) => json.encode(data.toMap());

class Historical {
Historical({
this.result_h,
this.success,
});

List<Result_h> result_h;
bool success;

factory Historical.fromMap(Map<String, dynamic> json) => Historical(
result_h: List<Result_h>.from(
json['result_h'].map((x) => Result_h.fromMap(x))),
success: json['success'],
);

Map<String, dynamic> toMap() => {
'result_h': List<dynamic>.from(result_h.map((x) => x.toMap())),
'success': success,
};
}

class Result_h {
Result_h({
this.close,
this.high,
this.low,
this.open,
this.startTime,
this.time,
this.volume,
});

double close;
double high;
double low;
double open;
DateTime startTime;
double time;
double volume;

factory Result_h.fromMap(Map<String, dynamic> json) => Result_h(
close: json['close'].toDouble(),
high: json['high'].toDouble(),
low: json['low'].toDouble(),
open: json['open'].toDouble(),
startTime: DateTime.parse(json['startTime']),
time: json['time'].toDouble(),
volume: json['volume'].toDouble(),
);

Map<String, dynamic> toMap() => {
'close': close,
'high': high,
'low': low,
'open': open,
'startTime': startTime.toIso8601String(),
'time': time,
'volume': volume,
};
}

/////////////////////////////////////////////////
// To parse this JSON data, do
//
// final market = marketFromMap(jsonString);
GetMarketCross marketFromMap(String str) =>
GetMarketCross.fromMap(json.decode(str));

String marketToMap(GetMarketCross data) => json.encode(data.toMap());

class GetMarketCross {
GetMarketCross({
this.result_m,
this.success,
});

Result_m result_m;
bool success;

factory GetMarketCross.fromMap(Map<String, dynamic> json) => GetMarketCross(
result_m: Result_m.fromMap(json['result_m']),
success: json['success'],
);

Map<String, dynamic> toMap() => {
'result_m': result_m.toMap(),
'success': success,
};
}

class Result_m {
Result_m({
this.ask,
this.baseCurrency,
this.bid,
this.change1H,
this.change24H,
this.changeBod,
this.enabled,
this.highLeverageFeeExempt,
this.last,
this.minProvideSize,
this.name,
this.postOnly,
this.price,
this.priceIncrement,
this.quoteCurrency,
this.quoteVolume24H,
this.restricted,
this.sizeIncrement,
this.type,
this.underlying,
this.volumeUsd24H,
});

double ask;
dynamic baseCurrency;
double bid;
double change1H;
double change24H;
double changeBod;
bool enabled;
bool highLeverageFeeExempt;
double last;
double minProvideSize;
String name;
bool postOnly;
double price;
double priceIncrement;
dynamic quoteCurrency;
double quoteVolume24H;
bool restricted;
double sizeIncrement;
String type;
String underlying;
double volumeUsd24H;

factory Result_m.fromMap(Map<String, dynamic> json) => Result_m(
ask: json['ask'].toDouble(),
baseCurrency: json['baseCurrency'],
bid: json['bid'].toDouble(),
change1H: json['change1h'].toDouble(),
change24H: json['change24h'].toDouble(),
changeBod: json['changeBod'].toDouble(),
enabled: json['enabled'],
highLeverageFeeExempt: json['highLeverageFeeExempt'],
last: json['last'].toDouble(),
minProvideSize: json['minProvideSize'].toDouble(),
name: json['name'],
postOnly: json['postOnly'],
price: json['price'].toDouble(),
priceIncrement: json['priceIncrement'].toDouble(),
quoteCurrency: json['quoteCurrency'],
quoteVolume24H: json['quoteVolume24h'].toDouble(),
restricted: json['restricted'],
sizeIncrement: json['sizeIncrement'].toDouble(),
type: json['type'],
underlying: json['underlying'],
volumeUsd24H: json['volumeUsd24h'].toDouble(),
);

Map<String, dynamic> toMap() => {
'ask': ask,
'baseCurrency': baseCurrency,
'bid': bid,
'change1h': change1H,
'change24h': change24H,
'changeBod': changeBod,
'enabled': enabled,
'highLeverageFeeExempt': highLeverageFeeExempt,
'last': last,
'minProvideSize': minProvideSize,
'name': name,
'postOnly': postOnly,
'price': price,
'priceIncrement': priceIncrement,
'quoteCurrency': quoteCurrency,
'quoteVolume24h': quoteVolume24H,
'restricted': restricted,
'sizeIncrement': sizeIncrement,
'type': type,
'underlying': underlying,
'volumeUsd24h': volumeUsd24H,
};
}
10 changes: 10 additions & 0 deletions lib/ftx_function.dart
Original file line number Diff line number Diff line change
@@ -1 +1,11 @@
import 'class_ftx.dart';
import 'ftx_function_base.dart';
import 'ftx_request_class.dart';
import 'package:dotenv/dotenv.dart';

Future run() async {
load();
var ftxApi = ApiProvide();
var data = PrimitiveWrapper();
await funzione_market_init(ftxApi, data);
}
86 changes: 86 additions & 0 deletions lib/ftx_function_base.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import 'dart:convert';
import 'class_ftx.dart';
import 'ftx_request_class.dart';
import 'package:dotenv/dotenv.dart';
import 'package:decimal/decimal.dart';

var versione = 'v8.02';

Future funzione_market_init(ApiProvide ftxApi, PrimitiveWrapper data) async {
var market_single =
await ftxApi.ftx_Get(env['URL_ftx'], 'markets/${env['Cross_ftx']}');
final market = marketFromMap(json.encode(market_single.data));
data.increment_base =
Decimal.parse(market.result_m.priceIncrement.toString());
data.increment = data.increment_base * Decimal.parse(env['distance_ord']);
data.ask_start = market.result_m.ask;
data.bid_start = market.result_m.bid;
data.type = market.result_m.type;
data.sizeIncrement = market.result_m.sizeIncrement.toString();
data.size_base =
Decimal.parse(env['size']) * Decimal.parse(data.sizeIncrement);
data.size_buy =
Decimal.parse(env['size']) * Decimal.parse(data.sizeIncrement);
data.size_sell =
Decimal.parse(env['size']) * Decimal.parse(data.sizeIncrement);
data.size_add =
Decimal.parse(env['size_add']) * Decimal.parse(data.sizeIncrement);
data.limit_order = data.increment * Decimal.parse(env['limit_order']);

var wallet_balances =
await ftxApi.ftx_Get_Auth(env['URL_ftx'], 'wallet/balances');
data.map_limit = await prep_list_orderLimit(data.increment);
var txt = ' πŸ”₯πŸ”₯ FTX_GridBot_1777${versione} πŸ”₯πŸ”₯\n';
txt += '\n';
txt += ' πŸ“‰ Cross start: ${market.result_m.name} πŸ“ˆ\n';
txt += '\n';
txt += 'βŒ›οΈ time: ${DateTime.now().toUtc()}\n';
var i = 0;
while (i < wallet_balances.data['result'].length) {
txt +=
'πŸ’° bilancio: ${wallet_balances.data['result'][i]['total']} ${wallet_balances.data['result'][i]['coin']}\n';

i++;
}
txt += '\n';
var currency;
if (data.type == 'spot') {
currency = market.result_m.baseCurrency.toString();
} else {
currency = 'USD';
}

txt +=
'hai impostato una size di ${env['size']} che corrisponde a ${data.size_base} ${currency} per un totale di ${int.parse(env['n_order']) * 2} ordini (max ${int.parse(env['limit_order']) * 2})\n';
txt +=
'la distanza minima tra gli ordini Γ¨ ${Decimal.parse(market.result_m.priceIncrement.toString())} e lo spread attuale Γ¨ ${(market.result_m.ask - market.result_m.bid).toStringAsFixed(10)}\n';
txt +=
'la distanza impostata Γ¨ ${data.increment} che corrisponde a ${env['distance_ord']} volte il minimo e ${data.increment.toDouble() / (market.result_m.ask - market.result_m.bid)} volte lo spread\n';
if (data.increment.toDouble() / (market.result_m.ask - market.result_m.bid) <
2) {
txt +=
'\n ⚠️⚠️ si consiglia di mantenere una distanza tra gli ordini superiore al doppio dello spread ⚠️⚠️\n';
}
if (env['trading'] == 'false') {
txt +=
'se le impostazioni ti soddisfano, attiva il trading sul file .env e riavviami πŸ€–\n';
}
if (env['trading'] == 'true') {
txt += '\n';
txt += 'il trading πŸ€– Γ¨ ATTIVATO\n';

txt += 'TO THE M🌘🌘N !!\n';
txt += 'πŸš€πŸš€πŸš€ \n';
}
print(txt);
}

Future<Map> prep_list_orderLimit(Decimal increment) async {
var map = {};
while (map.length + 1 <= int.parse(env['n_order'])) {
map.addAll({
'${map.length + 1}': '${Decimal.fromInt(map.length + 1) * increment}'
});
}
return map;
}
Loading

0 comments on commit 380578a

Please sign in to comment.