Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function importTradesB($userid)
- {
- // User Variables
- $user = User::where('id', $userid)->first();
- $key = Key::where([['userid', '=', $userid], ['exchange', '=', 'Bittrex']])->first();
- $apikey = decrypt($key->public);
- $apisecret = decrypt($key->private);
- $client = new \GuzzleHttp\Client();
- try{
- $nonce=time();
- $uri='https://bittrex.com/api/v1.1/account/getorderhistory?apikey='.$apikey.'&nonce='.$nonce;
- $sign=hash_hmac('sha512',$uri,$apisecret);
- $res = $client->request('GET', $uri, [
- 'headers' => [
- 'apisign' => $sign,
- ]]);
- $response = $res->getBody();
- $trades = json_decode($response, true);
- } catch (\GuzzleHttp\Exception\ClientException $e) {
- }
- foreach($trades['result'] as $trade)
- {
- if(!BittrexTrade::where('tradeid', $userid . $trade['OrderUuid'])->exists())
- {
- $currencies = explode("-", $trade['Exchange']);
- $ddate = strtotime($trade['TimeStamp']);
- $newformat = date('Y-m-d H:i:s', $ddate);
- $t = new BittrexTrade;
- $t->userid = $userid;
- $t->tradeid = $userid . $trade['OrderUuid'];
- $t->date = $newformat;
- $t->type = $trade['OrderType'];
- $t->market = $currencies[0];
- if($currencies[1] == "ANS")
- {
- $t->currency = "NEO";
- } elseif($currencies[1] == "BCC") {
- $t->currency = "BCH";
- } elseif($currencies[1] == "SEC")
- {
- $t->currency = "SAFEX";
- }
- else {
- $t->currency = $currencies[1];
- }
- $t->price = $trade['PricePerUnit'];
- $t->amount = $trade['Quantity'] - $trade['QuantityRemaining'];
- $t->fee = $trade['Commission'];
- $t->total = $trade['Price'];
- $t->save();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement