Skip to content

Instantly share code, notes, and snippets.

@DannyvdSluijs
Created May 25, 2020 19:32
Show Gist options
  • Select an option

  • Save DannyvdSluijs/f404d5bb043e5adc5c0e68d86c4adeb2 to your computer and use it in GitHub Desktop.

Select an option

Save DannyvdSluijs/f404d5bb043e5adc5c0e68d86c4adeb2 to your computer and use it in GitHub Desktop.
Map Bitstamp using JsonMapper
<?php
use App\TradingPair;
use Illuminate\Console\Command;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Http;
use JsonMapper\Cache\ArrayCache;
use JsonMapper\Enums\TextNotation;
use JsonMapper\JsonMapper;
use JsonMapper\Middleware\CaseConversion;
use JsonMapper\Middleware\TypedProperties;
class TradingPair {
public string $name;
public string $description;
public int $baseDecimals;
public int $counterDecimals;
public string $minimumOrder;
public string $trading;
public string $urlSymbol;
}
$response = Http::get('https://www.bitstamp.net/api/v2/trading-pairs-info/');
$mapper = JsonMapperFactory::default();
$mapper->push(new TypedProperties(new ArrayCache()));
$mapper->push(new CaseConversion(TextNotation::UNDERSCORE(), TextNotation::CAMEL_CASE()));
$pairs = Collection::make($this->mapper->mapArray($response->object(), new TradingPair()));
dd($pairs);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment