-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
960 additions
and
3 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { BaseAPI } from './BaseAPI'; | ||
import { APIParams } from '../APIRequester'; | ||
import { CurrencyPair, Market, MarketmapParams } from '../../../core'; | ||
|
||
export interface MarketMap { | ||
markets: { [ticker: string]: Market }; | ||
} | ||
|
||
export namespace MarketMap { | ||
export interface Data { | ||
markets: { [ticker: string]: Market.Data }; | ||
} | ||
} | ||
|
||
export class MarketmapAPI extends BaseAPI { | ||
public async marketMap(params: APIParams = {}): Promise<MarketMap> { | ||
return this.c | ||
.get<{ market_map: MarketMap.Data }>( | ||
`/slinky/marketmap/v1/marketmap`, | ||
params | ||
) | ||
.then(d => { | ||
const markets: { [ticker: string]: Market } = {}; | ||
for (const [ticker, market] of Object.entries(d.market_map.markets)) { | ||
markets[ticker] = Market.fromData(market); | ||
} | ||
return { markets }; | ||
}); | ||
} | ||
|
||
public async market( | ||
pair: CurrencyPair, | ||
params: APIParams = {} | ||
): Promise<Market> { | ||
return this.c | ||
.get<{ market: Market.Data }>(`/slinky/marketmap/v1/market`, { | ||
...params, | ||
'currency_pair.Base': pair.Base, | ||
'currency_pair.Quote': pair.Quote, | ||
}) | ||
.then(d => Market.fromData(d.market)); | ||
} | ||
|
||
public async lastUpdated(params: APIParams = {}): Promise<number> { | ||
return this.c | ||
.get<{ last_updated: string }>( | ||
`/slinky/marketmap/v1/last_updated`, | ||
params | ||
) | ||
.then(d => Number.parseInt(d.last_updated)); | ||
} | ||
|
||
public async parameters(params: APIParams = {}): Promise<MarketmapParams> { | ||
return this.c | ||
.get<{ params: MarketmapParams.Data }>( | ||
`/slinky/marketmap/v1/params`, | ||
params | ||
) | ||
.then(d => MarketmapParams.fromData(d.params)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import { JSONSerializable } from '../../util/json'; | ||
import { ProviderConfig } from './ProviderConfig'; | ||
import { Ticker } from './Ticker'; | ||
import { Market as Market_pb } from '@initia/initia.proto/slinky/marketmap/v1/market'; | ||
|
||
export class Market extends JSONSerializable< | ||
Market.Amino, | ||
Market.Data, | ||
Market.Proto | ||
> { | ||
/** | ||
* @param ticker the price feed for a given asset pair | ||
* @param provider_configs the list of provider-specific configs for this Market | ||
*/ | ||
constructor( | ||
public ticker: Ticker, | ||
public provider_configs: ProviderConfig[] | ||
) { | ||
super(); | ||
} | ||
|
||
public static fromAmino(data: Market.Amino): Market { | ||
const { ticker, provider_configs } = data; | ||
return new Market( | ||
Ticker.fromAmino(ticker), | ||
provider_configs.map(ProviderConfig.fromAmino) | ||
); | ||
} | ||
|
||
public toAmino(): Market.Amino { | ||
const { ticker, provider_configs } = this; | ||
return { | ||
ticker: ticker.toAmino(), | ||
provider_configs: provider_configs.map(config => config.toAmino()), | ||
}; | ||
} | ||
|
||
public static fromData(data: Market.Data): Market { | ||
const { ticker, provider_configs } = data; | ||
return new Market( | ||
Ticker.fromData(ticker), | ||
provider_configs.map(ProviderConfig.fromData) | ||
); | ||
} | ||
|
||
public toData(): Market.Data { | ||
const { ticker, provider_configs } = this; | ||
return { | ||
ticker: ticker.toData(), | ||
provider_configs: provider_configs.map(config => config.toData()), | ||
}; | ||
} | ||
|
||
public static fromProto(proto: Market.Proto): Market { | ||
return new Market( | ||
Ticker.fromProto(proto.ticker as Ticker.Proto), | ||
proto.providerConfigs.map(ProviderConfig.fromProto) | ||
); | ||
} | ||
|
||
public toProto(): Market.Proto { | ||
const { ticker, provider_configs } = this; | ||
return Market_pb.fromPartial({ | ||
ticker: ticker.toProto(), | ||
providerConfigs: provider_configs.map(config => config.toProto()), | ||
}); | ||
} | ||
} | ||
|
||
export namespace Market { | ||
export interface Amino { | ||
ticker: Ticker.Amino; | ||
provider_configs: ProviderConfig.Amino[]; | ||
} | ||
|
||
export interface Data { | ||
ticker: Ticker.Data; | ||
provider_configs: ProviderConfig.Data[]; | ||
} | ||
|
||
export type Proto = Market_pb; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { AccAddress } from '../bech32'; | ||
import { JSONSerializable } from '../../util/json'; | ||
import { Params as Params_pb } from '@initia/initia.proto/slinky/marketmap/v1/params'; | ||
|
||
export class MarketmapParams extends JSONSerializable< | ||
MarketmapParams.Amino, | ||
MarketmapParams.Data, | ||
MarketmapParams.Proto | ||
> { | ||
/** | ||
* @param market_authorities the list of authority accounts that are able to control updating the marketmap | ||
* @param admin the address that can remove addresses from the MarketAuthorities list | ||
*/ | ||
constructor( | ||
public market_authorities: AccAddress[], | ||
public admin: AccAddress | ||
) { | ||
super(); | ||
} | ||
|
||
public static fromAmino(data: MarketmapParams.Amino): MarketmapParams { | ||
return new MarketmapParams(data.market_authorities, data.admin); | ||
} | ||
|
||
public toAmino(): MarketmapParams.Amino { | ||
const { market_authorities, admin } = this; | ||
return { market_authorities, admin }; | ||
} | ||
|
||
public static fromData(data: MarketmapParams.Data): MarketmapParams { | ||
return new MarketmapParams(data.market_authorities, data.admin); | ||
} | ||
|
||
public toData(): MarketmapParams.Data { | ||
const { market_authorities, admin } = this; | ||
return { market_authorities, admin }; | ||
} | ||
|
||
public static fromProto(data: MarketmapParams.Proto): MarketmapParams { | ||
return new MarketmapParams(data.marketAuthorities, data.admin); | ||
} | ||
|
||
public toProto(): MarketmapParams.Proto { | ||
const { market_authorities, admin } = this; | ||
return Params_pb.fromPartial({ | ||
marketAuthorities: market_authorities, | ||
admin, | ||
}); | ||
} | ||
} | ||
|
||
export namespace MarketmapParams { | ||
export interface Amino { | ||
market_authorities: AccAddress[]; | ||
admin: AccAddress; | ||
} | ||
|
||
export interface Data { | ||
market_authorities: AccAddress[]; | ||
admin: AccAddress; | ||
} | ||
|
||
export type Proto = Params_pb; | ||
} |
Oops, something went wrong.