add get balance from 3commas

This commit is contained in:
Matthew Shillam 2019-04-03 09:36:28 +01:00
parent bce225d3ff
commit f1132f8269
8 changed files with 9550 additions and 7071 deletions

View File

@ -10,28 +10,29 @@ use function GuzzleHttp\json_decode;
class ThreeCommasController extends Controller
{
public function getTrades(){
private $baseUrl = 'https://3commas.io';
private $api_version = '/public/api/ver1/';
private $api_key = 'fd2465a6fa0e455986ef99a51dea14c759bf2feb8f5344558715b1176a3680e8';
private $api_secret = '7a43c6de51fc9d4d10f1889bc0bd816d1da63d24c4b0ef357f35e4eb95c5f5e6fef355b891cee3960d7cfc872f328c38906ac17a7152610098eb14940f29cb5643c58c09a7de5fa63859ffe1baedf01ba0c3fa3f30757f33bf5d5f7f2e22e3539f70109e';
$baseUrl = 'https://3commas.io';
$api_version = '/public/api/ver1/';
public function getTrades(){
$end_point = 'smart_trades';
$url = $baseUrl . $api_version . $end_point;
$api_key = 'fd2465a6fa0e455986ef99a51dea14c759bf2feb8f5344558715b1176a3680e8';
$api_secret = '7a43c6de51fc9d4d10f1889bc0bd816d1da63d24c4b0ef357f35e4eb95c5f5e6fef355b891cee3960d7cfc872f328c38906ac17a7152610098eb14940f29cb5643c58c09a7de5fa63859ffe1baedf01ba0c3fa3f30757f33bf5d5f7f2e22e3539f70109e';
$url = $this->baseUrl . $this->api_version . $end_point;
$params = [
'api_key' => $api_key,
'secret' => $api_secret,
'api_key' => $this->api_key,
'secret' => $this->api_secret,
'scope' => 'active',
'limit' => 50
];
$query = http_build_query($params);
$signature = hash_hmac('sha256', $api_version . $end_point . '?' . $query, $api_secret);
$signature = hash_hmac('sha256', $this->api_version . $end_point . '?' . $query, $this->api_secret);
$client = new Client([
'headers' => [
'Content-Type' => 'application/json',
'APIKEY' => $api_key,
'APIKEY' => $this->api_key,
'Signature' => $signature
],
]);
@ -40,31 +41,26 @@ class ThreeCommasController extends Controller
return $data;
}
public function getSignals(){
// Initialize the client
$api = new Client([
'base_uri' => 'https://app.signalprofits.com/',
'cookies' => true, // You have to have cookies turned on for this API to work
]);
public function getBalance(){
$end_point = 'accounts';
$url = $this->baseUrl . $this->api_version . $end_point;
$params = [
'api_key' => $this->api_key,
'secret' => $this->api_secret,
];
$query = http_build_query($params);
$signature = hash_hmac('sha256', $this->api_version . $end_point . '?' . $query, $this->api_secret);
// Login
$api->post('app/login', [
'form_params' => [
'identity' => 'john@eutrading.co.uk', // use your actual username
'password' => 'l0uis0404!', // use your actual password
],
]);
// Fetch
$response = $api->get('app/login');
// and decode some data
$boxscore = $response->getBody();
// And logout
$test = $api->get('wp-admin/admin-ajax.php?action=get_signals&limit=100');
$test2 = $test->getBody();
// $test2 = json_decode($test->getBody());
return $test2;
}
}
$client = new Client([
'headers' => [
'Content-Type' => 'application/json',
'APIKEY' => $this->api_key,
'Signature' => $signature
],
]);
$response = $client->request('GET', $url . '?' . $query);
$data = json_decode($response->getBody());
return $data;
}
}

1091
composer.lock generated

File diff suppressed because it is too large Load Diff

1313
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -11,21 +11,25 @@
},
"devDependencies": {
"axios": "^0.18",
"bootstrap": "^4.0.0",
"bootstrap": "^4.3.1",
"cross-env": "^5.1",
"jquery": "^3.2",
"laravel-mix": "^2.0",
"lodash": "^4.17.5",
"popper.js": "^1.12",
"vue": "^2.5.17"
"popper.js": "^1.14.7",
"resolve-url-loader": "^2.3.1",
"sass": "^1.17.3",
"sass-loader": "^7.1.0",
"vue": "^2.6.10",
"vue-template-compiler": "^2.6.10"
},
"dependencies": {
"ajv": "^6.5.5",
"bulma": "^0.7.2",
"cryptocurrency-icons": "^0.9.0",
"imagemin": "^6.0.0",
"ajv": "^6.10.0",
"bulma": "^0.7.4",
"cryptocurrency-icons": "^0.11.0",
"imagemin": "^6.1.0",
"img-loader": "^3.0.1",
"vue-material-design-icons": "^2.4.0",
"vue-material-design-icons": "^2.8.0",
"vue-router": "^3.0.2",
"vue-trading-view": "^1.0.1"
}

474
public/css/app.css vendored

File diff suppressed because it is too large Load Diff

13571
public/js/app.js vendored

File diff suppressed because it is too large Load Diff

View File

