Order Book
@link https://kuna.io/api/v2/order_book?market=btcuah
@param string $pair
@param bool $mapping

@return array|Order[] array with asks and bids
@throws ClientException
346486
public function orderBook(string $pair, bool $mapping = false)
    {
        $options = [
            'query' => ['market' => $pair],
        ];
        $response = $this->sendRequest(Api::GET, $this->getApiUrn(['order_book']), $options);

        if ($mapping) {
            $response = [
                'asks' => $this->deserializeItems($response['asks'], Order::class),
                'bids' => $this->deserializeItems($response['bids'], Order::class),
            ];
        }

        return $response;
    }
313955
public function mapField(array $mapping)
    {
        if ( ! isset($mapping['fieldName']) && isset($mapping['name'])) {
            $mapping['fieldName'] = $mapping['name'];
        }
        if ( ! isset($mapping['fieldName'])) {
            throw MappingException::missingFieldName($this->name);
        }
        if ( ! isset($mapping['name'])) {
            $mapping['name'] = $mapping['fieldName'];
        }
        if (isset($this->fieldMappings[$mapping['fieldName']])) {
            //throw MappingException::duplicateFieldMapping($this->name, $mapping['fieldName']);
        }
        if ($this->discriminatorField !== null && $this->discriminatorField == $mapping['name']) {
            throw MappingException::discriminatorFieldConflict($this->name, $this->discriminatorField);
        }
        if (isset($mapping['targetDocument']) && strpos($mapping['targetDocument'], '\\') === false && strlen($this->namespace)) {
            $mapping['targetDocument'] = $this->namespace . '\\' . $mapping['targetDocument'];
        }

        if (isset($mapping['discriminatorMap'])) {
            foreach ($mapping['discriminatorMap'] as $key => $class) {
                if (strpos($class, '\\') === false && strlen($this->namespace)) {
                    $mapping['discriminatorMap'][$key] = $this->namespace . '\\' . $class;
                }
            }
        }

        if (isset($mapping['cascade']) && isset($mapping['embedded'])) {
            throw MappingException::cascadeOnEmbeddedNotAllowed($this->name, $mapping['fieldName']);
        }

        $cascades = isset($mapping['cascade']) ? array_map('strtolower', (array) $mapping['cascade']) : array();

        if (in_array('all', $cascades) || isset($mapping['embedded'])) {
            $cascades = array('remove', 'persist', 'refresh', 'merge', 'detach');
        }

        if (isset($mapping['embedded'])) {
            unset($mapping['cascade']);
        } elseif (isset($mapping['cascade'])) {
            $mapping['cascade'] = $cascades;
        }

        $mapping['isCascadeRemove'] = in_array('remove', $cascades);
        $mapping['isCascadePersist'] = in_array('persist', $cascades);
        $mapping['isCascadeRefresh'] = in_array('refresh', $cascades);
        $mapping['isCascadeMerge'] = in_array('merge', $cascades);
        $mapping['isCascadeDetach'] = in_array('detach', $cascades);

        if (isset($mapping['type']) && $mapping['type'] === 'file') {
            $mapping['file'] = true;
        }
        if (isset($mapping['file']) && $mapping['file'] === true) {
            $this->file = $mapping['fieldName'];
            $mapping['name'] = 'file';
        }
        if (isset($mapping['distance']) && $mapping['distance'] === true) {
            $this->distance = $mapping['fieldName'];
        }
        if (isset($mapping['id']) && $mapping['id'] === true) {
            $mapping['name'] = '_id';
            $mapping['type'] = isset($mapping['type']) ? $mapping['type'] : 'id';
            $this->identifier = $mapping['fieldName'];
            if (isset($mapping['strategy'])) {
                $this->generatorOptions = isset($mapping['options']) ? $mapping['options'] : array();

                $generatorType = constant('Doctrine\ODM\MongoDB\Mapping\ClassMetadata::GENERATOR_TYPE_' . strtoupper($mapping['strategy']));
                if ($generatorType !== self::GENERATOR_TYPE_AUTO) {
                    if (isset($this->generatorOptions['type'])) {
                        $mapping['type'] = $this->generatorOptions['type'];
                    } elseif ($generatorType === ClassMetadata::GENERATOR_TYPE_INCREMENT) {
                        $mapping['type'] = 'int_id';
                    } else {
                        $mapping['type'] = 'custom_id';
                    }

                    unset($this->generatorOptions['type']);
                }

                $this->generatorType = $generatorType;
            }
        }
        if ( ! isset($mapping['nullable'])) {
            $mapping['nullable'] = false;
        }

        if (isset($mapping['reference']) && ! empty($mapping['simple']) && ! isset($mapping['targetDocument'])) {
            throw MappingException::simpleReferenceRequiresTargetDocument($this->name, $mapping['fieldName']);
        }

        if (isset($mapping['reference']) && $mapping['type'] === 'one') {
            $mapping['association'] = self::REFERENCE_ONE;
        }
        if (isset($mapping['reference']) && $mapping['type'] === 'many') {
            $mapping['association'] = self::REFERENCE_MANY;
        }
        if (isset($mapping['embedded']) && $mapping['type'] === 'one') {
            $mapping['association'] = self::EMBED_ONE;
        }
        if (isset($mapping['embedded']) && $mapping['type'] === 'many') {
            $mapping['association'] = self::EMBED_MANY;
        }

        if (isset($mapping['association']) && ! isset($mapping['targetDocument']) && ! isset($mapping['discriminatorField'])) {
            $mapping['discriminatorField'] = self::DEFAULT_DISCRIMINATOR_FIELD;
        }

        /*
        if (isset($mapping['type']) && ($mapping['type'] === 'one' || $mapping['type'] === 'many')) {
            $mapping['type'] = $mapping['type'] === 'one' ? self::ONE : self::MANY;
        }
        */
        if (isset($mapping['version'])) {
            $mapping['notSaved'] = true;
            $this->setVersionMapping($mapping);
        }
        if (isset($mapping['lock'])) {
            $mapping['notSaved'] = true;
            $this->setLockMapping($mapping);
        }
        $mapping['isOwningSide'] = true;
        $mapping['isInverseSide'] = false;
        if (isset($mapping['reference'])) {
            if (isset($mapping['inversedBy']) && $mapping['inversedBy']) {
                $mapping['isOwningSide'] = true;
                $mapping['isInverseSide'] = false;
            }
            if (isset($mapping['mappedBy']) && $mapping['mappedBy']) {
                $mapping['isInverseSide'] = true;
                $mapping['isOwningSide'] = false;
            }
            if (!isset($mapping['orphanRemoval'])) {
                $mapping['orphanRemoval'] = false;
            }
        }

        $this->fieldMappings[$mapping['fieldName']] = $mapping;
        if (isset($mapping['association'])) {
            $this->associationMappings[$mapping['fieldName']] = $mapping;
        }

        return $mapping;
    }
