Overtime Documentation
  • 🎾Get ready for Overtime
  • THE OVERDROP LEAGUE
  • ❓FAQ
  • ❗Sports Trading Guidelines
  • Free Bet
  • ABOUT OVERTIME SPORTSBOOK
    • 🏈Overtime V2 Architecture
    • Overtime Accounts
    • 🔴Onchain Live Markets
    • 🎲Odds Providers
    • 💵Onchain Free Bets
    • ⚖️Overtime Governance
    • 🐣History of Overtime
  • Overtime Guides
    • Providing Liquidity to Overtime
    • How to use Overtime
    • Current Incentives
    • Common User Mistakes
      • Deposited funds on the wrong network
    • Deposit USDC from Coinbase
    • Deposit USDC or USDT from Binance
      • Deposit from Binance Mobile App
      • Deposit from Binance Website
  • SPEED MARKETS
  • Introduction to Speed Markets
  • Chained Speed Markets
  • Speed Markets Trading Guide
  • Build Your Own Speed Markets App
  • Speed Market Deposit Guides
    • Deposit USDC from Coinbase
    • Deposit from Binance Mobile App
    • Deposit from Binance Website
  • FOR DEVELOPERS
  • 🔥Overtime V2 integration
    • Overtime V2 sports
    • Overtime V2 market types
    • Overtime V2 collaterals
    • Overtime V2 markets (protected)
    • Overtime V2 live markets (protected)
    • Overtime V2 user history
    • Overtime V2 quote data
    • Overtime V2 games info
    • Overtime V2 players info
    • Overtime V2 live scores
  • Links
    • ▶️Use the Dapp
    • ▶️Official Twitter
    • ▶️Medium
  • Resources
    • 📺Marketing Assets
    • ⚖️Terms of Use
Powered by GitBook
On this page
  • Speed Markets API
  • Contract integration
  • Buy a UP/DOWN position
  • Resolve market(s)
  • Resolve market with different collateral

Build Your Own Speed Markets App

PreviousSpeed Markets Trading GuideNextSpeed Market Deposit Guides

Last updated 1 month ago

Speed Markets API

In order to ensure easy integration with external partners Speed Markets API is created. API returns all required data to interact with Speed Markets AMM contract. Using Speed Markets API endpoints someone can get data about:

  • Buy

  • User claimable markets

  • Resolve markets (single or multiple markets)

  • Resolve market with different collateral (single market)

More details about each API endpoint with request/response examples can be found under .

Contract integration

Once all data are fetched from API, the next step is integration with Speed Markets contract. Depending on whether someone wants to buy a position or resolve a market (claim win) integration should be done with Speed Markets AMM contract.

The next sections describe integration with Speed Markets API and Speed Markets contract together with JS code examples.

Buy a UP/DOWN position

Let's say someone wants to buy UP position on the BTC market with a current strike price ($ 63,622.56) in 10 minutes from market creation and with a buy-in amount of 5 sUSD:

Buy UP position for 5 sUSD on BTC in 10 min from creation

Integration with Speed Markets API and Speed Markets AMM contract should include the following steps:

  1. Get a buy parameters for the market from Speed Markets API

  2. Create Speed Markets AMM contract instance

  3. Call createNewMarket or createNewMarketWithDifferentCollateral method on Speed Markets AMM contract with input parameters fetched from Speed Markets API in step #1

The JS code snippet below implements these steps:

const ethers = require('ethers');
const fetch = require('node-fetch');
const dotenv = require('dotenv');

// SpeedMarketsAMM contract ABI
const { speedAMMContract } = require('./speedAmmContractAbi.js');

dotenv.config();

const API_URL = 'https://overtimemarketsv2.xyz'; // base API URL
const NETWORK_ID = 10; // optimism network ID
const NETWORK = 'optimism'; // optimism network
// SpeedMarketsAMM contract address on optimism
const AMM_CONTRACT_ADDRESS = '0xE16B8a01490835EC1e76bAbbB3Cadd8921b32001'; 

const ASSET = 'BTC';
const DIRECTION = 'UP';
const COLLATERAL = 'sUSD';
const BUY_IN = 5; // 5 sUSD
const DELTA_TIME = 600; // 10 min

// create instance of Infura provider for optimism network
const provider = new ethers.providers.InfuraProvider(
    { chainId: Number(NETWORK_ID), name: NETWORK },
    process.env.INFURA
);

// create wallet instance for provided private key and provider
const wallet = new ethers.Wallet(process.env.PRIVATE_KEY, provider);

// create instance of Speed AMM contract
const speedAmm = new ethers.Contract(AMM_CONTRACT_ADDRESS, speedAMMContract.abi, wallet);

const createNewMarket = async () => {
    try {
        // Get contract method (createNewMarket/createNewMarketWithDifferentCollateral) parameters from Speed Markets API
        // for provided asset, direction, buy-in amount, collateral and delta time on optimism network
        const buyResponse = await fetch(
            `${API_URL}/speed-markets/networks/${NETWORK_ID}/buy/?asset=${ASSET}&direction=${DIRECTION}&buyin=${BUY_IN}&collateral=${COLLATERAL}&deltaTimeSec=${DELTA_TIME}`
        );

        const buyData = await buyResponse.json();
        console.log('Buy data', buyData);

        let tx;
        if (buyData.methodName == 'createNewMarketWithDifferentCollateral') {
            // call createNewMarketWithDifferentCollateral method on Speed Markets AMM contract
            tx = await speedAmm.createNewMarketWithDifferentCollateral(
                buyData.asset,
                buyData.strikeTime,
                buyData.delta,
                buyData.direction,
                buyData.priceUpdateData,
                buyData.collateral,
                buyData.collateralAmount,
                buyData.isEth,
                buyData.referrer,
                buyData.skewImpact,
                {
                    value: buyData.value,
                    type: 2,
                    maxPriorityFeePerGas: 10, // 10 wei
                }
            );
        } else {
            // call createNewMarket method on Speed Markets AMM contract
            tx = await speedAmm.createNewMarket(
                buyData.asset,
                buyData.strikeTime,
                buyData.delta,
                buyData.direction,
                buyData.buyinAmount,
                buyData.priceUpdateData,
                buyData.referrer,
                buyData.skewImpact,
                { value: buyData.value, type: 2, maxPriorityFeePerGas: 10 } // 10 wei
            );
        }

        // wait for the result
        const txResult = await tx.wait();
        console.log(`Successfully bought from Speed AMM. Transaction hash: ${txResult.transactionHash}`);
    } catch (e) {
        console.log('Failed to buy from Speed AMM', e);
    }
};

createNewMarket();

Resolve market(s)

Let's say someone wants to claim winnings on two markets (resolve markets) in sUSD:

Integration with Speed Markets API and Speed Markets AMM contract should include the following steps:

  1. Get a resolve parameters for the markets from Speed Markets API

  2. Get a user claimable markets from Speed Markets API

  3. Create Speed Markets AMM contract instance

  4. Call resolveMarketsBatch method on Speed Markets AMM contract with input parameters fetched from Speed Markets API in step #1

The JS code snippet below implements these steps:

const ethers = require('ethers');
const fetch = require('node-fetch');
const dotenv = require('dotenv');
// SpeedMarketsAMM contract ABI
const { speedAMMContract } = require('./speedAmmContractAbi.js'); 

dotenv.config();

const API_URL = 'https://overtimemarketsv2.xyz'; // base API URL
const NETWORK_ID = 10; // optimism network ID
const NETWORK = 'optimism'; // optimism network
// SpeedMarketsAMM contract address on optimism
const AMM_CONTRACT_ADDRESS = '0xE16B8a01490835EC1e76bAbbB3Cadd8921b32001'; 

// Speed markets addresses to resolve
const MARKET_1 = '0x5ef786087d122b9056f351Cf3B52E5A7B0d5277D'; 
const MARKET_2 = '0x2542906FE4701A8c930427c2ff6Db1C948B91571';

// create instance of Infura provider for optimism network
const provider = new ethers.providers.InfuraProvider(
    { chainId: Number(NETWORK_ID), name: NETWORK },
    process.env.INFURA
);

// create wallet instance for provided private key and provider
const wallet = new ethers.Wallet(process.env.PRIVATE_KEY, provider);

// create instance of Speed AMM contract
const speedAmm = new ethers.Contract(AMM_CONTRACT_ADDRESS, speedAMMContract.abi, wallet);

const resolveMarkets = async () => {
    try {
        // Get contract method (resolveMarketsBatch) parameters from Speed Markets API
        // for provided market address on optimism network
        const resolveResponse = await fetch(
            `${API_URL}/speed-markets/networks/${NETWORK_ID}/resolve?markets[]=${MARKET_1}&markets[]=${MARKET_2}`
        );

        const resolveData = await resolveResponse.json();
        console.log('Resolve data', resolveData);

        // call resolveMarketsBatch method on Speed Markets AMM contract
        const tx = await speedAmm.resolveMarketsBatch(
            resolveData.markets, 
            resolveData.priceUpdateData, 
            {
                value: resolveData.value,
                type: 2,
                maxPriorityFeePerGas: 10, // 10 wei
            }
        );

        // wait for the result
        const txResult = await tx.wait();
        console.log(`Successfully resolved market on Speed AMM. Transaction hash: ${txResult.transactionHash}`);
    } catch (e) {
        console.log('Failed to resolve market on Speed AMM', e);
    }
};

resolveMarkets();

Resolve market with different collateral

If someone wants to claim winning in different collateral than default one for a network (resolve market) process is the same as previous one, just using appropriate API and contract method. Corresponding API is "Resolve market with different collateral" and contract method resolveMarketWithOfframp. Currently batch is not available for claim with different collateral.

Get a Speed Markets AMM contract address for a specific network from

Get a Speed Markets AMM contract ABI from Speed Markets AMM

Resolve (claim) two markets wins

Get a Speed Markets AMM contract address for a specific network from

Get a Speed Markets AMM contract ABI from Speed Markets AMM

Thales contracts
contract repository
Thales contracts
contract repository
Postman documentation