@ -3,15 +3,15 @@
<section class="section tv-top-container" :class="{'colapse': tvTopContainerColapse}">
<div class="container is-fullhd">
<div class="columns">
<div class="column is-11 tv-top-column" :class="{'expand': tvTopContainerExpand}">
<div class="column is-9 tv-top-column" :class="{'expand': tvTopContainerExpand}">
<VueTradingView :options="{
symbol: 'BINANCE:BTCUSDT',
theme: 'dark',
allow_symbol_change: true,
autosize: true,
interval: 60,
hide_side_toolbar: false,
}" />
symbol: 'BINANCE:BTCUSDT',
theme: 'dark',
allow_symbol_change: true,
autosize: true,
interval: 60,
hide_side_toolbar: false,
}" />
</div>
<div class="column">
<span class="icon icon-circle" v-on:click="colapseTvTopContainer">
@ -24,6 +24,31 @@
<i class="mdi mdi-24px mdi-arrow-expand-down" v-on:click="expandTvTopContainer"></i>
</span>
</div>
<div class="column is-2">
24 Hour Stats
<div class="columns">
<div class="column is-one-quarter">
<img src="/images/cryptocurrency-icons/svg/color/btc.svg" alt="">
</div>
<div class="column is-three-quarters">
<big class="text-primary"
style="font-weight:600; font-size:2.5rem;">{{financial(balance_btc_amount, 3)}}</big><br>
<span
:class="{'text-error': day_profit_btc < 0, 'text-success': day_profit_btc > 0}">{{financial(day_profit_btc, 6)}}</span>
<span>{{day_profit_btc_percentage}}%</span><br>
AVAIL: <span class="text-secondary">{{btc_to_trade}}</span>
<br><br>
<big class="text-primary"
style="font-weight:600;">{{financial(balance_usd_amount, 2)}}</big><br>
<span
:class="{'text-error': day_profit_usd < 0, 'text-success': day_profit_usd > 0}">{{financial(day_profit_usd, 2)}}</span>
<span>{{day_profit_usd_percentage}}%</span><br>
AVAIL: <span class="text-secondary">{{financial(usd_to_trade, 2)}}</span>
</div>
</div>
</div>
</div>
</div>
</section>
@ -53,12 +78,13 @@
<div class="buttons">
<a class="button is-dark" @click="sort('profit_percentage'), activeFilter = 'profit'">
<span class="icon is-small">
<i class="mdi mdi-24px" :class="[ activeFilter == 'profit' && currentSortDir =='asc' ? 'mdi-chevron-up' : 'mdi-chevron-down' ]"></i>
<i class="mdi mdi-24px"
:class="[ activeFilter == 'profit' && currentSortDir =='asc' ? 'mdi-chevron-up' : 'mdi-chevron-down' ]"></i>
</span>
<span>
Profit %
Profit %
</span>
</a>
</a>
<a class="button is-dark" @click="sort('id')">Age</a>
<a class="button is-dark" @click="sort('to_currency_code')">Coin</a>
</div>
@ -76,12 +102,14 @@
<div class="coin-card is-clear-fix">
<div>
<div class="tokenicon-wrap is-pulled-left push-right">
<img v-bind:src="'/images/cryptocurrency-icons/svg/color/' + trade.to_currency_code + '.svg'" />
<img
v-bind:src="'/images/cryptocurrency-icons/svg/color/' + trade.to_currency_code + '.svg'" />
</div>
<div class="">
<big class="text-primary">{{ trade.to_currency_code }}</big>
<span class="is-pulled-right push-right">
<big :class="{'text-error': trade.profit_percentage < 0, 'text-success': trade.profit_percentage > 0}">{{trade.profit_percentage}}%</big>
<big
:class="{'text-error': trade.profit_percentage < 0, 'text-success': trade.profit_percentage > 0}">{{trade.profit_percentage}}%</big>
</span>
</div>
@ -151,6 +179,25 @@
})
},
fetchBalance() {
axios.get('/api/3commas/getbalance')
.then(response => {
this.balance = response.data,
this.balance_btc_amount = this.balance[0].btc_amount,
this.day_profit_btc = this.balance[0].day_profit_btc,
this.day_profit_btc_percentage = this.balance[0].day_profit_btc_percentage,
this.btc_to_trade = this.balance[0].available_for_trading.BTC,
this.balance_usd_amount = this.balance[0].usd_amount,
this.day_profit_usd = this.balance[0].day_profit_usd,
this.day_profit_usd_percentage = this.balance[0].day_profit_usd_percentage,
this.usd_to_trade = this.balance[0].available_for_trading.USDT
// console.log(this.balance[0].available_for_trading.BTC)
})
.catch(e => {
console.log('Error: ', e.response.data)
})
},
formatPrice(num) {
if (/\d+\.?\d*e[\+\-]*\d+/i.test(num)) {
var zero = '0',
@ -171,8 +218,8 @@
return num;
},
financial(x) {
return Number.parseFloat(x).toFixed(8);
financial(x, y = 8) {
return Number.parseFloat(x).toFixed(y);
}
},
@ -195,6 +242,8 @@
created() {
this.fetchTrades();
this.fetchBalance();
setInterval(() => this.fetchBalance(), 10000);
setInterval(() => this.fetchTrades(), 10000);
}

View File

@ -18,4 +18,5 @@ Route::middleware('auth:api')->get('/user', function (Request $request) {
});
Route::get('3commas/gettrades', 'ThreeCommasController@getTrades');
Route::get('3commas/getbalance', 'ThreeCommasController@getBalance');
Route::get('getsignals', 'ThreeCommasController@getSignals');