863344
public DSXOrderbookWrapper getDSXOrderbook(String pairs, String type) throws IOException {

    return dsx.getOrderbook(pairs.toLowerCase(), 1, type);
  }
861308
public static function create($mapping): Mapping
    {
        if (\is_array($mapping)) {
            $mappingObject = new self();
            $mappingObject->setProperties($mapping);

            return $mappingObject;
        }

        if ($mapping instanceof self) {
            return $mapping;
        }

        throw new InvalidException('Invalid object type');
    }
211338
private function buildMapping($mapping)
    {
        foreach ($mapping as $field => $type) {
            $mapping[$field] = $this->buildType($type);
        }

        return $mapping;
    }
1209911
public function listOrders($parameters = [])
    {
        $response = $this->client->get('transactions/orders', [
            'query' => $parameters,
        ]);
        return json_decode($response->getBody())->orders;
    }
148104
public function myHistory(string $pair, bool $mapping = false): array
    {
        $options = [
            'query' => ['market' => $pair],
        ];
        $response = $this->sendRequest(Api::GET, $this->getApiUrn(['trades', 'my']), $options);

        if ($mapping) {
            $response = $this->deserializeItems($response, History::class);
        }

        return $response;
    }
11220
public function pairs(string $query, array $params = []): array
	{
		return $this->all($query, $params, PDO::FETCH_KEY_PAIR);
	}
640887
public function createMapping(array $mapping, $index, $type)
    {
        $request = $this->createRequestInstance(self::INDEX_CREATE_MAPPING, $index, $type);
        $request->setBody($mapping);

        return $this->client->send($request);
    }
735517
public function create(array $mapping = [], array $options = [])
    {
        $data = [
            'body' => $mapping
        ];

        $response = $this->kuzzle->query(
            $this->buildQueryArgs('collection', 'create'),
            $this->kuzzle->addHeaders($data, $this->headers),
            $options
        );

        return $response['result']['acknowledged'];
    }
278698
public function activeOrders(string $pair, bool $mapping = false): array
    {
        $options = [
            'query' => ['market' => $pair],
        ];

        //sometimes instead of active orders
        // this request return market cap (https://kuna.io/api/v2/order_book?market=btcuah)
        $response = $this->sendRequest(Api::GET, $this->getApiUrn(['orders']), $options);

        if ($response && empty($response[0]['id'])) {
            throw new IncorrectResponseException(
                'Incorrect response',
                $this->client->getLastRequest(),
                $response
            );
        }

        if ($mapping) {
            $response = $this->deserializeItems($response, Order::class);
        }

        return $response;
    }
1308838
protected function setDefaults($mapping)
    {
        if (!is_array($mapping)) {
            $mapping = [];
        }
        foreach (['entity', 'attributes', 'relationships'] as $key) {
            if (!isset($mapping[$key]) || !is_array($mapping[$key])) {
                $mapping[$key] = [];
            }
        }
        return $mapping;
    }
80190
protected function mapMapping(array $record, Mapping $mapping, $context = null, $key = null)
    {
        $mapped = $this->mapFragment($record, $mapping->toArray(), $context, $key);

        if ($mapping->isWrapped()) {
            // Unwrap.
            return $mapped[0];
        }

        return $mapped;
    }
1310371
protected function createOrder(string $side, string $pair, float $volume, float $price, bool $mapping = false)
    {
        $options = [
            'form_params' => [
                'side' => $side,
                'market' => $pair,
                'volume' => $volume,
                'price' => $price,
            ],
        ];

        $response = $this->sendRequest(Api::POST, $this->getApiUrn(['orders']), $options);

        if ($mapping) {
            $response = $this->deserializeItem($response, Order::class);
        }

        return $response;
    }
1326103
private function addOrderBy(QueryBuilder $qb, array $orderBy = [])
    {
        if (count($orderBy)) {
            $alias = $qb->getAllAliases()[0];
            foreach ($orderBy as $sortCol => $order) {
                $qb->orderBy($alias . '.' . $sortCol, $order);
            }
        }

        return $qb;
    }
991760
public function mapManyToMany(array $mapping)
    {
        $mapping['type'] = self::MANY_TO_MANY;
        $mapping = $this->_validateAndCompleteManyToManyMapping($mapping);
        $this->_storeAssociationMapping($mapping);
    }
263658
public function getTranslatedPropertyNameAssoc($locale, $mapping)
    {
        return [
            'property'   => $this->getTranslatedPropertyName($locale, $mapping['property']),
            'assoc'      => $this->getTranslatedPropertyName($locale, $mapping['assoc']),
            'assocNulls' => $this->getTranslatedPropertyName($locale, $mapping['assocNulls']),
        ];
    }